v. 0.3

Two-Stage Difference-in-Differences

did2s - Estimates a TWFE model using the two-stage difference-in-differences approach from Gardner (2021)

Syntax

did2s depvar [if] [in] [weight], first_stage(varlist) second_stage(varlist) treatment(varname) cluster(varname)

Model
first_stage(varlist) Fixed effects and covariates that will be used to estimate counterfactual Y_it(0). This should be everything besides treatment variables.

second_stage(varlist) List of treatment variables. This could be, for example a 0/1 treatment dummy, a set of event-study leads/lags, or a continuous treatment variable.

treatment(varname) This must be a 0/1 dummy for when treatment is occuring; D_it = 1 if unit i is treated during period t. See Anticipation for details on how to deal with anticipation (shift D_it the number of periods of anticipation).

cluster(varname) What variable to cluster on (use unit id if you don't want to cluster).

unit(varname) Unit variable. If you use this option, *do not include unit fixed effects* in the first_stage regression. This is a trick that speeds up numerical computation that will speed things up a bunch if you have a lot of unit fixed effects. Note that the numerical equivalency only works if clutser is at the unit level (or higher!! e.g. units = people, cluster at state level)

Description

did2s implements Two-Staged Difference-in-Differences by Gardner (2021). A TWFE model for outcomes is given by unit/group fixed effects, time fixed effects, treatment variable (or variables in the case of event study), and potentially covariates. To avoid the problems with OLS estimation of difference-in-differences/event-studies in the presence of staggered treatment adoption, this method proceeds in two stages:

1. This program estimates the unit/group fixed effects, time fixed effects, and potentially covariates using only untreated/not-yet-treated observations. This is used to predict counterfactual outcomes in all periods and residualize the observed outcome.

2. Then regress the residualized outcome on the treatment variable(s) to estimate the treatment effects.

More details can be found in Gardner (2021) or more informally in this blog post.

Anticipation

This procedure works so long as μ_i and μ_t are consistently estimated. The key is to use only untreated/not-yet-treated observations to estimate the fixed effects. For example, if you used observations with D_it=1, you would attribute treatment effects τ as “fixed characteristics” and would combine μ_i with the treatment effects.

The fixed effects could be biased/inconsistent if there are anticipation effects, i.e. units respond before treatment starts. The fix is fairly simple, simply “shift” treatment date earlier by as many years as you suspect anticipation to occur (e.g. 2 years before treatment starts) and estimate on the subsample where the shifted treatment equals zero. If you suspect there is anticipation, pass this modified variable to treat_var.

Examples:

Setup

. use https://github.com/kylebutts/did2s_stata/raw/main/data/df_hom.dta, clear

Static Model

. did2s dep_var, first_stage(i.state i.year) second_stage(i.treat) treatment(treat) cluster(state)

Event Study Model

. gen rel_year_shift = rel_year + 20

. replace rel_year_shift = 100 if rel_year_shift == .

. did2s dep_var, first_stage(i.state i.year) second_stage(ib100.rel_year_shift) treatment(treat) cluster(state)

With Covariates

. use https://github.com/scunning1975/mixtape/raw/master/castle.dta, clear

. global demo blackm_15_24 whitem_15_24 blackm_25_44 whitem_25_44

. did2s l_homicide [aweight=popwt], first_stage(i.sid i.year) second_stage(i.post) treatment(post) cluster(sid)

. did2s l_homicide [aweight=popwt], first_stage(i.sid i.year $demo) second_stage(i.post) treatment(post) cluster(sid)

Stored results

did2s stores the following in e():

Scalars

e(N) number of observations

Macros

e(cmd) did2s

e(cmdline) command as typed

e(depvar) name of dependent variable

e(clustvar) name of cluster variable

e(vce) vcetype specified in vce()

e(vcetype) title used to label Std. Err.

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of the estimators

Functions

e(sample) marks estimation sample

Program Author

Kyle Butts

University of Colorado, Boulder

buttskyle96@gmail.com

References

Gardner (2021), Two-stage Difference-in-differences