*! version 0.2 29jul2021

Title

eventstudyweights --
estimate the implied weights on the cohort-specific average treatment effects
on the treated (CATTs) underlying two-way fixed effects regressions
with relative time indicators (event study specifications).
For the latest version, please check https://github.com/lsun20/EventStudyWeights

Syntax

eventstudyweights
[if] [in]
[weight] , cohort(eventstudyweights##main:variable)
rel_time(eventstudyweights##main:variable)
absorb(reghdfe##absvar:absvars)
[options covariates(eventstudyweights##main:varlist) saveweights(eventstudyweights##main:filename)]

where rel_time_list is the list of relative time indicators as specified in your two-way fixed effects regression. See illustration for an example of generating these relative time indicators.
The relative time indicators should take the value of zero for never treated units.

Users should shape their dataset to a long format where each observation is at the unit-time level.
The syntax is similar to reghdfe in specifying fixed effects (with absorb) and regressors other than the relative time indicators need to be specified separately in covariates(varlist).
Furthermore, the syntax also requires the user to specify the cohort categories as well as the relative time categories (see explanations below).
See illustration for an example of specifying the syntax.

options

Main
cohort(varname) categorical varaible that contains the initial treatment timing of each unit. This categorical variable should be set to be missing for never treated units.

rel_time(varname) categorical varaible that contains the time relative to initial treatment for each unit at each calendar time.

eventstudyweights requires hdfe (Sergio 2015) to be installed to partial out controls from the relative time indicators.
eventstudyweights will prompt the user for installation of
hdfe if necessary.

Controls
absorb(varlist) specifies unit and time fixed effects.

covariates(varlist) specify covariates that lend validity to the parallel trends assumption, i.e. covariates you would have included in the canonical two-way fixed effects regressions.

Save Output
saveweights(filename) if specified, save weights to filename.xlsx along with cohort and relative time, using Stata's built-in putexcel

aweights and fweights are allowed;
see weight.

Description

eventstudyweights estimate weights underlying two-way fixed effects regressions with relative time indicators,
It is optimized for speed in large panel datasets thanks to hdfe.

To estimate the dynamic effects of an absorbing treatment, researchers often use two-way fixed effects regressions that include leads and lags of the treatment (event study specification).
Units are categorized into different cohorts based on their initial treatment timing.
Sun and Abraham (2020) show the coefficients in this event study specification can be written as a linear combination of cohort-specific effects from both its own relative period and other relative periods.
eventstudyweights is a Stata module that estimates these weights for any given event study specification.
They also propose the interaction weighted (IW) estimator as an alternative estimator for the estimation of dynamic effects.
eventstudyinteract is a Stata model that implements the IW estimator and is maintained at
https://github.com/lsun20/eventstudyinteract.

For each relative time indicator specified in rel_time_list, eventstudyweights estimates the weights
underlying the linear combination of treatment effects in its associated coefficients using
an auxiliary regression. It provides built-in options to control for fixed effects and covariates
(see Controls). eventstudyweights saves these weights in e(weights). If specified in in saveweights, exports these weights to a spreadsheet that can be analyzed separately.
This spreadsheet also contains the cohort and relative time each weight corresponds to, with headers as specified in cohort() and rel_time().

Examples

Load the 1968 extract of the National Longitudinal Survey of Young Women and Mature Women.

. webuse nlswork, clear

Code the cohort categorical variable based on when the individual first joined the union.

. gen union_year = year if union == 1

. bysort idcode: egen first_union = min(union_year)

. drop union_year

Code the relative time categorical variable.

. gen ry = year - first_union

Suppose we will later use a specification with lead<=-2 and lag=0,1,>=2 to estimate the dynamic effect of union status on income. We first generate these relative time indicators.

. gen g_2 = ry <= -2

. gen g0 = ry == 0

. gen g1 = ry == 1

. gen g2 = ry >= 2

For the coefficient associate with each of the above relative time indicators in a two-way fixed effects regression, we can estimate the weights and export to a spreadsheet "weights.xlsx".

. eventstudyweights g_2 g0 g1 g2, absorb(i.idcode i.year) cohort(first_union) rel_time(ry) saveweights("weights")

Alternatively, we can view the weights in Stata.

. eventstudyweights g_2 g0 g1 g2, absorb(i.idcode i.year) cohort(first_union) rel_time(ry)

. mat list e(weights)

To plot the weights underlying the coefficient associate with, e.g., relative time indicator lead=2, you may try

. import excel "weights.xlsx", clear firstrow

. keep g_2 first_union ry

. reshape wide g_2, i(ry) j(first_union)

. graph twoway line g_2* ry, xtitle("relative time") ytitle("weight in TWFE g_2 coefficient") graphregion(fcolor(white)) scheme(sj)

You may also check the weights have properties discussed in the paper:

. egen w_sum = rowtotal(g_2*)

Acknowledgements

Thank you to the users of the program who devoted time to reporting
the bugs that they encountered.

References

Correia, S. 2015.
HDFE: Stata module to partial out variables with respect to a set of fixed effects
{browse "https://ideas.repec.org/c/boc/bocode/s457985.html":https://ideas.repec.org/c/boc/bocode/s457985.html

Sun, L. and Abraham, S. 2020.
Estimating Dynamic Treatment Effects in Event Studies with
Heterogeneous Treatment Effects

Citation of eventstudyweights

eventstudyweights is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Sun, L., 2020.
eventstudyweights: weights underlying two-way fixed effects event studies regressions.
https://github.com/lsun20/EventStudyWeights.

Author

Liyang Sun

lsun20@mit.edu