[3] | hprice2a.dta | ||
[7] | hprice2a.dta | ||
master.do:35 | |||
→ | ch4.26.do | ↘ |
ch4.26.do open
file:script:do
# | content |
---|---|
1 [+] | * ITSP 4.26 - |
3 [+] | use hprice2a , |
4 [+] | regress price nox dist rooms stratio proptax |
5 [+] | mfx , |
7 [+] | use hprice2a , |
// run regression |
|
9 [+] | quietly regress price nox dist rooms stratio |
// compute appropriate t-statistic for 95% confidence interval |
|
11 [+] | scalar tmfx = invttail(e(df_r), 0.975) |
12 [+] | tempvar y x eyex seyex1 seyex2 |
13 [+] | foreach v in `y' `x' `eyex' `seyex1' `seyex2' { // generate variables needed |
14 [+] | qui generate `v' = . |
15 [+] | } |
// summarize, detail computes percentiles of stratio |
|
17 [+] | quietly summarize stratio if e(sample) , |
18 [+] | local pct 1 10 25 50 75 90 99 |
19 [+] | local i = 0 |
20 [+] | foreach p of local pct { |
21 [+] | local pc`p' = r(p`p') |
22 [+] | local ++i |
// set those percentiles into tempvar x |
|
24 [+] | quietly replace `x' = `pc`p'' in `i' |
25 [+] | } |
27 [+] | local i = 0 |
28 [+] | foreach p of local pct { |
// compute elasticities at those points |
|
30 [+] | quietly mfx compute , |
31 [+] | local ++i |
// save predictions at these points in tempvar y |
|
33 [+] | quietly replace `y' = e(Xmfx_y) in `i' |
// retrieve elasticities |
|
35 [+] | matrix Meyex = e(Xmfx_eyex) |
36 [+] | matrix eta = Meyex[1, "stratio"] // for the stratio column |
37 [+] | quietly replace `eyex' = eta[1, 1] in `i' // and save in tempvar eyex |
// retrieve standard errors of the elasticities |
|
39 [+] | matrix Seyex = e(Xmfx_se_eyex) |
40 [+] | matrix se = Seyex[1,"stratio"] // for the stratio column |
// compute upper and lower bounds of confidence interval |
|
42 [+] | quietly replace `seyex1' = `eyex' + tmfx*se[1, 1] in `i' |
43 [+] | quietly replace `seyex2' = `eyex' - tmfx*se[1, 1] in `i' |
44 [+] | } |
46 [+] | label variable `x' "Student/teacher ratio (percentiles `pct')" |
47 [+] | label variable `y' "Predicted median house price, dollars" |
48 [+] | label variable `eyex' "Elasticity" |
49 [+] | label variable `seyex1' "95% c.i." |
50 [+] | label variable `seyex2' "95% c.i." |
// graph the scatter of elasticities vs. percentiles of stratio // as well as the predictions with rline // and the 95% confidence bands with connected |
|
54 [+] | twoway (scatter `eyex' `x', ms(Oh) yscale(range(-0.5 -2.0)) ylabel(,nogrid)) /// (rline `seyex1' `seyex2' `x') /// (connected `y' `x', yaxis(2) yscale(axis(2) range(18000 35000))) , /// ytitle(Elasticity of price v. student/teacher ratio) |
* ITSP 4.26 - use hprice2a, clear regress price nox dist rooms stratio proptax mfx, eyex use hprice2a, clear // run regression quietly regress price nox dist rooms stratio // compute appropriate t-statistic for 95% confidence interval scalar tmfx = invttail(e(df_r), 0.975) tempvar y x eyex seyex1 seyex2 foreach v in `y' `x' `eyex' `seyex1' `seyex2' { // generate variables needed qui generate `v' = . } // summarize, detail computes percentiles of stratio quietly summarize stratio if e(sample), detail local pct 1 10 25 50 75 90 99 local i = 0 foreach p of local pct { local pc`p' = r(p`p') local ++i // set those percentiles into tempvar x quietly replace `x' = `pc`p'' in `i' } local i = 0 foreach p of local pct { // compute elasticities at those points quietly mfx compute, eyex at(mean stratio = `pc`p'') local ++i // save predictions at these points in tempvar y quietly replace `y' = e(Xmfx_y) in `i' // retrieve elasticities matrix Meyex = e(Xmfx_eyex) matrix eta = Meyex[1, "stratio"] // for the stratio column quietly replace `eyex' = eta[1, 1] in `i' // and save in tempvar eyex // retrieve standard errors of the elasticities matrix Seyex = e(Xmfx_se_eyex) matrix se = Seyex[1,"stratio"] // for the stratio column // compute upper and lower bounds of confidence interval quietly replace `seyex1' = `eyex' + tmfx*se[1, 1] in `i' quietly replace `seyex2' = `eyex' - tmfx*se[1, 1] in `i' } label variable `x' "Student/teacher ratio (percentiles `pct')" label variable `y' "Predicted median house price, dollars" label variable `eyex' "Elasticity" label variable `seyex1' "95% c.i." label variable `seyex2' "95% c.i." // graph the scatter of elasticities vs. percentiles of stratio // as well as the predictions with rline // and the 95% confidence bands with connected twoway (scatter `eyex' `x', ms(Oh) yscale(range(-0.5 -2.0)) ylabel(,nogrid)) /// (rline `seyex1' `seyex2' `x') /// (connected `y' `x', yaxis(2) yscale(axis(2) range(18000 35000))), /// ytitle(Elasticity of price v. student/teacher ratio)