Content
--------------------------------------------------------------------------------------------------------------------------------------------
name:
log: C:\doug work\Colin\JHR cluster paper\work Summer 2014\empirical example code\table1.log
log type: text
opened on: 25 Jun 2014, 18:22:52
. cap log close t1out ;
. qui log using table1_out.csv , text replace name(t1out) ;
. qui log off t1out ;
. clear ;
. set more off ;
. do set_directory_macros ;
. #delimit ;
delimiter now ;
. local my_top_path = subinstr(c(pwd), "doug work\Colin\JHR cluster paper\work Summer 2014\empirical example code", "",.) ;
. global rawdat = "`my_top_path'data\CPS\July 2013 extract for cluster JHR" ;
. global madedat = "`my_top_path'madedata\Colin JHR paper" ;
. if "$S_OS" == "Unix" { ;
. global rawdat = "../data" ;
. global madedat = "../data" ;
. } ;
. di "$rawdat" ;
C:\data\CPS\July 2013 extract for cluster JHR
. di "$madedat" ;
C:\madedata\Colin JHR paper
. *global rawdat = "C:\data\CPS\July 2013 extract for cluster JHR" ;
. *global madedat = "C:\madedata\Colin JHR paper" ;
. *global rawdat = "C:\Users\dlmiller\data\CPS\July 2013 extract for cluster JHR" ;
. *global madedat = "C:\Users\dlmiller\madedata\Colin JHR paper" ;
.
end of do-file
. cap prog drop runme ;
. prog def runme ;
1. /***************** MAKE THE DATA SET ****************/
> /* generate state policy variable */
> use statefip using "${madedat}/CPS_2012_micro_small" , replace ;
2. contract statefip ;
3. set seed 10101 ;
4. generate sort_order = uniform() ;
5. sort sort_order ;
6. gen policy = _n <= 25 ;
7. sort statefip ;
8. drop sort_order _freq ;
9. *list ;
. tempfile statelist ;
10. qui save `statelist' ;
11. /* load up the micro data set, and merge on the fake policy variable */
> *use "${madedat}/CPS_2012_micro_small" , replace ;
. *use "${madedat}/CPS_2012_micro_medium" , replace ;
. use "${madedat}/CPS_2012_micro" , replace ;
12. sort statefip ;
13. merge m:1 statefip using `statelist' ;
14. tab _merge ;
15. drop _merge ;
16. /***************** ESTIMATE THE MODELS ****************/
>
> /*column 1 */
> reg lnwage policy age age2 yrseduc ;
17. local b_ols = _b[policy] ;
18. /* slope coefficient */
> local se_ols_default = _se[policy] ;
19. /* default standard errors */
> local N_ols = e(N) ;
20. /* number of observations */
> predict tab1_resid , resid ;
21. reg lnwage policy age age2 yrseduc , robust ;
22. estimates store ols_white ;
23. local se_ols_robust = _se[policy] ;
24. /* Heteroscedastic robust standard errors */
>
> reg lnwage policy age age2 yrseduc , cluster(statefip) ;
25. local se_ols_cluster = _se[policy] ;
26. /* Cluster robust (cluster on state) standard errors */
> local G_ols = e(N_clust) ;
27. /* Number clusters */
>
> reg lnwage policy age age2 yrseduc , vce(bootstrap , cluster(statefip) reps(399) seed(10101) ) ;
28. local se_ols_bootstrap = _se[policy] ;
29. /* Pairs cluster bootstrap standard errors */
>
>
>
> /* what is the range of cluster sizes? */
> preserve ;
30. gen byte one = 1 ;
31. collapse (sum) clusize = one , by(statefip) ;
32. summ clusize ;
33. local clusize_min = r(min) ;
34. local clusize_max = r(max) ;
35. restore ;
36. loneway tab1_resid statefip ;
37. local rho = r(rho) ;
38. /* Intraclass correlation */
> di ;
39. di "intraclass correation = `rho'" ;
40. /* what else to save? */
>
>
> /* now do RE models */
> /* Column 2, "FGLS (Random Effects)" */
> xtset statefip ;
41. xtreg lnwage policy age age2 yrseduc , re ;
42. local b_re = _b[policy] ;
43. local se_re_default = _se[policy] ;
44. local N_re = e(N) ;
45. xtreg lnwage policy age age2 yrseduc , re cluster(statefip) ;
46. local se_re_cluster = _se[policy] ;
47. /*********************************************/
> /* COLIN I CANNOT GET THIS TO CONVERGE IN A SHORT AMOUNT OF TIME with full sample.
> I PROPOSE WE comment it out in the published code */
> /* On Doug's work desktop, takes 2 hours to run when using "full" micro sample. */
> /* also, for "small" sample, it doesn't yet give the same thing as the regular re model */
> /* another way to to random effects model
> (compare with xtreg output)
> (not in table) */
> set matsize 6000 ;
48. xtreg lnwage policy age age2 yrseduc , pa corr(exch) robust ;
49. /************ END PROPOSED commenting out *********/
>
> /* Random Effects model with cluster bootstrap for standard errors */
> xtreg lnwage policy age age2 yrseduc , re vce(bootstrap , reps(399) seed(10101) ) ;
50. local se_re_bootstrap = _se[policy] ;
51. /* next, display output */
>
> qui log on t1out ;
52. di ;
53. di "OLS" ;
54. di ;
55. di ;
56. di "beta, " %8.4f `b_ols' ;
57. di "se def," %8.4f `se_ols_default' ;
58. di "se rob," %8.4f `se_ols_robust' ;
59. di "se clu," %8.4f `se_ols_cluster' ;
60. di "se boot," %8.4f `se_ols_bootstrap' ;
61. di ;
62. di "Num obs," %8.0f `N_ols' ;
63. di "Num clusters," %8.0f `G_ols' ;
64. di "Ng range," " `clusize_min' to `clusize_max'" ;
65. di "Rho, " %8.3f `rho' ;
66. di ;
67. di "Random effects" ;
68. di ;
69. di ;
70. di "beta, " %8.4f `b_re' ;
71. di "se def," %8.4f `se_re_default' ;
72. di "se rob," " - " ;
73. di "se clu," %8.4f `se_re_cluster' ;
74. di "se boot," %8.4f `se_re_bootstrap' ;
75. di ;
76. di "Num obs," %8.0f `N_re' ;
77. qui log off t1out ;
78. end ;
. runme ;
(label STATEFIP already defined)
Result # of obs.
-----------------------------------------
not matched 0
matched 65,685 (_merge==3)
-----------------------------------------
_merge | Freq. Percent Cum.
------------------------+-----------------------------------
matched (3) | 65,685 100.00 100.00
------------------------+-----------------------------------
Total | 65,685 100.00
Source | SS df MS Number of obs = 65685
-------------+------------------------------ F( 4, 65680) = 6200.90
Model | 7035.92988 4 1758.98247 Prob > F = 0.0000
Residual | 18631.1654 65680 .283665734 R-squared = 0.2741
-------------+------------------------------ Adj R-squared = 0.2741
Total | 25667.0953 65684 .390766325 Root MSE = .5326
------------------------------------------------------------------------------
lnwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0108393 .004176 2.60 0.009 .0026544 .0190241
age | .0739416 .001337 55.30 0.000 .0713211 .0765621
age2 | -.0007438 .0000159 -46.89 0.000 -.0007749 -.0007127
yrseduc | .0997156 .0007671 129.99 0.000 .0982121 .1012191
_cons | -.427386 .0282196 -15.15 0.000 -.4826964 -.3720757
------------------------------------------------------------------------------
Linear regression Number of obs = 65685
F( 4, 65680) = 5858.20
Prob > F = 0.0000
R-squared = 0.2741
Root MSE = .5326
------------------------------------------------------------------------------
| Robust
lnwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0108393 .0041821 2.59 0.010 .0026424 .0190361
age | .0739416 .0013218 55.94 0.000 .0713508 .0765324
age2 | -.0007438 .0000159 -46.87 0.000 -.0007749 -.0007127
yrseduc | .0997156 .0008136 122.56 0.000 .098121 .1013102
_cons | -.427386 .0276512 -15.46 0.000 -.4815824 -.3731897
------------------------------------------------------------------------------
Linear regression Number of obs = 65685
F( 4, 50) = 1368.19
Prob > F = 0.0000
R-squared = 0.2741
Root MSE = .5326
(Std. Err. adjusted for 51 clusters in statefip)
------------------------------------------------------------------------------
| Robust
lnwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0108393 .0228967 0.47 0.638 -.0351502 .0568287
age | .0739416 .0016335 45.27 0.000 .0706606 .0772227
age2 | -.0007438 .0000188 -39.52 0.000 -.0007816 -.000706
yrseduc | .0997156 .0017455 57.13 0.000 .0962097 .1032215
_cons | -.427386 .0402531 -10.62 0.000 -.5082367 -.3465353
------------------------------------------------------------------------------
(running regress on estimation sample)
Bootstrap replications (399)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.................................................. 50
.................................................. 100
.................................................. 150
.................................................. 200
.................................................. 250
.................................................. 300
.................................................. 350
.................................................
Linear regression Number of obs = 65685
Replications = 399
Wald chi2(4) = 6047.80
Prob > chi2 = 0.0000
R-squared = 0.2741
Adj R-squared = 0.2741
Root MSE = 0.5326
(Replications based on 51 clusters in statefip)
------------------------------------------------------------------------------
| Observed Bootstrap Normal-based
lnwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0108393 .02242 0.48 0.629 -.0331031 .0547816
age | .0739416 .0015024 49.22 0.000 .070997 .0768862
age2 | -.0007438 .0000178 -41.68 0.000 -.0007788 -.0007088
yrseduc | .0997156 .001692 58.94 0.000 .0963994 .1030317
_cons | -.427386 .0383132 -11.16 0.000 -.5024785 -.3522936
------------------------------------------------------------------------------
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
clusize | 51 1287.941 906.6592 519 5866
One-way Analysis of Variance for tab1_resid: Residuals
Number of obs = 65685
R-squared = 0.0183
Source SS df MS F Prob > F
-------------------------------------------------------------------------
Between statefip 340.3613 50 6.8072259 24.43 0.0000
Within statefip 18290.804 65634 .2786788
-------------------------------------------------------------------------
Total 18631.165 65684 .28364846
Intraclass Asy.
correlation S.E. [95% Conf. Interval]
------------------------------------------------
0.01804 0.00439 0.00944 0.02664
Estimated SD of statefip effect .0715452
Estimated SD within statefip .5279004
Est. reliability of a statefip mean 0.95906
(evaluated at n=1275.43)
intraclass correation = .0180365115611955
panel variable: statefip (unbalanced)
Random-effects GLS regression Number of obs = 65685
Group variable: statefip Number of groups = 51
R-sq: within = 0.2705 Obs per group: min = 519
between = 0.5073 avg = 1287.9
overall = 0.2738 max = 5866
Wald chi2(4) = 24378.97
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
------------------------------------------------------------------------------
lnwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0313806 .0199321 1.57 0.115 -.0076857 .0704469
age | .0737589 .0013265 55.60 0.000 .0711589 .0763588
age2 | -.0007416 .0000157 -47.12 0.000 -.0007725 -.0007108
yrseduc | .0986358 .0007668 128.64 0.000 .0971329 .1001386
_cons | -.4360083 .0311989 -13.98 0.000 -.4971571 -.3748595
-------------+----------------------------------------------------------------
sigma_u | .06919635
sigma_e | .52790317
rho | .01689116 (fraction of variance due to u_i)
------------------------------------------------------------------------------
Random-effects GLS regression Number of obs = 65685
Group variable: statefip Number of groups = 51
R-sq: within = 0.2705 Obs per group: min = 519
between = 0.5073 avg = 1287.9
overall = 0.2738 max = 5866
Wald chi2(4) = 5933.54
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
(Std. Err. adjusted for 51 clusters in statefip)
------------------------------------------------------------------------------
| Robust
lnwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0313806 .021422 1.46 0.143 -.0106057 .0733669
age | .0737589 .0015954 46.23 0.000 .0706319 .0768858
age2 | -.0007416 .0000185 -40.16 0.000 -.0007778 -.0007054
yrseduc | .0986358 .0015316 64.40 0.000 .0956338 .1016377
_cons | -.4360083 .0411843 -10.59 0.000 -.5167282 -.3552885
-------------+----------------------------------------------------------------
sigma_u | .06919635
sigma_e | .52790317
rho | .01689116 (fraction of variance due to u_i)
------------------------------------------------------------------------------
Iteration 1: tolerance = .02025086
Iteration 2: tolerance = .00020521
Iteration 3: tolerance = 2.513e-06
Iteration 4: tolerance = 3.074e-08
GEE population-averaged model Number of obs = 65685
Group variable: statefip Number of groups = 51
Link: identity Obs per group: min = 519
Family: Gaussian avg = 1287.9
Correlation: exchangeable max = 5866
Wald chi2(4) = 5943.02
Scale parameter: .2840842 Prob > chi2 = 0.0000
(Std. Err. adjusted for clustering on statefip)
------------------------------------------------------------------------------
| Robust
lnwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0315239 .0214323 1.47 0.141 -.0104826 .0735303
age | .0737576 .001595 46.24 0.000 .0706313 .0768838
age2 | -.0007416 .0000185 -40.17 0.000 -.0007778 -.0007054
yrseduc | .0986223 .0015297 64.47 0.000 .095624 .1016205
_cons | -.43603 .0411934 -10.58 0.000 -.5167675 -.3552924
------------------------------------------------------------------------------
(running xtreg on estimation sample)
Bootstrap replications (399)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.................................................. 50
.................................................. 100
.................................................. 150
.................................................. 200
.................................................. 250
.................................................. 300
.................................................. 350
.................................................
Random-effects GLS regression Number of obs = 65685
Group variable: statefip Number of groups = 51
R-sq: within = 0.2705 Obs per group: min = 519
between = 0.5073 avg = 1287.9
overall = 0.2738 max = 5866
Wald chi2(4) = 6273.36
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
(Replications based on 51 clusters in statefip)
------------------------------------------------------------------------------
| Observed Bootstrap Normal-based
lnwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
policy | .0313806 .0216008 1.45 0.146 -.0109562 .0737174
age | .0737589 .0014781 49.90 0.000 .0708618 .0766559
age2 | -.0007416 .0000177 -42.01 0.000 -.0007762 -.000707
yrseduc | .0986358 .0015458 63.81 0.000 .0956061 .1016655
_cons | -.4360083 .0395176 -11.03 0.000 -.5134613 -.3585553
-------------+----------------------------------------------------------------
sigma_u | .06919635
sigma_e | .52790317
rho | .01689116 (fraction of variance due to u_i)
------------------------------------------------------------------------------
OLS
beta, 0.0108
se def, 0.0042
se rob, 0.0042
se clu, 0.0229
se boot, 0.0224
Num obs, 65685
Num clusters, 51
Ng range, 519 to 5866
Rho, 0.018
Random effects
beta, 0.0314
se def, 0.0199
se rob, -
se clu, 0.0214
se boot, 0.0216
Num obs, 65685
. qui log close t1out ;
. log close _all ;
name:
log: C:\doug work\Colin\JHR cluster paper\work Summer 2014\empirical example code\table1.log
log type: text
closed on: 25 Jun 2014, 20:29:26
--------------------------------------------------------------------------------------------------------------------------------------------