ch5.01.do open
file:script:do
| # | content |
|---|---|
| 1 [+] | * itsp ch5.01 - 5.15 |
| 3 [+] | use un , |
| 4 [+] | describe |
| 5 [+] | return list |
| 6 [+] | local sb: sortedby |
| 7 [+] | display "dataset sorted by: `sb'" |
| 9 [+] | summarize troop , |
| 10 [+] | scalar iqr = r(p75) - r(p25) |
| 11 [+] | display "IQR = " iqr |
| 12 [+] | scalar semean = r(sd) / sqrt(r(N)) |
| 13 [+] | display "Mean = " r(mean) " S.E. = " semean |
* from http://www.stata-press.com/data/r9/union |
|
| 16 [+] | use unionT , |
| 17 [+] | xtset |
| 18 [+] | return list |
| 20 [+] | ttest age , |
| 21 [+] | return list |
| 23 [+] | use un , |
| 24 [+] | regress deaths duration troop |
| 25 [+] | ereturn list |
| 27 [+] | local regressors: colnames e(b) |
| 28 [+] | display "Regressors: `regressors'" |
| 30 [+] | estat summarize |
| 32 [+] | matrix list e(b) |
| 34 [+] | estat vce |
| 36 [+] | use usairquality , |
| 37 [+] | quietly regress so2 temp manuf pop |
| 38 [+] | estimates store model1 |
| 39 [+] | quietly regress so2 temp pop wind |
| 40 [+] | estimates store model2 |
| 41 [+] | quietly regress so2 temp wind precip days |
| 42 [+] | estimates store model3 |
| 43 [+] | quietly regress so2 temp manuf pop wind precip days |
| 44 [+] | estimates store model4 |
| 45 [+] | estimates table model1 model2 model3 model4 , /// b(%7.3f) se(%6.3g) p(%4.3f) |
| 48 [+] | estimates table model4 model1 model3 model2 , /// b(%7.3g) star label title("Models of sulphur dioxide concentration") |
| 51 [+] | estimates for model1 model2 model3 model4: test temp = -1.6 |
| 53 [+] | estimates replay model1 |
| 55 [+] | forvalues i = 1/4 { |
| 56 [+] | estimates restore model`i' |
| 57 [+] | estimates notes: from file `c(filename)' saved `c(filedate)' |
| 58 [+] | estimates save so2_model`i' , |
| 59 [+] | } |
| 61 [+] | clear |
| 62 [+] | estimates clear |
| 63 [+] | estimates describe using so2_model3 |
| 64 [+] | estimates use so2_model3 |
| 65 [+] | estimates store so2_model3 |
| 66 [+] | estimates table * |
| 68 [+] | use usairquality , |
| 69 [+] | eststo clear |
| 70 [+] | eststo: quietly regress so2 temp manuf pop |
| 71 [+] | eststo: quietly regress so2 temp pop wind |
| 72 [+] | eststo: quietly regress so2 temp wind precip days |
| 73 [+] | eststo: quietly regress so2 temp manuf pop wind precip days |
| 74 [+] | esttab using esttab_example.tex , /// alignment(D{.}{.}{-1}) replace |
| 78 [+] | * prep data for illustration of long/wide |
| 80 [+] | use NEstates , |
| 81 [+] | keep if inlist(year,1990,1995,2000) |
| 82 [+] | drop dpi* |
| 83 [+] | keep year popCT popMA popRI |
| 84 [+] | order year |
| 85 [+] | xpose , |
| 86 [+] | drop in 1 |
| 87 [+] | gen str state = "CT" in 1 |
| 88 [+] | replace state = "MA" in 2 |
| 89 [+] | replace state = "RI" in 3 |
| 90 [+] | rename v1 pop1990 |
| 91 [+] | rename v2 pop1995 |
| 92 [+] | rename v3 pop2000 |
| 93 [+] | order state |
| 94 [+] | list , |
| 96 [+] | reshape long pop , |
| 97 [+] | list , |
| 99 [+] | /* prep data for reshape, merge, append use http://fmwww.bc.edu/ec-p/data/wooldridge2k/MATHPNL,clear xtset year distid label var year "year" rename math4 math4score rename math7 math7score keep distid year lunch enrol expp revpp avgsal drop grad math4score math7score staff cpi rexpp label data "modified mathpnl.dta from Wooldridge (2000)" save mathpnlLfull,replace forv y=1992/1998 { preserve keep if year==`y' save mathpnl`y',replace restore } use mathpnlLfull, clear keep distid year expp revpp avgsal math4score math7score keep if inlist(year,1992,1994,1996,1998) use mathpnlL,clear xtset distid year, delta(2) save mathpnlL, replace reshape wide expp revpp avgsal math4score math7score, i(distid) j(year) save mathpnlW, replace */ |
| 126 [+] | use mathpnl_long , |
| 127 [+] | describe |
| 129 [+] | xtset |
| 130 [+] | tabulate year |
| 132 [+] | use mathpnl_wide , |
| 133 [+] | describe |
| 135 [+] | reshape long expp revpp avgsal math4score math7score , |
| 137 [+] | describe |
| 139 [+] | reshape wide expp revpp avgsal math4score math7score , |
| 141 [+] | use mathpnl1992 , |
| 142 [+] | append using mathpnl1994 |
| 143 [+] | append using mathpnl1996 |
| 144 [+] | append using mathpnl1998 |
| 145 [+] | label data "" |
| 146 [+] | save mathpnl_appended , |
| 147 [+] | describe |
| 149 [+] | * set up dummy dataset for merge |
| 151 [+] | use mathpnl_long , |
| 152 [+] | keep distid year |
| 153 [+] | keep if year == 1992 |
| 154 [+] | gen int state = uniform() * 50 + 1 |
| 155 [+] | drop year |
| 156 [+] | label var state "State code" |
| 157 [+] | label data "" |
| 158 [+] | sort distid |
| 159 [+] | save mathpnl_state , |
| 160 [+] | describe |
| 162 [+] | use mathpnl_long , |
| 163 [+] | merge distid using mathpnl_state , |
| 164 [+] | tab _merge |
| 165 [+] | assert _merge == 3 |
| 166 [+] | drop _merge |
| 167 [+] | save mathpnl_longs , |
* set up datasets for multiple merge |
|
| 170 [+] | use mathpnl_wide , |
| 171 [+] | forv i=1992(2)1998 { |
| 172 [+] | preserve |
| 173 [+] | keep distid *`i' |
| 174 [+] | label data "" |
| 175 [+] | save mathpnl`i'm , |
| 176 [+] | restore |
| 177 [+] | } |
| 179 [+] | use mathpnl1992m , |
| 180 [+] | forvalues y=1994(2)1998 { |
| 181 [+] | merge distid using mathpnl`y'm , |
| 182 [+] | assert _merge == 3 |
| 183 [+] | drop _merge |
| 184 [+] | } |
| 185 [+] | save mathpnlm , |
| 187 [+] | use mathpnl_wide , |
| 188 [+] | preserve |
| 189 [+] | stack expp1992 avgsal1992 expp1998 avgsal1998 , |
| 190 [+] | scatter expp1992 expp1998 sal , /// legend(position(5) ring(0) label(1 "1992") label(2 "1998")) |
| 194 [+] | restore |
| 196 [+] | use mathpnl_long , |
| 197 [+] | separate expp , |
| 198 [+] | summarize expp* |
* itsp ch5.01 - 5.15
use un, clear
describe
return list
local sb: sortedby
display "dataset sorted by: `sb'"
summarize troop, detail
scalar iqr = r(p75) - r(p25)
display "IQR = " iqr
scalar semean = r(sd) / sqrt(r(N))
display "Mean = " r(mean) " S.E. = " semean
* from http://www.stata-press.com/data/r9/union
use unionT, clear
xtset
return list
ttest age, by(union)
return list
use un, clear
regress deaths duration troop
ereturn list
local regressors: colnames e(b)
display "Regressors: `regressors'"
estat summarize
matrix list e(b)
estat vce
use usairquality, clear
quietly regress so2 temp manuf pop
estimates store model1
quietly regress so2 temp pop wind
estimates store model2
quietly regress so2 temp wind precip days
estimates store model3
quietly regress so2 temp manuf pop wind precip days
estimates store model4
estimates table model1 model2 model3 model4, stat(r2_a rmse) ///
b(%7.3f) se(%6.3g) p(%4.3f)
estimates table model4 model1 model3 model2, stat(r2_a rmse ll) ///
b(%7.3g) star label title("Models of sulphur dioxide concentration")
estimates for model1 model2 model3 model4: test temp = -1.6
estimates replay model1
forvalues i = 1/4 {
estimates restore model`i'
estimates notes: from file `c(filename)' saved `c(filedate)'
estimates save so2_model`i', replace
}
clear
estimates clear
estimates describe using so2_model3
estimates use so2_model3
estimates store so2_model3
estimates table *
use usairquality,clear
eststo clear
eststo: quietly regress so2 temp manuf pop
eststo: quietly regress so2 temp pop wind
eststo: quietly regress so2 temp wind precip days
eststo: quietly regress so2 temp manuf pop wind precip days
esttab using esttab_example.tex, ar2 label se nostar nodepvars brackets ///
nomtitles title("Models of sulphur dioxide concentration") booktabs ///
alignment(D{.}{.}{-1}) replace
* prep data for illustration of long/wide
use NEstates, clear
keep if inlist(year,1990,1995,2000)
drop dpi*
keep year popCT popMA popRI
order year
xpose,clear
drop in 1
gen str state = "CT" in 1
replace state = "MA" in 2
replace state = "RI" in 3
rename v1 pop1990
rename v2 pop1995
rename v3 pop2000
order state
list, noobs
reshape long pop, i(state) j(year)
list, noobs sepby(state)
/* prep data for reshape, merge, append
use http://fmwww.bc.edu/ec-p/data/wooldridge2k/MATHPNL,clear
xtset year distid
label var year "year"
rename math4 math4score
rename math7 math7score
keep distid year lunch enrol expp revpp avgsal drop grad math4score math7score staff cpi rexpp
label data "modified mathpnl.dta from Wooldridge (2000)"
save mathpnlLfull,replace
forv y=1992/1998 {
preserve
keep if year==`y'
save mathpnl`y',replace
restore
}
use mathpnlLfull, clear
keep distid year expp revpp avgsal math4score math7score
keep if inlist(year,1992,1994,1996,1998)
use mathpnlL,clear
xtset distid year, delta(2)
save mathpnlL, replace
reshape wide expp revpp avgsal math4score math7score, i(distid) j(year)
save mathpnlW, replace
*/
use mathpnl_long, clear
describe
xtset
tabulate year
use mathpnl_wide, clear
describe
reshape long expp revpp avgsal math4score math7score, i(distid) j(year)
describe
reshape wide expp revpp avgsal math4score math7score, i(distid) j(year)
use mathpnl1992, clear
append using mathpnl1994
append using mathpnl1996
append using mathpnl1998
label data ""
save mathpnl_appended, replace
describe
* set up dummy dataset for merge
use mathpnl_long,clear
keep distid year
keep if year == 1992
gen int state = uniform() * 50 + 1
drop year
label var state "State code"
label data ""
sort distid
save mathpnl_state, replace
describe
use mathpnl_long, clear
merge distid using mathpnl_state, sort uniqusing
tab _merge
assert _merge == 3
drop _merge
save mathpnl_longs, replace
* set up datasets for multiple merge
use mathpnl_wide,clear
forv i=1992(2)1998 {
preserve
keep distid *`i'
label data ""
save mathpnl`i'm, replace
restore
}
use mathpnl1992m, clear
forvalues y=1994(2)1998 {
merge distid using mathpnl`y'm, sort unique
assert _merge == 3
drop _merge
}
save mathpnlm, replace
use mathpnl_wide, clear
preserve
stack expp1992 avgsal1992 expp1998 avgsal1998, into(expp sal) wide clear
scatter expp1992 expp1998 sal, m(oh x) scheme(s2mono) ///
title("School District Expenditures vs. Average Salaries") ///
xtitle("Average salaries") ytitle("Expenditures") ///
legend(position(5) ring(0) label(1 "1992") label(2 "1998"))
restore
use mathpnl_long, clear
separate expp, by(year) veryshortlabel
summarize expp*