[4] | grunfeldavg.dta | |||
[19] | grunfeldavg.dta | |||
[90] | grunfeldavg.dta | |||
ch9.01.do:94 |
[114] | [+] lfirmstats | ||
master.do:43 | ||||
→ | ch9.01.do | ↘ | ||
ch903t |
[16] | |||
ch902t |
[87] | |||
[+] firmstats
|
[94] |
ch9.01.do:114 ch9.08.do:3 ch9.09.do:3 |
||
matoutraw |
[118] | |||
matout2raw |
[134] |
ch9.01.do open
file:script:do
# | content |
---|---|
1 [+] | * itsp ch9.01 - ch9.05c |
3 [+] | clear all |
4 [+] | use grunfeldavg |
5 [+] | levelsof company , |
6 [+] | local ncomp : word count `colist' |
7 [+] | forvalues i = 1/`ncomp' { |
8 [+] | local c : word `i' of `colist' |
9 [+] | quietly regress invest L(1/2).kstock L.kapavg if company == `c' |
10 [+] | matrix beta`i' = e(b) |
11 [+] | matrix allbeta = (nullmat(allbeta) \ beta`i') |
12 [+] | local row "`row' `c'" |
13 [+] | } |
14 [+] | matrix rownames allbeta = `row' |
16 [+] | outtable using ch9.03t , /// format(%9.4f) center caption("Grunfeld company estimates") |
19 [+] | use grunfeldavg , |
20 [+] | levelsof company , |
21 [+] | local ncomp : word count `colist' |
22 [+] | matrix table1 = J(`ncomp', 7, 0) |
24 [+] | local i 0 |
25 [+] | levelsof company , |
26 [+] | foreach c of local colist { |
27 [+] | quietly { |
28 [+] | local ++i |
29 [+] | summarize invest if company == `c' , |
30 [+] | matrix table1[`i', 1] = r(p25) |
31 [+] | matrix table1[`i', 2] = r(p50) |
32 [+] | matrix table1[`i', 3] = r(p75) |
33 [+] | correlate invest invavg if company == `c' |
34 [+] | matrix table1[`i', 4] = r(rho) |
35 [+] | correlate kstock kapavg if company == `c' |
36 [+] | matrix table1[`i', 5] = r(rho) |
37 [+] | regress invest L.kstock L.kapavg if company == `c' |
38 [+] | matrix table1[`i', 6] = _b["L.kstock"] |
39 [+] | matrix table1[`i', 7] = _se["L.kstock"] |
40 [+] | } |
41 [+] | } |
42 [+] | matrix rownames table1 = `colist' |
43 [+] | matrix colnames table1 = p25 p50 p75 r_invest r_kap beta_k se_k |
65 [+] | /* forvalues i = 1/`ncomp' { local c : word `i' of `colist' quietly { summarize invest if company == `c', detail matrix table1[`i', 1] = r(p25) matrix table1[`i', 2] = r(p50) matrix table1[`i', 3] = r(p75) correlate invest invavg if company == `c' matrix table1[`i', 4] = r(rho) correlate kstock kapavg if company == `c' matrix table1[`i', 5] = r(rho) regress invest L.kstock L.kapavg if company == `c' matrix table1[`i', 6] = _b["L.kstock"] matrix table1[`i', 7] = _se["L.kstock"] } } matrix rownames table1 = `colist' matrix colnames table1 = p25 p50 p75 r_invest r_kap beta_k se_k */ |
86 [+] | mat list table1 , |
87 [+] | outtable using ch9.02t , /// format(%9.3f) center caption("Grunfeld company statistics") |
90 [+] | use grunfeldavg , |
91 [+] | levelsof company , |
92 [+] | local ncomp : word count `colist' |
93 [+] | tempname p |
94 [+] | postfile `p' compnr p25 p50 p75 r_invest r_kap beta_k se_k using firmstats , |
96 [+] | forvalues i = 1/`ncomp' { |
97 [+] | local c : word `i' of `colist' |
98 [+] | quietly { |
99 [+] | summarize invest if company == `c' , |
100 [+] | local p25 = r(p25) |
101 [+] | local p50 = r(p50) |
102 [+] | local p75 = r(p75) |
103 [+] | correlate invest invavg if company == `c' |
104 [+] | local r_invest = r(rho) |
105 [+] | correlate kstock kapavg if company == `c' |
106 [+] | local r_kap = r(rho) |
107 [+] | regress invest L.kstock L.kapavg if company == `c' |
108 [+] | } |
109 [+] | post `p' (`i') (`p25') (`p50') (`p75') (`r_invest') (`r_kap') /// (_b["L.kstock"]) (_se["L.kstock"]) |
111 [+] | } |
112 [+] | postclose `p' |
114 [+] | use firmstats , |
115 [+] | summarize |
117 [+] | tempname fh |
118 [+] | file open `fh' using matout.raw , |
120 [+] | local rows = rowsof(table1) |
121 [+] | local cols = colsof(table1) |
122 [+] | local timestamp "Matrix created `c(current_date)' `c(current_time)'" |
123 [+] | file write `fh' "`timestamp'" _n |
124 [+] | file write `fh' "`rows' `cols'" _n |
125 [+] | forvalues i = 1/`rows' { |
126 [+] | forvalues j = 1/`cols' { |
127 [+] | file write `fh' (table1[`i', `j']) " " |
128 [+] | } |
129 [+] | file write `fh' _n |
130 [+] | } |
131 [+] | file close `fh' |
133 [+] | tempname fh |
134 [+] | file open `fh' using matout2.raw , |
135 [+] | local rows = rowsof(table1) |
136 [+] | local cols = colsof(table1) |
137 [+] | local timestamp "Matrix created `c(current_date)' `c(current_time)'" |
138 [+] | file write `fh' "`timestamp'" _n |
139 [+] | file write `fh' "`rows' `cols'" _n |
140 [+] | local coln : colnames table1 |
141 [+] | local rown : rownames table1 |
142 [+] | file write `fh' "firmno `coln'" _n |
143 [+] | forvalues i = 1/`rows' { |
144 [+] | local rn : word `i' of `rown' |
145 [+] | file write `fh' `"`rn' "' |
146 [+] | forvalues j = 1/`cols' { |
147 [+] | file write `fh' (table1[`i', `j']) " " |
148 [+] | } |
149 [+] | file write `fh' _n |
150 [+] | } |
151 [+] | file close `fh' |
153 [+] | type matout2.raw |
* itsp ch9.01 - ch9.05c clear all use grunfeldavg levelsof company, local(colist) local ncomp : word count `colist' forvalues i = 1/`ncomp' { local c : word `i' of `colist' quietly regress invest L(1/2).kstock L.kapavg if company == `c' matrix beta`i' = e(b) matrix allbeta = (nullmat(allbeta) \ beta`i') local row "`row' `c'" } matrix rownames allbeta = `row' outtable using ch9.03t, mat(allbeta) replace /// format(%9.4f) center caption("Grunfeld company estimates") use grunfeldavg, clear levelsof company, local(colist) local ncomp : word count `colist' matrix table1 = J(`ncomp', 7, 0) local i 0 levelsof company, local(colist) foreach c of local colist { quietly { local ++i summarize invest if company == `c', detail matrix table1[`i', 1] = r(p25) matrix table1[`i', 2] = r(p50) matrix table1[`i', 3] = r(p75) correlate invest invavg if company == `c' matrix table1[`i', 4] = r(rho) correlate kstock kapavg if company == `c' matrix table1[`i', 5] = r(rho) regress invest L.kstock L.kapavg if company == `c' matrix table1[`i', 6] = _b["L.kstock"] matrix table1[`i', 7] = _se["L.kstock"] } } matrix rownames table1 = `colist' matrix colnames table1 = p25 p50 p75 r_invest r_kap beta_k se_k /* tokenize `colist' forvalues i = 1/`ncomp' { quietly { summarize invest if company == ``i'', detail matrix table1[`i', 1] = r(p25) matrix table1[`i', 2] = r(p50) matrix table1[`i', 3] = r(p75) correlate invest invavg if company == ``i'' matrix table1[`i', 4] = r(rho) correlate kstock kapavg if company == ``i'' matrix table1[`i', 5] = r(rho) regress invest L.kstock L.kapavg if company == ``i'' matrix table1[`i', 6] = _b["L.kstock"] matrix table1[`i', 7] = _se["L.kstock"] } } matrix rownames table1 = `colist' matrix colnames table1 = p25 p50 p75 r_invest r_kap beta_k se_k */ /* forvalues i = 1/`ncomp' { local c : word `i' of `colist' quietly { summarize invest if company == `c', detail matrix table1[`i', 1] = r(p25) matrix table1[`i', 2] = r(p50) matrix table1[`i', 3] = r(p75) correlate invest invavg if company == `c' matrix table1[`i', 4] = r(rho) correlate kstock kapavg if company == `c' matrix table1[`i', 5] = r(rho) regress invest L.kstock L.kapavg if company == `c' matrix table1[`i', 6] = _b["L.kstock"] matrix table1[`i', 7] = _se["L.kstock"] } } matrix rownames table1 = `colist' matrix colnames table1 = p25 p50 p75 r_invest r_kap beta_k se_k */ mat list table1, format(%9.3f) ti("Grunfeld company statistics") outtable using ch9.02t, mat(table1) replace /// format(%9.3f) center caption("Grunfeld company statistics") use grunfeldavg, clear levelsof company, local(colist) local ncomp : word count `colist' tempname p postfile `p' compnr p25 p50 p75 r_invest r_kap beta_k se_k using firmstats, replace forvalues i = 1/`ncomp' { local c : word `i' of `colist' quietly { summarize invest if company == `c', detail local p25 = r(p25) local p50 = r(p50) local p75 = r(p75) correlate invest invavg if company == `c' local r_invest = r(rho) correlate kstock kapavg if company == `c' local r_kap = r(rho) regress invest L.kstock L.kapavg if company == `c' } post `p' (`i') (`p25') (`p50') (`p75') (`r_invest') (`r_kap') /// (_b["L.kstock"]) (_se["L.kstock"]) } postclose `p' use firmstats, clear summarize tempname fh file open `fh' using matout.raw, write replace local rows = rowsof(table1) local cols = colsof(table1) local timestamp "Matrix created `c(current_date)' `c(current_time)'" file write `fh' "`timestamp'" _n file write `fh' "`rows' `cols'" _n forvalues i = 1/`rows' { forvalues j = 1/`cols' { file write `fh' (table1[`i', `j']) " " } file write `fh' _n } file close `fh' tempname fh file open `fh' using matout2.raw, write replace local rows = rowsof(table1) local cols = colsof(table1) local timestamp "Matrix created `c(current_date)' `c(current_time)'" file write `fh' "`timestamp'" _n file write `fh' "`rows' `cols'" _n local coln : colnames table1 local rown : rownames table1 file write `fh' "firmno `coln'" _n forvalues i = 1/`rows' { local rn : word `i' of `rown' file write `fh' `"`rn' "' forvalues j = 1/`cols' { file write `fh' (table1[`i', `j']) " " } file write `fh' _n } file close `fh' type matout2.raw