/* ** Bootstrap OLS */ @ Data generation under Weak Ideal Conditions @ /* ** Regressors are stochastic. ** The errors are different across different data sets. ** Errors are non-normal: Chi-square(2)-2 */ new; @ open output file @ output file = bootols_cross.out reset ; @ Model: y(t) = beta(1) + beta(2)*x(t) + e @ seed = 1; beta2 = 0.5; beta1 = 0.5; tt = 100; @ # of observations @ kk = 2; @ # of betas @ nboot = 1000; @ Generating x and y @ x = rndns(tt,1,seed)^1; y = beta1 + beta2*x + (rndns(tt,1,seed)^2+rndns(tt,1,seed)^2-2); @ OLS using yy and xx @ yy = y; xx = ones(tt,1)~x; olsb = invpd(xx'xx)*(xx'yy); olse = yy - xx*olsb ; s2 = (olse'olse)/(tt-kk); v = s2*invpd(xx'xx); se = sqrt(diag(v)); @ testing H_o: beta2 = true beta 2 @ asympw = ( (olsb[2]-beta2)/se[2] )^2 ; asympp = cdfchic(asympw,1); asympw1 = ( (olsb[2]-1)/se[2] )^2 ; asympp1 = cdfchic(asympw1,1); "Asymptotic Wald test result for H_o: beta2 = true beta2 (" beta2 ")"; " Wald Stat, p-val:" asympw asympp ; ""; "Asymptotic Wald test result for H_o: beta2 = 1"; " Wald Stat, p-val:" asympw1 asympp1 ; ""; @ Boot strap tests @ bootw = zeros(nboot,1) ; z = y~x; i = 1 ; do while i <= nboot ; cboot = ceil( tt*rndus(tt,1,seed) ) ; @ choosing bootstrap data points @ bz = z[cboot,.] ; byy = bz[.,1]; bxx = ones(tt,1)~bz[.,2]; @ Bootstrap OLS using yy and xx @ bootb = invpd(bxx'bxx)*(bxx'byy); boote = byy - bxx*bootb ; bs2 = (boote'boote)/(tt-kk); bv = bs2*invpd(bxx'bxx); bse = sqrt(diag(bv)); bootw[i] = ( (bootb[2]-olsb[2])/bse[2] )^2 ; i = i + 1 ; endo ; @ BOOTSTRAP CRITICAL VALUES @ bootwt = sortc(bootw,1) ; tc = nboot ; bootc = bootwt[ceil(tc*0.99)]|bootwt[ceil(tc*0.95)]|bootwt[ceil(tc*0.9)]; "" ; "BOOTSTRAP WALD TEST FOR H_o: beta2 = true (" beta2 ")" ; ""; " STATISTICS C-VAL-1% C-VAL-5% C-VAL-10% "; asympw bootc' ; "" ; "BOOTSTRAP WALD TEST FOR H_o: beta2 = 1"; ""; " STATISTICS C-VAL-1% C-VAL-5% C-VAL-10% "; asympw1 bootc' ; output off;