| [42] | sourcedata | |||
| [64] | statelist | |||
| [81] | sourcedata | |||
| [88] | to_be_sampled | |||
| [134] | main_data | |||
| [142] | pairs_bs_out | |||
| [164] | to_be_sampled | |||
| [176] | main_data | |||
| [228] | bsout | |||
| [229] | pairs_bs_out | |||
| [241] | bsout | |||
|
t2_mcloop.do:29 |
[295] | [+] lt2_post_G`numstates'..ate'.dta | ||
| table2.do:13 | ||||
| → | t2_mcloop.do | ↘ | ||
|
[+] "t2_post_G`numstates..e'.dta"
|
[29] |
t2_mcloop.do:295 |
||
|
to_be_sampled |
[76] | |||
|
main_data |
[121] | |||
|
pairs_bs_out |
[148] | |||
|
bsout |
[231] | |||
|
bsout |
[155] | |||
|
savedata |
[296] | |||
|
statelist |
[46] | |||
t2_mcloop.do open
file:script:do
| # | content |
|---|---|
| 1 [+] | #delimit |
| 3 [+] | /* this program sets up the MC loop for Table 2 It has the following inputs in the the program: mcreps how many monte carlo reps bsrep how many bootstrap replications numstates how many clusters sourcedata a data file, which has the course data savedata a data file - the output of the Monte Carlo program gets written to this data file. */ |
| 16 [+] | cap prog drop do_the_monte_carlo |
| 17 [+] | prog def do_the_monte_carlo |
| 18 [+] | syntax , |
| 20 [+] | /* get ready to run the monte carlo */ |
| 22 [+] | tempfile to_be_sampled main_data bsout pairs_bs_out |
| 24 [+] | local mydate = subinstr("$S_DATE"," ","_",.) |
| 25 [+] | cap erase "t2_post_`mydate'.dta" |
| 27 [+] | local postlist = "b se_rob se_clu se_CR2 se_CR3 dof_CR2_IK dof_CSS se_clu_bs bs_misreps p_pairs_bs p_rad_res p_rad_res_high p_rad_res_low p_rad_unres p_webb_res " |
| 28 [+] | cap postclose mcoutput |
| 29 [+] | qui postfile mcoutput numobs numstates K numbsreps `postlist' using "t2_post_G`numstates'_`mydate'.dta" , |
| 31 [+] | di "MC Reps = `mcreps', BS Reps = `bsreps', Number of states sampled = `numstates'" |
| 32 [+] | di "Using data from `sourcedata'" |
| 34 [+] | local lhs = "lnwage" |
| 35 [+] | local key_rhs = "policy" |
| 36 [+] | local rhs = "`key_rhs' age age2 yrseduc" |
| 37 [+] | local command = "reg `lhs' `rhs' , cluster(pseudo_cluster) " |
| 39 [+] | local beta_hypothesis = 0 |
| 41 [+] | tempfile statelist |
| 42 [+] | qui use statefip using "`sourcedata'" |
| 43 [+] | contract statefip |
| 44 [+] | keep statefip |
| 45 [+] | sort statefip |
| 46 [+] | qui save "`statelist'" |
/* the main loop */ |
|
| 50 [+] | qui forvalues mc = 1/`mcreps' { |
| 52 [+] | noi di "." _continue |
| 53 [+] | if (mod(`mc',100) == 1) { |
| 54 [+] | noi di " `mc' " _continue |
| 55 [+] | } |
/* make sure we don't post last round's data to this round */ |
|
| 58 [+] | foreach zz in `postlist' { |
| 59 [+] | local `zz' = "." |
| 60 [+] | } |
| 62 [+] | /* generate the data */ |
| 64 [+] | use `statelist' , |
| 65 [+] | bsample `numstates' |
/* assign treatment dummy to 1/2 of states (round down) */ |
|
| 67 [+] | gen sortvar = uniform() |
| 68 [+] | sort sortvar |
| 69 [+] | gen policy = _n / _N <= 0.5 |
/* generate pseudo-cluster-ids for later */ |
|
| 71 [+] | sort statefip |
| 72 [+] | qui by statefip: gen subid = _n |
| 73 [+] | egen pseudo_cluster = group(statefip subid) |
| 74 [+] | keep statefip subid pseudo_cluster policy |
| 75 [+] | sort statefip subid |
| 76 [+] | save `to_be_sampled' , |
| 78 [+] | keep statefip |
| 79 [+] | contract statefip |
| 80 [+] | sort statefip |
| 81 [+] | merge 1:m statefip using "`sourcedata'" , |
| 83 [+] | gen personid = _n |
| 84 [+] | expand _freq |
| 85 [+] | sort personid |
| 86 [+] | qui by personid: gen subid = _n |
| 87 [+] | sort statefip subid |
| 88 [+] | merge m:1 statefip subid using `to_be_sampled' , |
| 91 [+] | /* estimate the models */ |
| 93 [+] | reg lnwage policy age age2 yrseduc , |
| 94 [+] | local b = _b[policy] |
| 95 [+] | local se_rob = _se[policy] |
| 96 [+] | local K = e(rank) |
| 97 [+] | local numobs = e(N) |
| 99 [+] | tempname betavec v_naive |
| 100 [+] | matrix `betavec' = e(b) |
/* generate residuals. Also, generate "restricted, impose the null hypothesis" residuals */ |
|
| 103 [+] | predict yhat , |
| 104 [+] | predict resid , |
| 106 [+] | replace `lhs' = `lhs' - `beta_hypothesis' * `key_rhs' |
| 107 [+] | local shortcommand = subinstr("`command'","`key_rhs'","",.) |
| 108 [+] | `shortcommand' |
| 109 [+] | predict resid_restricted , |
| 110 [+] | predict yhat_restricted , |
| 111 [+] | replace yhat_restricted = yhat_restricted + (`beta_hypothesis' * `key_rhs') |
| 112 [+] | replace `lhs' = `lhs' + `beta_hypothesis' * `key_rhs' |
| 115 [+] | reg lnwage policy age age2 yrseduc , |
| 116 [+] | local se_clu = _se[policy] |
| 118 [+] | gen one = 1 |
| 119 [+] | sort pseudo_cluster |
| 120 [+] | gen obsnum = _n |
| 121 [+] | save `main_data' , |
/* get the CR2, CR3 standard errors adjustments. Also get I-K degrees of freedom, and CSS effective number of clusters */ |
|
| 125 [+] | CR23_IK_CSS , |
| 127 [+] | foreach r in se_CR2 se_CR3 dof_CR2_IK dof_CSS { |
| 128 [+] | local `r' = r(`r') |
| 129 [+] | } |
/* do nonparametric bootstraps: for standard errors */ |
|
| 134 [+] | use `main_data' , |
| 135 [+] | cap erase `pairs_bs_out' |
| 137 [+] | qui bootstrap _b _se , reps(`bsreps') nodots cluster(pseudo_cluster) idcluster(pseudo_cluster_2) saving(`pairs_bs_out' , double) : reg lnwage policy age age2 yrseduc , |
| 139 [+] | local se_clu_bs = _se[policy] |
| 140 [+] | local bs_misreps = e(N_misreps) |
| 142 [+] | use `pairs_bs_out' , |
| 143 [+] | keep _b_policy _se_policy |
| 144 [+] | gen t_pairs_bs = ((_b_policy - `b') / _se_policy) |
| 145 [+] | keep t_pairs_bs |
| 147 [+] | summ |
| 148 [+] | save `pairs_bs_out' , |
/* Do percentile-T bootstraps */ |
|
| 151 [+] | local main_t = (`b' - `beta_hypothesis') / `se_clu' |
| 153 [+] | cap postclose bs_output |
| 154 [+] | cap erase `bsout' |
| 155 [+] | postfile bs_output t_rad_res t_rad_unres t_webb_res using `bsout' |
| 157 [+] | qui forvalues bb = 1/`bsreps' { |
| 162 [+] | /* then estimate the models, and save the t-statistics */ |
| 164 [+] | use pseudo_cluster using `to_be_sampled' , |
| 165 [+] | gen my_uniform = uniform() |
| 166 [+] | gen wild_rademacher = -1 + 2 * (my_uniform >= 0.5) |
| 167 [+] | 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)) |
| 174 [+] | keep pseudo_cluster wild_rademacher wild_webb |
| 175 [+] | sort pseudo_cluster |
| 176 [+] | merge 1:m pseudo_cluster using `main_data' , |
/* create transformed residuals and new wild-outcome-variables */ |
|
| 179 [+] | gen resid_wild_rad_restricted = resid_restricted * wild_rademacher |
| 180 [+] | gen resid_wild_rad_unrestricted = resid * wild_rademacher |
| 181 [+] | gen resid_wild_webb_restricted = resid_restricted * wild_webb |
| 183 [+] | gen y_wild_rademacher_restricted = yhat_restricted + resid_wild_rad_restricted |
| 184 [+] | gen y_wild_rademacher_unrestricted = yhat + resid_wild_rad_unrestricted |
| 185 [+] | gen y_wild_webb_restricted = yhat_restricted + resid_wild_webb_restricted |
| 187 [+] | /* 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 */ |
| 191 [+] | local shortcommand = subinstr("`command'","`lhs'","y_wild_rademacher_restricted",.) |
| 192 [+] | `shortcommand' |
| 193 [+] | local b_wild_rademacher_restricted = _b[`key_rhs'] |
| 194 [+] | local se_wild_rademacher_restricted = _se[`key_rhs'] |
| 196 [+] | local shortcommand = subinstr("`command'","`lhs'","y_wild_rademacher_unrestricted",.) |
| 197 [+] | `shortcommand' |
| 198 [+] | local b_wild_rademacher_unrestricted = _b[`key_rhs'] |
| 199 [+] | local se_wild_rademacher_unrestricted = _se[`key_rhs'] |
| 201 [+] | local shortcommand = subinstr("`command'","`lhs'","y_wild_webb_restricted",.) |
| 202 [+] | `shortcommand' |
| 203 [+] | local b_wild_webb_restricted = _b[`key_rhs'] |
| 204 [+] | local se_wild_webb_restricted = _se[`key_rhs'] |
| 206 [+] | /* make the t-stats ; store away into a postfile */ |
| 208 [+] | local t_wild_rademacher_restricted = (`b_wild_rademacher_restricted ' - `beta_hypothesis') / `se_wild_rademacher_restricted' |
| 210 [+] | local t_wild_rademacher_unrestricted = (`b_wild_rademacher_unrestricted ' - `b') / `se_wild_rademacher_unrestricted' |
| 212 [+] | local t_wild_webb_restricted = (`b_wild_webb_restricted ' - `beta_hypothesis') / `se_wild_webb_restricted' |
| 215 [+] | post bs_output (`t_wild_rademacher_restricted') (`t_wild_rademacher_unrestricted') (`t_wild_webb_restricted') |
| 217 [+] | } |
| 219 [+] | postclose bs_output |
| 221 [+] | /* identify percentiles in the bootstrap distribution, to get p-values and/or rejection rates */ |
| 223 [+] | /* to get these percentiles, we will make lists of t-stats, with the "main" t-stat stuck into this list we wante to know what the p-value of this main t-stat is. Because with wild, few clusters, we can get intervals, we will use mean-p-value [is this what we want?] of the interval. */ |
| 227 [+] | drop _all |
| 228 [+] | use `bsout' |
| 229 [+] | merge 1:1 _n using `pairs_bs_out' , |
| 230 [+] | summ |
| 231 [+] | save `bsout' , |
| 233 [+] | drop _all |
| 234 [+] | set obs 1 |
| 235 [+] | gen t_rad_res = `main_t' |
| 236 [+] | gen t_rad_unres = `main_t' |
| 237 [+] | gen t_webb_res = `main_t' |
| 238 [+] | gen t_pairs_bs = `main_t' |
//summ ; |
|
| 241 [+] | append using `bsout' |
| 242 [+] | gen rank = . |
| 243 [+] | //summ ; |
| 245 [+] | /* //noi di "main_t = `main_t'" ; //noi tab t_rad_res ; //noi tab t_rad_unres ; //noi tab t_webb_res ; */ |
| 252 [+] | foreach var in pairs_bs rad_res rad_unres webb_res { |
| 254 [+] | sort t_`var' |
| 255 [+] | replace rank = _n |
| 256 [+] | summ t_`var' |
| 257 [+] | local maxrank = r(N) |
| 258 [+] | summ rank if abs(t_`var' - `main_t') < 0.0001 |
| 259 [+] | local meanrank = r(mean) |
| 260 [+] | local toprank = r(max) |
| 261 [+] | local botrank = r(min) |
| 262 [+] | local pctile = `meanrank' / `maxrank' |
| 263 [+] | local myp = 2 * min(`pctile' , (1-`pctile')) |
| 264 [+] | local p_`var' = `myp' |
/* for two point wild bootstraps with few clusters, have interval-p-value problem. This gets at ends of the interval */ |
|
| 268 [+] | local pctile_top = `toprank' / `maxrank' |
| 269 [+] | local myp1 = 2 * min(`pctile_top' , (1-`pctile_top')) |
| 270 [+] | local pctile_bot = `botrank' / `maxrank' |
| 271 [+] | local myp2 = 2 * min(`pctile_bot' , (1-`pctile_bot')) |
| 273 [+] | local p_`var'_high = max(`myp1',`myp2') |
| 274 [+] | local p_`var'_low = min(`myp1',`myp2') |
| 276 [+] | } |
| 278 [+] | /* //foreach zz in `postlist' { ; // noi di "`zz' = ``zz'' " ; //} ; */ |
| 284 [+] | /* save the results */ |
| 286 [+] | post mcoutput (`numobs') (`numstates') (`K') (`bsreps') (`b') (`se_rob') (`se_clu') (`se_CR2') (`se_CR3') (`dof_CR2_IK') (`dof_CSS') (`se_clu_bs') (`bs_misreps') (`p_pairs_bs') (`p_rad_res') (`p_rad_res_high') (`p_rad_res_low') (`p_rad_unres') (`p_webb_res') |
| 289 [+] | } |
/* now, take the whole package of results and save them */ |
|
| 293 [+] | postclose mcoutput |
| 295 [+] | use "t2_post_G`numstates'_`mydate'.dta" , |
| 296 [+] | qui save `savedata' , |
| 298 [+] | di |
| 301 [+] | end |
#delimit ;
/* this program sets up the MC loop for Table 2
It has the following inputs in the the program:
mcreps how many monte carlo reps
bsrep how many bootstrap replications
numstates how many clusters
sourcedata a data file, which has the course data
savedata a data file - the output of the Monte Carlo program gets written to this data file.
*/
cap prog drop do_the_monte_carlo ;
prog def do_the_monte_carlo ;
syntax , [mcreps(integer 3) bsreps(integer 4) numstates(integer 6) sourcedata(string) savedata(string)] ;
/* get ready to run the monte carlo */
tempfile to_be_sampled main_data bsout pairs_bs_out ;
local mydate = subinstr("$S_DATE"," ","_",.) ;
cap erase "t2_post_`mydate'.dta" ;
local postlist = "b se_rob se_clu se_CR2 se_CR3 dof_CR2_IK dof_CSS se_clu_bs bs_misreps p_pairs_bs p_rad_res p_rad_res_high p_rad_res_low p_rad_unres p_webb_res " ;
cap postclose mcoutput ;
qui postfile mcoutput numobs numstates K numbsreps `postlist' using "t2_post_G`numstates'_`mydate'.dta" , replace ;
di "MC Reps = `mcreps', BS Reps = `bsreps', Number of states sampled = `numstates'" ;
di "Using data from `sourcedata'" ;
local lhs = "lnwage" ;
local key_rhs = "policy" ;
local rhs = "`key_rhs' age age2 yrseduc" ;
local command = "reg `lhs' `rhs' , cluster(pseudo_cluster) " ;
local beta_hypothesis = 0 ;
tempfile statelist ;
qui use statefip using "`sourcedata'" ;
contract statefip ;
keep statefip ;
sort statefip ;
qui save "`statelist'" ;
/* the main loop */
qui forvalues mc = 1/`mcreps' { ;
noi di "." _continue ;
if (mod(`mc',100) == 1) { ; /* every X reps, report progress */
noi di " `mc' " _continue ;
} ;
/* make sure we don't post last round's data to this round */
foreach zz in `postlist' { ;
local `zz' = "." ;
} ;
/* generate the data */
use `statelist' , replace ;
bsample `numstates' ;
/* assign treatment dummy to 1/2 of states (round down) */
gen sortvar = uniform() ;
sort sortvar ;
gen policy = _n / _N <= 0.5 ;
/* generate pseudo-cluster-ids for later */
sort statefip ;
qui by statefip: gen subid = _n ;
egen pseudo_cluster = group(statefip subid) ;
keep statefip subid pseudo_cluster policy ;
sort statefip subid ;
save `to_be_sampled' , replace ;
keep statefip ;
contract statefip ;
sort statefip ;
merge 1:m statefip using "`sourcedata'" , assert(match using) keep(match) nogenerate ;
gen personid = _n ;
expand _freq ; /* this was generated by the contract command; tells us how many replicates of each state to make */
sort personid ;
qui by personid: gen subid = _n ;
sort statefip subid ;
merge m:1 statefip subid using `to_be_sampled' , assert(match) keep(match) nogenerate ;
/* estimate the models */
reg lnwage policy age age2 yrseduc , robust ;
local b = _b[policy] ;
local se_rob = _se[policy] ;
local K = e(rank) ;
local numobs = e(N) ;
tempname betavec v_naive ;
matrix `betavec' = e(b) ;
/* generate residuals. Also, generate "restricted, impose the null hypothesis" residuals */
predict yhat , xb ;
predict resid , resid ;
replace `lhs' = `lhs' - `beta_hypothesis' * `key_rhs' ;
local shortcommand = subinstr("`command'","`key_rhs'","",.) ;
`shortcommand' ;
predict resid_restricted , residual ;
predict yhat_restricted , xb ;
replace yhat_restricted = yhat_restricted + (`beta_hypothesis' * `key_rhs') ;
replace `lhs' = `lhs' + `beta_hypothesis' * `key_rhs' ;
reg lnwage policy age age2 yrseduc , cluster(pseudo_cluster) ;
local se_clu = _se[policy] ;
gen one = 1 ;
sort pseudo_cluster ;
gen obsnum = _n ;
save `main_data' , replace ;
/* get the CR2, CR3 standard errors adjustments. Also get I-K degrees of freedom, and CSS effective number of clusters */
CR23_IK_CSS , betavec(`betavec') lhs(`lhs') rhs(`rhs') key_rhs(`key_rhs') main_data("`main_data'") ;
foreach r in se_CR2 se_CR3 dof_CR2_IK dof_CSS { ;
local `r' = r(`r') ;
} ;
/* do nonparametric bootstraps: for standard errors */
use `main_data' , replace ;
cap erase `pairs_bs_out' ;
qui bootstrap _b _se , reps(`bsreps') nodots cluster(pseudo_cluster) idcluster(pseudo_cluster_2) saving(`pairs_bs_out' , double)
: reg lnwage policy age age2 yrseduc , cluster(pseudo_cluster_2) ;
local se_clu_bs = _se[policy] ;
local bs_misreps = e(N_misreps) ;
use `pairs_bs_out' , replace ;
keep _b_policy _se_policy ;
gen t_pairs_bs = ((_b_policy - `b') / _se_policy) ;
keep t_pairs_bs ;
summ ;
save `pairs_bs_out' , replace ;
/* Do percentile-T bootstraps */
local main_t = (`b' - `beta_hypothesis') / `se_clu' ;
cap postclose bs_output ;
cap erase `bsout' ;
postfile bs_output t_rad_res t_rad_unres 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 pseudo_cluster 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 pseudo_cluster wild_rademacher wild_webb ;
sort pseudo_cluster ;
merge 1:m pseudo_cluster using `main_data' , 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_rad_unrestricted = resid * 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_rademacher_unrestricted = yhat + resid_wild_rad_unrestricted ;
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 */
local shortcommand = subinstr("`command'","`lhs'","y_wild_rademacher_restricted",.) ;
`shortcommand' ;
local b_wild_rademacher_restricted = _b[`key_rhs'] ;
local se_wild_rademacher_restricted = _se[`key_rhs'] ;
local shortcommand = subinstr("`command'","`lhs'","y_wild_rademacher_unrestricted",.) ;
`shortcommand' ;
local b_wild_rademacher_unrestricted = _b[`key_rhs'] ;
local se_wild_rademacher_unrestricted = _se[`key_rhs'] ;
local shortcommand = subinstr("`command'","`lhs'","y_wild_webb_restricted",.) ;
`shortcommand' ;
local b_wild_webb_restricted = _b[`key_rhs'] ;
local se_wild_webb_restricted = _se[`key_rhs'] ;
/* make the t-stats ; store away into a postfile */
local t_wild_rademacher_restricted = (`b_wild_rademacher_restricted ' - `beta_hypothesis')
/ `se_wild_rademacher_restricted' ;
local t_wild_rademacher_unrestricted = (`b_wild_rademacher_unrestricted ' - `b')
/ `se_wild_rademacher_unrestricted' ;
local t_wild_webb_restricted = (`b_wild_webb_restricted ' - `beta_hypothesis')
/ `se_wild_webb_restricted' ;
post bs_output (`t_wild_rademacher_restricted') (`t_wild_rademacher_unrestricted') (`t_wild_webb_restricted') ;
} ;
postclose bs_output ;
/* identify percentiles in the bootstrap distribution, to get p-values and/or rejection rates */
/* to get these percentiles, we will make lists of t-stats, with the "main" t-stat stuck into this list
we wante to know what the p-value of this main t-stat is. Because with wild, few clusters, we can get intervals,
we will use mean-p-value [is this what we want?] of the interval. */
drop _all ;
use `bsout' ;
merge 1:1 _n using `pairs_bs_out' , nogenerate ;
summ ;
save `bsout' , replace ;
drop _all ;
set obs 1 ;
gen t_rad_res = `main_t' ;
gen t_rad_unres = `main_t' ;
gen t_webb_res = `main_t' ;
gen t_pairs_bs = `main_t' ;
//summ ;
append using `bsout' ;
gen rank = . ;
//summ ;
/*
//noi di "main_t = `main_t'" ;
//noi tab t_rad_res ;
//noi tab t_rad_unres ;
//noi tab t_webb_res ;
*/
foreach var in pairs_bs rad_res rad_unres webb_res { ;
sort t_`var' ;
replace rank = _n ;
summ t_`var' ;
local maxrank = r(N) ; /* should be #bs reps; but this allows for missing bs values */
summ rank if abs(t_`var' - `main_t') < 0.0001 ; /* allow for machine error in t-stat computations in bootstrap step */
local meanrank = r(mean) ;
local toprank = r(max) ;
local botrank = r(min) ;
local pctile = `meanrank' / `maxrank' ;
local myp = 2 * min(`pctile' , (1-`pctile')) ;
local p_`var' = `myp' ;
/* for two point wild bootstraps with few clusters, have interval-p-value problem. This gets
at ends of the interval */
local pctile_top = `toprank' / `maxrank' ;
local myp1 = 2 * min(`pctile_top' , (1-`pctile_top')) ;
local pctile_bot = `botrank' / `maxrank' ;
local myp2 = 2 * min(`pctile_bot' , (1-`pctile_bot')) ;
local p_`var'_high = max(`myp1',`myp2') ;
local p_`var'_low = min(`myp1',`myp2') ;
} ;
/*
//foreach zz in `postlist' { ;
// noi di "`zz' = ``zz'' " ;
//} ;
*/
/* save the results */
post mcoutput (`numobs') (`numstates') (`K') (`bsreps') (`b') (`se_rob') (`se_clu') (`se_CR2') (`se_CR3') (`dof_CR2_IK') (`dof_CSS') (`se_clu_bs') (`bs_misreps')
(`p_pairs_bs') (`p_rad_res') (`p_rad_res_high') (`p_rad_res_low') (`p_rad_unres') (`p_webb_res') ;
} ;
/* now, take the whole package of results and save them */
postclose mcoutput ;
use "t2_post_G`numstates'_`mydate'.dta" , replace ;
qui save `savedata' , replace ;
di ;
end ;