makedata.do:112 makedata.do:117 makedata.do:122 |
[17] | [+] l${madedat}/CPS_2012_micro | ||
makedata.do:112 makedata.do:117 makedata.do:122 |
[30] | [+] l${madedat}/CPS_2012_micro | ||
[33] | statelist | |||
[65] | bootout | |||
[76] | maindata | |||
[101] | to_be_sampled | |||
[114] | maindata | |||
[148] | bsout | |||
[163] | bsout | |||
[167] | rad | |||
doall.do:5 | ||||
→ | t1_boot_breakdown.do | ↘ | ||
t1_boot_breakdown.log |
[3] | |||
set_directory_macros.do |
[9] | |||
maindata |
[55] | |||
to_be_sampled |
[82] | |||
G6_boot_density.png |
[70] | |||
bsout |
[155] | |||
bsout |
[92] | |||
rad |
[161] | |||
G6_Wild_CDFs.png |
[173] | |||
G6_Wild_CDFs_ZOOM.png |
[179] | |||
statelist |
[27] |
t1_boot_breakdown.do open
file:script:do
# | content log |
---|---|
1 [+] | #delimit |
2 [+] | cap log close |
3 [+] | log using t1_boot_breakdown.log , |
5 [+] | clear |
6 [+] | set seed 9479826 |
7 [+] | set more off |
9 [+] | do set_directory_macros |
11 [+] | cap prog drop runme |
12 [+] | prog def runme |
14 [+] | local bsreps = 999 |
/* generate state policy variable */ |
|
17 [+] | use statefip using "${madedat}/CPS_2012_micro" , |
18 [+] | contract statefip |
19 [+] | generate sort_order = uniform() |
20 [+] | sort sort_order |
21 [+] | keep if _n <= 6 |
22 [+] | gen policy = _n <= 3 |
23 [+] | sort statefip |
24 [+] | drop sort_order _freq |
26 [+] | tempfile statelist |
27 [+] | qui save `statelist' |
30 [+] | use "${madedat}/CPS_2012_micro" , |
32 [+] | sort statefip |
33 [+] | merge m:1 statefip using `statelist' |
34 [+] | tab _merge |
35 [+] | keep if _merge == 3 |
36 [+] | drop _merge |
37 [+] | tab statefip |
/* first run the basic regressions for G=6 */ |
|
42 [+] | reg lnwage policy age age2 yrseduc |
43 [+] | reg lnwage policy age age2 yrseduc , |
44 [+] | reg lnwage policy age age2 yrseduc , |
45 [+] | local main_b = _b[policy] |
46 [+] | local main_se = _se[policy] |
/* the hypothesis is: beta on policy = 0. So to estimtate imposing this restriction, we will just drop "policy" from the regression */ |
|
50 [+] | reg lnwage age age2 yrseduc |
51 [+] | predict resid_restricted , |
52 [+] | predict yhat_restricted , |
53 [+] | sort statefip |
54 [+] | tempfile maindata |
55 [+] | qui save `maindata' |
/* next we do a nonparametric bootstrap; show that the resulting distribution of the bootstrapped betas can be non-normal and multimodal */ |
|
60 [+] | tempfile bootout |
61 [+] | reg lnwage policy age age2 yrseduc , |
64 [+] | drop _all |
65 [+] | use `bootout' |
67 [+] | summ |
68 [+] | summ _b_policy , |
69 [+] | kdensity _b_policy , |
70 [+] | graph export G6_boot_density.png , |
/* next we do a wild bootstrap, Rademacher weights (+-1), and show that the resulting distribution of t-statistics takes only a few values (and hence the p-value of the main t-staistic is only interval-identified We will do the same with the Webb 6-point distribution, to see that the t-stats has a much more "continuous" distribution. */ |
|
76 [+] | use `maindata' , |
77 [+] | keep statefip |
78 [+] | contract statefip |
79 [+] | drop _freq |
80 [+] | sort statefip |
81 [+] | tempfile to_be_sampled |
82 [+] | qui save `to_be_sampled' |
83 [+] | list |
86 [+] | local main_t = (`main_b' - 0) / `main_se' |
89 [+] | cap postclose bs_output |
90 [+] | tempfile bsout |
91 [+] | cap erase `bsout' |
92 [+] | postfile bs_output t_rad_res t_webb_res using `bsout' |
94 [+] | qui forvalues bb = 1/`bsreps' { |
99 [+] | /* then estimate the models, and save the t-statistics */ |
101 [+] | use statefip using `to_be_sampled' , |
102 [+] | gen my_uniform = uniform() |
103 [+] | gen wild_rademacher = -1 + 2 * (my_uniform >= 0.5) |
104 [+] | gen wild_webb = (-1) * sqrt(1.5) * (my_uniform > (0) & my_uniform <= (1/6)) + (-1) * sqrt(1) * (my_uniform > (1/6) & my_uniform <= (2/6)) + (-1) * sqrt(0.5) * (my_uniform > (2/6) & my_uniform <= (3/6)) + (+1) * sqrt(0.5) * (my_uniform > (3/6) & my_uniform <= (4/6)) + (+1) * sqrt(1) * (my_uniform > (4/6) & my_uniform <= (5/6)) + (+1) * sqrt(1.5) * (my_uniform > (5/6) & my_uniform <= (6/6)) |
111 [+] | keep statefip wild_rademacher wild_webb |
112 [+] | sort statefip |
114 [+] | merge 1:m statefip using `maindata' , |
/* create transformed residuals and new wild-outcome-variables */ |
|
117 [+] | gen resid_wild_rad_restricted = resid_restricted * wild_rademacher |
118 [+] | gen resid_wild_webb_restricted = resid_restricted * wild_webb |
120 [+] | gen y_wild_rademacher_restricted = yhat_restricted + resid_wild_rad_restricted |
121 [+] | gen y_wild_webb_restricted = yhat_restricted + resid_wild_webb_restricted |
123 [+] | /* now estimate cluster-robust models on each of these three, generating t-statistics. For the restricted model, the t-stat is based on the null hypothesis. for the unrestricted model the t-stat is based on the main (first) estiamted beta */ |
127 [+] | reg y_wild_rademacher_restricted policy age age2 yrseduc , |
128 [+] | local b_wild_rademacher_restricted = _b[policy] |
129 [+] | local se_wild_rademacher_restricted = _se[policy] |
131 [+] | reg y_wild_webb_restricted policy age age2 yrseduc , |
132 [+] | local b_wild_webb_restricted = _b[policy] |
133 [+] | local se_wild_webb_restricted = _se[policy] |
135 [+] | /* make the t-stats ; store away into a postfile */ |
137 [+] | local t_wild_rademacher_restricted = (`b_wild_rademacher_restricted ' - 0) / `se_wild_rademacher_restricted' |
139 [+] | local t_wild_webb_restricted = (`b_wild_webb_restricted ' - 0) / `se_wild_webb_restricted' |
142 [+] | post bs_output (`t_wild_rademacher_restricted') (`t_wild_webb_restricted') |
144 [+] | } |
146 [+] | postclose bs_output |
148 [+] | use `bsout' , |
149 [+] | summ |
150 [+] | gen one = 1 |
151 [+] | sort t_rad_res |
152 [+] | gen Rademacher = sum(one) / _N |
153 [+] | sort t_webb_res |
154 [+] | gen Webb = sum(one) / _N |
155 [+] | qui save `bsout' , |
157 [+] | keep Rademacher t_rad_res |
158 [+] | rename t_rad_res t_stat |
159 [+] | tempfile rad |
160 [+] | sort t_stat |
161 [+] | qui save `rad' |
163 [+] | qui use `bsout' |
164 [+] | keep Webb t_webb_res |
165 [+] | rename t_webb_res t_stat |
166 [+] | sort t_stat |
167 [+] | merge t_stat using `rad' |
168 [+] | sort t_stat Rademacher Webb |
169 [+] | summ |
171 [+] | graph twoway (line Rademacher t_stat) (line Webb t_stat) , |
173 [+] | graph export G6_Wild_CDFs.png , |
175 [+] | local lower = `main_t' - 0.04 |
176 [+] | local upper = `main_t' + 0.04 |
177 [+] | graph twoway (line Rademacher t_stat if t_stat >= `lower' & t_stat <= `upper') (line Webb t_stat if t_stat >= `lower' & t_stat <= `upper') , |
179 [+] | graph export G6_Wild_CDFs_ZOOM.png , |
181 [+] | end |
183 [+] | runme |
185 [+] | log close _all |
#delimit ; cap log close ; log using t1_boot_breakdown.log, text replace ; clear ; set seed 9479826 ; set more off ; do set_directory_macros ; cap prog drop runme ; prog def runme ; local bsreps = 999 ; /* generate state policy variable */ use statefip using "${madedat}/CPS_2012_micro" , replace ; contract statefip ; generate sort_order = uniform() ; sort sort_order ; keep if _n <= 6 ; gen policy = _n <= 3 ; sort statefip ; drop sort_order _freq ; tempfile statelist ; qui save `statelist' ; use "${madedat}/CPS_2012_micro" , replace ; sort statefip ; merge m:1 statefip using `statelist' ; tab _merge ; keep if _merge == 3 ; drop _merge ; tab statefip ; /* first run the basic regressions for G=6 */ reg lnwage policy age age2 yrseduc ; reg lnwage policy age age2 yrseduc , robust ; reg lnwage policy age age2 yrseduc , cluster(statefip) ; local main_b = _b[policy] ; local main_se = _se[policy] ; /* generate restricted residuals, and y-hats; these will be used later in the Wild bootstraps */ /* the hypothesis is: beta on policy = 0. So to estimtate imposing this restriction, we will just drop "policy" from the regression */ reg lnwage age age2 yrseduc ; predict resid_restricted , resid ; predict yhat_restricted , xb ; sort statefip ; tempfile maindata ; qui save `maindata' ; /* next we do a nonparametric bootstrap; show that the resulting distribution of the bootstrapped betas can be non-normal and multimodal */ tempfile bootout ; reg lnwage policy age age2 yrseduc , vce(bootstrap , cluster(statefip) reps(`bsreps') saving(`bootout') ) ; drop _all ; use `bootout' ; summ ; summ _b_policy , detail ; kdensity _b_policy , bw(0.004) n(400) ; graph export G6_boot_density.png , replace ; /* next we do a wild bootstrap, Rademacher weights (+-1), and show that the resulting distribution of t-statistics takes only a few values (and hence the p-value of the main t-staistic is only interval-identified We will do the same with the Webb 6-point distribution, to see that the t-stats has a much more "continuous" distribution. */ use `maindata' , clear ; keep statefip ; contract statefip ; drop _freq ; sort statefip ; tempfile to_be_sampled ; qui save `to_be_sampled' ; list ; local main_t = (`main_b' - 0) / `main_se' ; cap postclose bs_output ; tempfile bsout ; cap erase `bsout' ; postfile bs_output t_rad_res t_webb_res using `bsout' ; qui forvalues bb = 1/`bsreps' { ; /* for the wild bootstrap */ /* take the cluster list, generate 3 sets of residual transformations */ /* then merge these back onto main dataset, created transformed residuals and then transformed y-hats */ /* then estimate the models, and save the t-statistics */ use statefip using `to_be_sampled' , replace ; gen my_uniform = uniform() ; gen wild_rademacher = -1 + 2 * (my_uniform >= 0.5) ; gen wild_webb = (-1) * sqrt(1.5) * (my_uniform > (0) & my_uniform <= (1/6)) + (-1) * sqrt(1) * (my_uniform > (1/6) & my_uniform <= (2/6)) + (-1) * sqrt(0.5) * (my_uniform > (2/6) & my_uniform <= (3/6)) + (+1) * sqrt(0.5) * (my_uniform > (3/6) & my_uniform <= (4/6)) + (+1) * sqrt(1) * (my_uniform > (4/6) & my_uniform <= (5/6)) + (+1) * sqrt(1.5) * (my_uniform > (5/6) & my_uniform <= (6/6)) ; keep statefip wild_rademacher wild_webb ; sort statefip ; merge 1:m statefip using `maindata' , assert(match) keep(match) nogenerate ; /* create transformed residuals and new wild-outcome-variables */ gen resid_wild_rad_restricted = resid_restricted * wild_rademacher ; gen resid_wild_webb_restricted = resid_restricted * wild_webb ; gen y_wild_rademacher_restricted = yhat_restricted + resid_wild_rad_restricted ; gen y_wild_webb_restricted = yhat_restricted + resid_wild_webb_restricted ; /* now estimate cluster-robust models on each of these three, generating t-statistics. For the restricted model, the t-stat is based on the null hypothesis. for the unrestricted model the t-stat is based on the main (first) estiamted beta */ reg y_wild_rademacher_restricted policy age age2 yrseduc , cluster(statefip) ; local b_wild_rademacher_restricted = _b[policy] ; local se_wild_rademacher_restricted = _se[policy] ; reg y_wild_webb_restricted policy age age2 yrseduc , cluster(statefip) ; local b_wild_webb_restricted = _b[policy] ; local se_wild_webb_restricted = _se[policy] ; /* make the t-stats ; store away into a postfile */ local t_wild_rademacher_restricted = (`b_wild_rademacher_restricted ' - 0) / `se_wild_rademacher_restricted' ; local t_wild_webb_restricted = (`b_wild_webb_restricted ' - 0) / `se_wild_webb_restricted' ; post bs_output (`t_wild_rademacher_restricted') (`t_wild_webb_restricted') ; } ; postclose bs_output ; use `bsout' , clear ; summ ; gen one = 1 ; sort t_rad_res ; gen Rademacher = sum(one) / _N ; sort t_webb_res ; gen Webb = sum(one) / _N ; qui save `bsout' , replace ; keep Rademacher t_rad_res ; rename t_rad_res t_stat ; tempfile rad ; sort t_stat ; qui save `rad' ; qui use `bsout' ; keep Webb t_webb_res ; rename t_webb_res t_stat ; sort t_stat ; merge t_stat using `rad' ; sort t_stat Rademacher Webb ; summ ; graph twoway (line Rademacher t_stat) (line Webb t_stat) , xline(`main_t') ti("CDFs of Bootstrapped t-distributions") note("Note: 6 Clusters. 999 bootstrap replications. Vertical line at main t-statistic.") ; graph export G6_Wild_CDFs.png , replace ; local lower = `main_t' - 0.04 ; local upper = `main_t' + 0.04 ; graph twoway (line Rademacher t_stat if t_stat >= `lower' & t_stat <= `upper') (line Webb t_stat if t_stat >= `lower' & t_stat <= `upper') , xline(`main_t') ti("CDFs of Bootstrapped t-distributions") note("Note: 6 Clusters. 999 bootstrap replications. Vertical line at main t-statistic. Zoomed in near main t-staistic.") ; graph export G6_Wild_CDFs_ZOOM.png , replace ; end ; runme ; log close _all ;