clear all set more off * This program illustrates the use of the Pairs Bootstrap * to improve the size of a heteroskedasticity robust t-test * The null is not imposed * Define main parameters local n = 50 local rep = 1000 local b = 99 * Initialize series local smpl=max(`n',`rep',`b') set obs `smpl' qui g t=0 if _n<=`rep' qui g pb=0 if _n<=`rep' qui g byte tr=0 if _n<=`rep' qui g byte trb=0 if _n<=`rep' qui g x=0 if _n<=`n' qui g e=0 if _n<=`n' qui g y=0 if _n<=`n' qui g yb=0 if _n<=`n' * Start outer loop over different values of the parameters foreach m of numlist 0 0.25 { set seed 31052011 * Start main loop forvalues i = 1/`rep' { * Generate data qui replace x = rchi2(2) if _n<=`n' qui replace e = rnormal(0,1) if _n<=`n' qui replace y=1+`m'*x+x*e if _n<=`n' * Run regression and compute t statistic qui reg y x if _n<=`n', vce(hc3) qui replace t=_b[x]/_se[x] if _n==`i' local at=(_b[x]/_se[x]) local m0=_b[x] local count=0 qui save z1.dta, replace * Start bootstrap loop forvalues j = 1/`b' { qui keep x y qui bsample if _n<=`n' qui rename y yb qui rename x xb qui merge 1:1 _n using z1.dta, nogenerate noreport qui reg yb xb if _n<=`n', vce(hc3) qui local count=`count'+ (((_b[xb]-`m0')/_se[xb])>=(`at')) drop yb xb * End bootstrap loop } * Compute bootstrap results qui replace pb=2*min(`count',(`b'-`count'))/`b' if _n==`i' * End main loop } * Compute and display results qui replace tr=abs(t)>1.96 if _n<=`rep' qui replace trb=pb<=0.05 if _n<=`rep' di di as result "Results for m = " `m' su tr trb if _n<=`rep' * End outer loop }