Hi. I am studying the treatment effect of an intervention using a matching based approach, where treated states are matched to untreated states. I then conduct a difference-in-difference analysis by running individual event-study regressions. To understand the overall treatment effect, I aggregate the estimates from the individual event-study regressions and calculate the average effect of all treatment (or subgroups of treatment with similar characteristics). This is similar to a stacked regression, while leveraging custom weights to calculate more efficient averages. However, I am flummoxed when it comes to calculating the p-values of the stacked regression. I can calculate the p-values for the individual event-study regressions, but I'm not sure how to do that for the stacked regression. Any help will be much appreciated.
Below is a sample of my data and the related code. Part 1 first sets-up the code for the individual regressions. Part 2, runs the individual event studies, and Part 3 outputs the coefficients and SE for the stacked regression
Below is a sample of my data and the related code. Part 1 first sets-up the code for the individual regressions. Part 2, runs the individual event studies, and Part 3 outputs the coefficients and SE for the stacked regression
Code:
*DATA SAMPLE clear input str50 state byte stepone str13 Treated_State byte(weeknum adopt_week) float(tested confirmed_1 recovered_1 deceased_1) "Bihar" 1 "Bihar" 37 22 10.968039 .190893 .1850546 .0010001912 "Bihar" 0 "Bihar" 14 22 .08867207 .0045832135 .0023129422 .000027012813 "Bihar" 1 "Bihar" 24 22 1.5934727 .09181153 .06732514 .00046399885 "Bihar" 0 "Bihar" 9 22 .023821475 .00044607 .00013972557 3.5857715e-06 "Bihar" 1 "Bihar" 29 22 5.068347 .14344008 .13148248 .0007292264 "Bihar" 1 "Bihar" 36 22 10.247828 .18750395 .1810866 .000966963 "Bihar" 0 "Bihar" 20 22 .3337463 .024219856 .015814569 .00016518455 "Bihar" 1 "Bihar" 39 22 12.378263 .1976383 .19192722 .0010621055 "Bihar" 0 "Bihar" 12 22 .04013124 .0024207544 .0007249235 .000011235418 "Bihar" 0 "Bihar" 4 22 0 .000017450755 7.171544e-07 7.171544e-07 "Bihar" 1 "Bihar" 42 22 14.507592 .20766734 .2023336 .0011390802 "Bihar" 1 "Bihar" 28 22 4.260896 .13483803 .12253084 .0007003012 "Bihar" 1 "Bihar" 22 22 .58980757 .05235824 .033925343 .0002959457 "Bihar" 0 "Bihar" 11 22 .04245099 .001358888 .000448341 7.53012e-06 "Bihar" 0 "Bihar" 21 22 .4104603 .036436457 .02434966 .00022243737 "Bihar" 1 "Bihar" 26 22 2.7848125 .11582927 .1013988 .0005929671 "Bihar" 1 "Bihar" 23 22 1.0034382 .07272435 .0476965 .0003849923 "Bihar" 1 "Bihar" 45 22 16.280634 .21531174 .21075015 .001205656 "Bihar" 1 "Bihar" 47 22 17.28098 .2176378 .21473382 .001243187 "Bihar" 0 "Bihar" 3 22 0 3.34672e-06 0 0 "Bihar" 1 "Bihar" 48 22 5.016259 .06231139 .06166022 .0003585772 "Bihar" 0 "Bihar" 13 22 .06862139 .003441026 .0015243116 .00002067795 "Bihar" 0 "Bihar" 5 22 .0021611445 .000034781988 8.964429e-06 8.3668e-07 "Bihar" 1 "Bihar" 25 22 2.1707711 .10481963 .08708943 .0005343995 "Bihar" 1 "Bihar" 31 22 6.606687 .159154 .14880905 .0007728533 "Bihar" 0 "Bihar" 15 22 .11010375 .005678189 .0037403186 .0000334672 "Bihar" 0 "Bihar" 16 22 .1419289 .006759179 .005025698 .00004458309 "Bihar" 1 "Bihar" 43 22 15.157097 .21073844 .20558017 .0011626267 "Bihar" 0 "Bihar" 10 22 .030944014 .000708907 .0003206875 5.259132e-06 "Bihar" 1 "Bihar" 33 22 7.866549 .1729872 .1631078 .0008461226 "Bihar" 1 "Bihar" 44 22 15.731228 .21312033 .2083853 .001183663 "Bihar" 0 "Bihar" 7 22 .01026487 .0001143861 .000035618665 1.67336e-06 "Bihar" 0 "Bihar" 6 22 .006518694 .00005976286 .00002402467 8.3668e-07 "Bihar" 0 "Bihar" 19 22 .27508557 .015854968 .01087182 .00012155766 "Bihar" 1 "Bihar" 46 22 16.790081 .21676815 .2128226 .0012233458 "Bihar" 1 "Bihar" 35 22 9.480743 .18312895 .1762636 .0009274 "Bihar" 1 "Bihar" 40 22 13.10717 .20105493 .19557564 .0010884013 "Bihar" 1 "Bihar" 32 22 7.18386 .1659875 .1561607 .00080393 "Bihar" 1 "Bihar" 41 22 13.814168 .20439556 .19904032 .0011118283 "Bihar" 1 "Bihar" 38 22 11.61945 .19399765 .18851824 .0010309094 "Bihar" 1 "Bihar" 34 22 8.671193 .17866656 .16996786 .00088963 "Bihar" 0 "Bihar" 18 22 .2263394 .010706636 .007791762 .00008283133 "Bihar" 0 "Bihar" 8 22 .01659794 .0003028782 .00005581851 1.7928858e-06 "Bihar" 1 "Bihar" 27 22 3.595409 .12605326 .112047 .000643885 "Bihar" 0 "Bihar" 17 22 .1847392 .008343254 .006337254 .0000580895 "Bihar" 1 "Bihar" 30 22 5.962443 .15187284 .14039527 .0007506215 "Kerala" 0 "Bihar" 33 22 11.500824 1.0108571 .73942 .003441993 "Andaman and Nicobar Islands" 0 "Bihar" 16 22 3.484779 .013638 .009859662 0 "Andaman and Nicobar Islands" 0 "Bihar" 9 22 0 .008312343 .007916517 0 "Goa" 0 "Bihar" 42 22 24.99102 3.26321 3.152922 .04703154 "Kerala" 0 "Bihar" 23 22 2.9451056 .1053519 .067913376 .0003457041 "Assam" 0 "Bihar" 36 22 14.292813 .6104815 .59098816 .0027706614 "Goa" 0 "Bihar" 33 22 18.456299 2.6669946 2.418868 .035946194 "Haryana" 0 "Bihar" 20 22 1.635232 .0961351 .073335856 .001267538 "Sikkim" 0 "Bihar" 40 22 9.693072 .7866824 .6995482 .017555937 "Andaman and Nicobar Islands" 0 "Bihar" 27 22 10.32965 .8549838 .7644117 .01270241 "Himachal Pradesh" 0 "Bihar" 15 22 .7725636 .007716243 .004821918 .00009589041 "Uttar Pradesh" 0 "Bihar" 38 22 8.136458 .2360498 .2218127 .0033841254 "West Bengal" 0 "Bihar" 12 22 .16232093 .004200241 .001553936 .0002930675 "Kerala" 0 "Bihar" 21 22 2.028432 .05916177 .030607015 .0001903406 "Tamil Nadu" 0 "Bihar" 18 22 1.870065 .15681656 .09355383 .002163004 "Sikkim" 0 "Bihar" 15 22 .779389 .01026248 .000989673 0 "Tamil Nadu" 0 "Bihar" 16 22 1.2541747 .08605569 .04768007 .0010987704 "Tamil Nadu" 0 "Bihar" 38 22 15.418982 1.0213224 .9902132 .01537316 "Haryana" 0 "Bihar" 43 22 15.681849 .9124741 .8887321 .010078524 "Telangana" 0 "Bihar" 20 22 .7892355 .12872688 .09636908 .001157212 "Assam" 0 "Bihar" 48 22 5.384646 .18090364 .17842126 .000901475 "Telangana" 0 "Bihar" 44 22 18.982489 .7740374 .7559922 .0041744066 "Tamil Nadu" 0 "Bihar" 10 22 .3525985 .011223236 .0028275126 .0000766233 "Kerala" 0 "Bihar" 36 22 14.798937 1.4142284 1.1824659 .004966751 "Telangana" 0 "Bihar" 11 22 .008976741 .0043782145 .002712827 .00010478238 "DNHnDD" 0 "Bihar" 48 22 0 .10070013 .099568 .00005958588 "Goa" 0 "Bihar" 16 22 3.593646 .05871985 .014981447 .00008348794 "Haryana" 0 "Bihar" 15 22 .6720359 .028770726 .013211495 .000394611 "Kerala" 0 "Bihar" 22 22 2.4545944 .0800362 .04671317 .00025785458 "Tamil Nadu" 0 "Bihar" 14 22 .8242128 .04646787 .02478575 .0004084059 "Gujarat" 0 "Bihar" 23 22 1.57717 .10784288 .0830006 .0039638146 "Assam" 0 "Bihar" 14 22 .349497 .008937268 .003072264 .00001541339 "Uttar Pradesh" 0 "Bihar" 36 22 7.281742 .222857 .20943135 .003224936 "Andaman and Nicobar Islands" 0 "Bihar" 29 22 13.269522 .9310543 .8765743 .013098237 "Tripura" 0 "Bihar" 23 22 5.139132 .15989837 .1149585 .0010592614 "Kerala" 0 "Bihar" 40 22 19.08958 1.8361642 1.6577562 .007048297 "Mizoram" 0 "Bihar" 44 22 15.313794 .355477 .3480465 .000671141 "Mizoram" 0 "Bihar" 46 22 16.351917 .3633389 .3568792 .0007550336 "Tamil Nadu" 0 "Bihar" 48 22 6.03661 .3163394 .3099539 .004662697 "Goa" 0 "Bihar" 22 22 8.970909 .4600928 .32867345 .0038682746 "Telangana" 0 "Bihar" 16 22 .17189798 .02581485 .011238582 .0005918477 "Kerala" 0 "Bihar" 6 22 .04594774 .0010960854 .0005893239 8.540926e-06 "DNHnDD" 0 "Bihar" 46 22 0 .3519142 .3475942 .00020855057 "Tripura" 0 "Bihar" 5 22 0 .000021471515 0 0 "Telangana" 0 "Bihar" 36 22 12.601858 .6781473 .6244607 .003721118 "DNHnDD" 0 "Bihar" 14 22 .9501266 .002591986 .0001936541 0 "Tamil Nadu" 0 "Bihar" 45 22 19.744255 1.093329 1.0681666 .016162608 "Haryana" 0 "Bihar" 18 22 1.1319395 .06329919 .04768017 .0009660993 "Kerala" 0 "Bihar" 15 22 .45039225 .007500966 .003583935 .00005978648 "Rajasthan" 0 "Bihar" 8 22 .12059858 .003066296 .0010130388 .00006508298 "West Bengal" 0 "Bihar" 39 22 6.106421 .5024678 .4686932 .008746178 "Assam" 0 "Bihar" 28 22 8.113241 .4270555 .3418553 .001447609 "Sikkim" 0 "Bihar" 11 22 .15182875 0 0 0 "Sikkim" 0 "Bihar" 38 22 6.616501 .7212565 .6543245 .0151463 end //////////////////////////////////////////////// //// //// //// PART 1. Define regression program //// //// //// //////////////////////////////////////////////// capture program drop runEventStudies program define runEventStudies args data yList name use "${outdir}\\`data'".dta", clear * group indicator. So it's 1 both before and after the event bysort state: egen treated = max(stepone) egen eventBlock = group(Treated_State adopt_week) qui gen post = weeknum > adopt_week //should turn on for the controls based on the state qui gen treated_post = treated * post qui gen treated_trend = weeknum * treated qui sum eventBlock local N = r(max) disp "TOTAL: `N'" * Run regressions - include test rates foreach y of local yList { disp "`y'" forvalues i = 1/`N' { disp "`i'" * Balanced T, with FEs to control for week areg `y' post treated_post tested i.weeknum if eventBlock == `i' /// ,absorb(state) //mine is not a balanced panel - restrict analysis to make it balanced local b_`y'_`i'_b = _b[treated_post] local se_`y'_`i'_b = _se[treated_post] } } *** Step 2: Construct a dataset saving all coefficients and SEs *keep Treated_State adopt_week eventBlock cem_varlist qui duplicates drop foreach suff in b { foreach y of local yList { qui gen b_`y'_`suff' = "" qui gen se_`y'_`suff' = "" forvalues i = 1/`N' { qui replace b_`y'_`suff' = "`b_`y'_`i'_`suff''" if eventBlock == `i' qui replace se_`y'_`suff' = "`se_`y'_`i'_`suff''" if eventBlock == `i' } qui destring b_`y'_`suff', replace qui destring se_`y'_`suff', replace } } drop eventBlock * Save the data foreach x in Treated_State { encode `x', gen(temp) drop `x' rename temp `x' } * save order state weeknum cem_varlist sort state weeknum save "${coeffdir}\coefficients_`name'.dta", replace end //////////////////////////////////////////////////////////////////////////////// //////////// //////////// //////////// PART 2. Run the event studies //////////// //////////// //////////// //////////////////////////////////////////////////////////////////////////////// * Acquired runEventStudies "1matched_cohort" /// Data `"confirmed_1 recovered_1 deceased_1"' /// yList "one" /// name //////////////////////////////////////////////////////////////////////////////// //////////// //////////// //////////// PART 3. Calculate averages //////////// //////////// //////////// //////////////////////////////////////////////////////////////////////////////// * Uses Inverse variance average: these weights give the smallest SE of the sum of the vars local oneVars "confirmed_1 recovered_1 deceased_1" local sets `" "" "_trend" "' foreach set of local sets { * open file, write header file open EScoeff using "${paperdir}\Tables\EScoeff`set'.csv", write replace file write EScoeff "Variable,All states,Early adopters,Late adopters" _n foreach sample in one two three four { use "${coeffdir}\coefficients_`sample'.dta", replace * Average effect of all states foreach var of local `sample'Vars { * ALL qui egen wavg_`var' = wtmean(b_`var'_b`set') /// if treated == 1, weight(1/(se_`var'_b`set'^2)) qui egen wvar_`var' = mean(1/(se_`var'_b`set'^2)) /// SE command if treated == 1 qui replace wvar_`var' = sqrt(1/wvar_`var') ///follows from 206 local t = wavg_`var'/wvar_`var' di 2*ttail(e(df_r),abs(`t´)) df = st_numscalar("e(df_r)") t = wavg_`var'/wvar_`var' 2*ttail(df, abs(t)) * record values sum wavg_`var' local avgAllStates : display %4.2f r(mean) drop wavg_`var' sum wvar_`var' local sdAllStates : display %4.2f r(mean) drop wvar_`var' file write EScoeff "`var',`avgAllStates',`avgEarlyStates',`avgLateStates'" _n file write EScoeff `",="(`sdAllStates')",="(`sdEarlyStates')",="(`sdLateStates')""' _n } } file close EScoeff }
Comment