------------------------------------------------------------------------------- log: c:\bill\spring2011\wild_bs_example_1.log log type: text opened on: 28 Jan 2011, 19:48:16 . * set stata parameters; . set mem 5m ; Current memory allocation current memory usage settable value description (1M = 1024k) -------------------------------------------------------------------- set maxvar 5000 max. variables allowed 1.909M set memory 5M max. data space 5.000M set matsize 400 max. RHS vars in models 1.254M ----------- 8.163M . set more off ; . * fix seed for replication purposes and; . * set the number of bootstrap replications; . set seed 365476247 ; . global bootreps = 999; . tempfile main bootsave ; . use carton_sales_taxes; . drop if year<2004; (1044 observations deleted) . /* the data contains monthly market share of > cigarette sales by carton (compared to pack) > for 35 states over the 2001-2006 period so there > are 35*12*6 = observations. I regress the market > share on real taxes (state+federal in dollars/pack) > and add state, year and month dummies. Because > taxes are at the state level, you clustrer at the > state level. The parameter we will generate bootstrap > p-values for is on real_tax and the null hypothesis we > will impose is ho: beta(real_tax)=0 > */ > > > * means of key covariates; . sum carton_market_share real_tax; Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- carton_mar~e | 1044 .4399535 .1723505 .1241852 .7455736 real_tax | 1044 1.246764 .6341391 0 3.051637 . * construct the dummies used in analysis; . xi i.state i.month i.year; i.state _Istate_1-29 (_Istate_1 for state==AL omitted) i.month _Imonth_1-12 (naturally coded; _Imonth_1 omitted) i.year _Iyear_2004-2006 (naturally coded; _Iyear_2004 omitted) . di ; . * run ols without clustered std errors, just for comparison; . reg carton_market_share _I* real_tax; Source | SS df MS Number of obs = 1044 -------------+------------------------------ F( 42, 1001) = 1222.46 Model | 30.3895294 42 .723560223 Prob > F = 0.0000 Residual | .592482903 1001 .000591891 R-squared = 0.9809 -------------+------------------------------ Adj R-squared = 0.9801 Total | 30.9820123 1043 .02970471 Root MSE = .02433 ------------------------------------------------------------------------------ carton_mar~e | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Istate_2 | -.1450251 .0063325 -22.90 0.000 -.1574516 -.1325987 _Istate_3 | -.2283005 .0059946 -38.08 0.000 -.2400639 -.216537 _Istate_4 | -.2051017 .0069859 -29.36 0.000 -.2188104 -.1913931 _Istate_5 | .0515015 .0057344 8.98 0.000 .0402487 .0627542 _Istate_6 | .0254028 .0057345 4.43 0.000 .0141498 .0366558 _Istate_7 | -.1925453 .0061181 -31.47 0.000 -.2045511 -.1805396 _Istate_8 | -.030434 .0057703 -5.27 0.000 -.0417573 -.0191107 _Istate_9 | -.2106366 .0057345 -36.73 0.000 -.2218896 -.1993836 _Istate_10 | -.3753734 .0069859 -53.73 0.000 -.389082 -.3616647 _Istate_11 | -.1533013 .0076156 -20.13 0.000 -.1682457 -.1383569 _Istate_12 | -.0858996 .0059103 -14.53 0.000 -.0974976 -.0743016 _Istate_13 | -.0785124 .0057776 -13.59 0.000 -.0898501 -.0671748 _Istate_14 | .1166236 .0057735 20.20 0.000 .1052941 .127953 _Istate_15 | .1870962 .0057977 32.27 0.000 .1757191 .1984733 _Istate_16 | .018584 .0058111 3.20 0.001 .0071807 .0299873 _Istate_17 | -.368502 .0069659 -52.90 0.000 -.3821714 -.3548325 _Istate_18 | .0247755 .0060095 4.12 0.000 .0129828 .0365682 _Istate_19 | -.1170564 .0058589 -19.98 0.000 -.1285536 -.1055592 _Istate_20 | -.2651542 .0063268 -41.91 0.000 -.2775695 -.2527388 _Istate_21 | -.0443864 .0065921 -6.73 0.000 -.0573222 -.0314505 _Istate_22 | -.2519335 .008726 -28.87 0.000 -.269057 -.2348101 _Istate_23 | .1785096 .0058308 30.61 0.000 .1670676 .1899516 _Istate_24 | .1544118 .0057657 26.78 0.000 .1430975 .1657261 _Istate_25 | -.0894185 .005736 -15.59 0.000 -.1006744 -.0781627 _Istate_26 | -.2510447 .0058454 -42.95 0.000 -.2625153 -.239574 _Istate_27 | .1028153 .0057766 17.80 0.000 .0914796 .114151 _Istate_28 | -.3649852 .0072779 -50.15 0.000 -.3792668 -.3507036 _Istate_29 | .016942 .005902 2.87 0.004 .0053602 .0285237 _Imonth_2 | .0047901 .0036935 1.30 0.195 -.0024578 .0120379 _Imonth_3 | .003449 .0036927 0.93 0.351 -.0037973 .0106954 _Imonth_4 | -.000845 .003692 -0.23 0.819 -.0080898 .0063999 _Imonth_5 | -.000491 .0036895 -0.13 0.894 -.0077311 .0067491 _Imonth_6 | -.0018084 .0036926 -0.49 0.624 -.0090544 .0054377 _Imonth_7 | -.0016992 .0036908 -0.46 0.645 -.0089418 .0055434 _Imonth_8 | .0060778 .0036941 1.65 0.100 -.0011713 .0133268 _Imonth_9 | .0023534 .0036951 0.64 0.524 -.0048976 .0096044 _Imonth_10 | -.0018453 .0036981 -0.50 0.618 -.0091021 .0054116 _Imonth_11 | -.0053518 .0036984 -1.45 0.148 -.0126094 .0019058 _Imonth_12 | .0040418 .0036942 1.09 0.274 -.0032075 .0112911 _Iyear_2005 | -.0046846 .0018602 -2.52 0.012 -.0083349 -.0010343 _Iyear_2006 | -.013917 .0018705 -7.44 0.000 -.0175875 -.0102464 real_tax | -.0201751 .003371 -5.98 0.000 -.0267903 -.01356 _cons | .5595832 .0054096 103.44 0.000 .5489677 .5701988 ------------------------------------------------------------------------------ . * now run ols and cluster at the state level; . reg carton_market_share _I* real_tax, cluster(state); Linear regression Number of obs = 1044 F( 13, 28) = . Prob > F = . R-squared = 0.9809 Root MSE = .02433 (Std. Err. adjusted for 29 clusters in state) ------------------------------------------------------------------------------ | Robust carton_mar~e | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Istate_2 | -.1450251 .0066001 -21.97 0.000 -.1585449 -.1315054 _Istate_3 | -.2283005 .0042925 -53.19 0.000 -.2370932 -.2195078 _Istate_4 | -.2051017 .0098023 -20.92 0.000 -.2251808 -.1850226 _Istate_5 | .0515015 .0000121 4252.12 0.000 .0514767 .0515263 _Istate_6 | .0254028 .0000982 258.68 0.000 .0252017 .025604 _Istate_7 | -.1925453 .0052395 -36.75 0.000 -.2032779 -.1818128 _Istate_8 | -.030434 .0015806 -19.25 0.000 -.0336717 -.0271963 _Istate_9 | -.2106366 .0000982 -2144.90 0.000 -.2108377 -.2104354 _Istate_10 | -.3753734 .0098023 -38.29 0.000 -.3954525 -.3552943 _Istate_11 | -.1533013 .012312 -12.45 0.000 -.1785213 -.1280813 _Istate_12 | -.0858996 .0035166 -24.43 0.000 -.0931031 -.0786961 _Istate_13 | -.0785124 .0017339 -45.28 0.000 -.0820642 -.0749606 _Istate_14 | .1166236 .0016478 70.77 0.000 .1132481 .1199991 _Istate_15 | .1870962 .0021004 89.07 0.000 .1827936 .1913987 _Istate_16 | .018584 .0023124 8.04 0.000 .0138474 .0233207 _Istate_17 | -.368502 .0097162 -37.93 0.000 -.3884047 -.3485992 _Istate_18 | .0247755 .0044164 5.61 0.000 .015729 .033822 _Istate_19 | -.1170564 .0029524 -39.65 0.000 -.1231042 -.1110087 _Istate_20 | -.2651542 .0065673 -40.38 0.000 -.2786066 -.2517017 _Istate_21 | -.0443864 .0079882 -5.56 0.000 -.0607494 -.0280234 _Istate_22 | -.2519335 .0161588 -15.59 0.000 -.2850334 -.2188337 _Istate_23 | .1785096 .0025949 68.79 0.000 .1731943 .1838249 _Istate_24 | .1544118 .0014757 104.64 0.000 .1513891 .1574346 _Istate_25 | -.0894185 .0003323 -269.13 0.000 -.0900991 -.0887379 _Istate_26 | -.2510447 .0027859 -90.11 0.000 -.2567512 -.2453381 _Istate_27 | .1028153 .0017138 59.99 0.000 .0993048 .1063258 _Istate_28 | -.3649852 .0110101 -33.15 0.000 -.3875383 -.3424321 _Istate_29 | .016942 .0034315 4.94 0.000 .0099128 .0239712 _Imonth_2 | .0047901 .001317 3.64 0.001 .0020923 .0074878 _Imonth_3 | .003449 .0014448 2.39 0.024 .0004894 .0064087 _Imonth_4 | -.000845 .0020356 -0.42 0.681 -.0050148 .0033248 _Imonth_5 | -.000491 .0018064 -0.27 0.788 -.0041912 .0032092 _Imonth_6 | -.0018084 .0020849 -0.87 0.393 -.0060791 .0024624 _Imonth_7 | -.0016992 .0021232 -0.80 0.430 -.0060484 .00265 _Imonth_8 | .0060778 .0031652 1.92 0.065 -.0004058 .0125614 _Imonth_9 | .0023534 .0040593 0.58 0.567 -.0059616 .0106684 _Imonth_10 | -.0018453 .0030995 -0.60 0.556 -.0081944 .0045038 _Imonth_11 | -.0053518 .0035491 -1.51 0.143 -.0126217 .0019182 _Imonth_12 | .0040418 .0048803 0.83 0.415 -.005955 .0140387 _Iyear_2005 | -.0046846 .0040704 -1.15 0.260 -.0130224 .0036533 _Iyear_2006 | -.013917 .0070822 -1.97 0.059 -.0284241 .0005901 real_tax | -.0201751 .0082818 -2.44 0.021 -.0371397 -.0032106 _cons | .5595832 .0074706 74.90 0.000 .5442803 .5748862 ------------------------------------------------------------------------------ . * save t-test as a global variable; . global maint = _b[real_tax] / _se[real_tax] ; . * now run OLS and impose null that real_tax=0; . reg carton_market_share _I*; Source | SS df MS Number of obs = 1044 -------------+------------------------------ F( 41, 1002) = 1209.37 Model | 30.3683288 41 .740690947 Prob > F = 0.0000 Residual | .613683459 1002 .000612459 R-squared = 0.9802 -------------+------------------------------ Adj R-squared = 0.9794 Total | 30.9820123 1043 .02970471 Root MSE = .02475 ------------------------------------------------------------------------------ carton_mar~e | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Istate_2 | -.1611035 .0058331 -27.62 0.000 -.1725501 -.149657 _Istate_3 | -.2387572 .0058331 -40.93 0.000 -.2502038 -.2273107 _Istate_4 | -.2289809 .0058331 -39.26 0.000 -.2404274 -.2175343 _Istate_5 | .051531 .0058331 8.83 0.000 .0400844 .0629775 _Istate_6 | .0256421 .0058331 4.40 0.000 .0141955 .0370886 _Istate_7 | -.2053091 .0058331 -35.20 0.000 -.2167556 -.1938625 _Istate_8 | -.0342844 .0058331 -5.88 0.000 -.045731 -.0228379 _Istate_9 | -.2103973 .0058331 -36.07 0.000 -.2218439 -.1989508 _Istate_10 | -.3992525 .0058331 -68.45 0.000 -.4106991 -.387806 _Istate_11 | -.1832943 .0058331 -31.42 0.000 -.1947408 -.1718477 _Istate_12 | -.0944664 .0058331 -16.19 0.000 -.105913 -.0830198 _Istate_13 | -.0742884 .0058331 -12.74 0.000 -.085735 -.0628418 _Istate_14 | .1206379 .0058331 20.68 0.000 .1091913 .1320844 _Istate_15 | .192213 .0058331 32.95 0.000 .1807664 .2036596 _Istate_16 | .0129509 .0058331 2.22 0.027 .0015044 .0243975 _Istate_17 | -.3921714 .0058331 -67.23 0.000 -.403618 -.3807248 _Istate_18 | .0140169 .0058331 2.40 0.016 .0025703 .0254634 _Istate_19 | -.1242487 .0058331 -21.30 0.000 -.1356953 -.1128022 _Istate_20 | -.2811526 .0058331 -48.20 0.000 -.2925991 -.269706 _Istate_21 | -.0638461 .0058331 -10.95 0.000 -.0752927 -.0523996 _Istate_22 | -.2912977 .0058331 -49.94 0.000 -.3027443 -.2798511 _Istate_23 | .1848309 .0058331 31.69 0.000 .1733843 .1962774 _Istate_24 | .1580067 .0058331 27.09 0.000 .1465601 .1694532 _Istate_25 | -.0902279 .0058331 -15.47 0.000 -.1016745 -.0787814 _Istate_26 | -.2578312 .0058331 -44.20 0.000 -.2692778 -.2463847 _Istate_27 | .1069902 .0058331 18.34 0.000 .0955436 .1184367 _Istate_28 | -.3918066 .0058331 -67.17 0.000 -.4032532 -.38036 _Istate_29 | .0085825 .0058331 1.47 0.142 -.0028641 .0200291 _Imonth_2 | .0036697 .0037523 0.98 0.328 -.0036935 .0110329 _Imonth_3 | .0024207 .0037523 0.65 0.519 -.0049425 .0097839 _Imonth_4 | -.0017688 .0037523 -0.47 0.637 -.009132 .0055944 _Imonth_5 | -.0009498 .0037523 -0.25 0.800 -.008313 .0064134 _Imonth_6 | -.0028168 .0037523 -0.75 0.453 -.01018 .0045464 _Imonth_7 | -.0009565 .0037523 -0.25 0.799 -.0083197 .0064067 _Imonth_8 | .0048862 .0037523 1.30 0.193 -.002477 .0122494 _Imonth_9 | .0010542 .0037523 0.28 0.779 -.006309 .0084174 _Imonth_10 | -.0034176 .0037523 -0.91 0.363 -.0107808 .0039456 _Imonth_11 | -.0069555 .0037523 -1.85 0.064 -.0143187 .0004077 _Imonth_12 | .0028362 .0037523 0.76 0.450 -.004527 .0101994 _Iyear_2005 | -.0061329 .0018761 -3.27 0.001 -.0098145 -.0024513 _Iyear_2006 | -.0157819 .0018761 -8.41 0.000 -.0194635 -.0121003 _cons | .5456082 .0049638 109.92 0.000 .5358676 .5553488 ------------------------------------------------------------------------------ . * output residuals; . predict epshat , resid; . predict yhat , xb ; . * sort by state and temp save data; . sort state; . qui save `main' , replace ; . * get the number of states; . qui by state: keep if _n == 1 ; . qui summ ; . global numstates = r(N) ; . * output the t-statistics for real_tax to a file; . postfile bskeep t_wild using bs_results, replace; . * iterate over the bootstrap replications; . forvalues b = 1/$bootreps { ; 2. /* wild bootstrap */ > use `main', replace ; 3. * with 50% probability constuct dummy; . * that adds or substracts Radamaker error; . qui by state: gen temp = uniform() ; 4. qui by state: gen pos = (temp[1] < .5) ; 5. gen wildresid = epshat * (2*pos - 1) ; 6. * now construct y; . gen wildy = yhat + wildresid ; 7. * now regress y on all x variables; . qui reg wildy _I* real_tax, cluster(state); 8. * generate the t-stat; . local bst_wild = _b[real_tax] / _se[real_tax] ; 9. * add to the bottom of the post file; . post bskeep (`bst_wild') ; 10. } ; . /* end of bootstrap reps */ > > * save the post file; . postclose bskeep ; . * clear the current data set; . clear; . * load up the wild t-stats; . use bs_results; . * figure out where the main-t is in the; . * synthetic distribution; . gen positive=$maint>0; . gen pos=t_wild>$maint; . gen neg=t_wild<$maint; . gen reject=positive*pos + (1-positive)*neg; . sum reject; Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- reject | 999 .032032 .1761733 0 1 . local sumreject=r(sum); . local p_value_wild=2*`sumreject'/$bootreps; . local p_value_main=2*(ttail(($numstates-1),abs($maint))); . di "Number BS reps = $bootreps"; Number BS reps = 999 . di "P-value from clustered standard errors = `p_value_main'"; P-value from clustered standard errors = .0214648522876161 . di "P-value from wild boostrap = `p_value_wild'"; P-value from wild boostrap = .0640640640640641 . log close ; log: c:\bill\spring2011\wild_bs_example_1.log log type: text closed on: 28 Jan 2011, 19:50:04 -------------------------------------------------------------------------------