When unconfoundedness fails, we need a different assumption. Parallel trends, which leads to the difference-in-differences estimator, restricts a different counterfactual object. It is not weaker in general: neither assumption implies the other.
Related reading: For a side-by-side comparison of DiD, synthetic DiD, synthetic control, and TASC on a single panel — the Proposition 99 California smoking data, where the four estimators do not agree — see the Same data, different estimators chapter in Topics on Econometrics and Causal Inference.
13.1\(T=2\) Panel Data
Suppose we have two periods, \(t = (1,2)\). Some units are treated just prior to period 2. For each individual \(i\), there are four potential outcomes:
Parallel trends and no anticipation are the two assumptions we name, but they are not the whole set the derivation uses. It also maintains consistency and a well-defined treatment, so that \(Y = DY(1) + (1-D)Y(0)\) and the treatment has no hidden versions with different effects. It maintains no interference for the stated estimand: one unit’s outcome does not move with another unit’s treatment. Section 13.13 returns to this and shows what the estimand becomes when it fails. It maintains overlap, so both groups are observed in both periods and, once covariates enter, comparable units exist in each. And it maintains stable composition, so the same population is sampled in both periods. Differential attrition or entry breaks the comparison even when trends are parallel.
13.5 Advantages and Disadvantages of DiD
Advantages:
No need to assume unconfoundedness. PT and NA take its place, alongside the maintained conditions listed above. Or say we don’t need treatment itself to be independent of potential outcomes, but we do need it to be independent to the change in potential outcome at least for untreated state. This allows selection on untreated outcome levels. If the selection bias does not change over time, then DiD can handle it. It is not a relaxation of unconfoundedness, though: groups can have equal untreated post-period levels and unequal untreated changes, and then unconfoundedness holds while parallel trends fails.
Disadvantages:
PT and NA might be violated.
PT is not scale free, in the sense that even if outcome can have PT, but then non-linear transformation of outcome won’t have PT (for example log of Y).
13.6 Traditional DiD
In practice, DiD in many period setting is usually done with
here \(W_{it} =(1[t=2] \cdot D_i)\), which is the interaction of post-treatment indicator and treatment group indicator.
This is usually called Two Way Fixed Effect (TWFE). There are multiple ways to implement the same model in practice.
TWFE can be done by “Pooled OLS”. That is, using OLS on time dummies and firm (individual) dummies. Wooldridge (2021) shows it’s equivalent to use treatment dummies, instead of individual dummies. He also shows that this model can be equivalently implemented with fixed effect model and random effect model.
13.7 TWFE with Staggered Treatment Timing
The problem comes in when there is different timing of treatment. People used to still use
where \(W_{it}\) now is a dummy when an individual \(i\) gets treated at time \(t\).
However, what is \(\beta\) here?
13.8 Goodman-Bacon Decomposition
Goodman-Bacon (2021) showed that \(\beta\) in the TWFE is a weighted average of many different treatment effects, between treated cohorts, and control units, both can be different at different time points. The weights are a function of the size of the subsample, relative size of treatment and control units, and the timing of treatment in the sub sample. The decomposition weights themselves are non-negative and sum to one; the problem is that the units treated earlier are used as controls later. When those “forbidden” 2x2 comparisons are expressed in terms of the underlying cohort-time ATTs, some ATTs receive negative weight (de Chaisemartin and D’Haultfœuille 2020). Therefore there is no meaningful interpretation of \(\beta\): it does not need to be a convex combination of treatment effects.
Bacon decomposition
Bacon decomposition
13.9 Wooldridge’s ETWFE
There are a lot of ways to deal with staggered DiD situation. Wooldridge (2021) is basically saying: This is not a problem of TWFE, it’s a mis-use of TWFE. The reason we get non-sensible result of \(\beta\) is that we know there is heterogeneous treatment effect, in the sense the treatment effect differs across cohort, but we force them to be the same. If we relax it, it can work. As he shows, this works when we specify cohort effects accordingly.
Here \(g\) is a cohort indicator, a cohort is determined by the time of getting treatment. ETWFE is allowing each cohort to have different effect at each different time point after being treated. The baseline group is the never treated group. If there is no never treated group, it can easily be changed to comparing to the last treated group.
When the treatment comes in amounts, such as a dose or a count, the same regression extends to it. The chapter DiD with Continuous Treatment covers that case.
13.10 Example 1: US Teen Employment
We’ll use the mpdta dataset on US teen employment from the did package. “Treatment” in this dataset refers to an increase in the minimum wage rate. Our goal is to estimate the effect of this minimum wage treatment (treat) on the log of teen employment (lemp). Notice that the panel ID is at the county level (countyreal), but treatment was staggered across cohorts (first_treat) so that a group of counties were treated at the same time. In addition to these staggered treatment effects, we also observe log population (lpop) as a potential control variable.
Code
# mpdta from the did R package (Callaway & Sant'Anna 2021)mpdta = CSV.read("data/mpdta.csv", DataFrame)rename!(mpdta, "first.treat"=>"first_treat")first(mpdta, 6)
6×6 DataFrame
Row
year
countyreal
lpop
lemp
first_treat
treat
Int64
Int64
Float64
Float64
Int64
Int64
1
2003
8001
5.89676
8.46147
2007
1
2
2004
8001
5.89676
8.33687
2007
1
3
2005
8001
5.89676
8.34022
2007
1
4
2006
8001
5.89676
8.37816
2007
1
5
2007
8001
5.89676
8.48735
2007
1
6
2003
8019
2.23238
4.99721
2007
1
The three tables below give the panel shape: observations per year, the ever-treated indicator, and the treatment cohorts.
The panel is balanced: 500 counties observed in each of 2003 through 2007, 2,500 observations. 955 observations belong to ever-treated counties and 1,545 to never-treated ones. The cohorts are 2004 (100 observations, so 20 counties), 2006 (200, or 40 counties) and 2007 (655, or 131 counties), with 309 counties never treated. Treatment timing is staggered, which is exactly the case where plain TWFE misbehaves.
We fit ETWFE with log population as a control, clustering on county.
Code
mod =etwfe(mpdta, @formula(lemp ~ lpop); # outcome ~ controls tvar =:year, # time variable gvar =:first_treat, # group variable vcov = Vcov.cluster(:countyreal)); # clustered by county
The raw model has one coefficient per cohort-year cell plus the control interactions, 22 in all. That is not something to read directly. emfx() aggregates the cells into the ATT.
Code
emfx(mod)
1×5 DataFrame
Row
type
estimate
std_error
conf_low
conf_high
String
Float64
Float64
Float64
Float64
1
ATT
-0.050627
0.0124973
-0.0751212
-0.0261329
The ATT is \(-0.0506\) with a standard error of 0.0125 and a 95% interval of \([-0.0751, -0.0261]\). Raising the minimum wage lowered teen employment by about 5% on average across treated county-years.
The same cells can be aggregated by time since treatment instead.
Code
mod_es =emfx(mod, type="event")mod_es
4×5 DataFrame
Row
event
estimate
std_error
conf_low
conf_high
Int64
Float64
Float64
Float64
Float64
1
0
-0.0332122
0.013366
-0.059409
-0.00701545
2
1
-0.0573456
0.0171496
-0.0909583
-0.023733
3
2
-0.13787
0.0307884
-0.198214
-0.0775264
4
3
-0.109539
0.0323153
-0.172876
-0.0462028
The effect grows with exposure: \(-0.033\) in the treatment year, \(-0.057\) after one year, \(-0.138\) after two, \(-0.110\) after three. All four are significant. The standard errors widen with event time, from 0.013 to 0.032, because the later horizons rest on fewer cohorts: event time 0 uses all three cohorts (191 counties), event time 1 uses the 2004 and 2006 cohorts (60 counties), and event times 2 and 3 rest on the 2004 cohort alone (20 counties).
Adding post_only = FALSE keeps the pre-treatment periods in the plot.
Code
mod_es2 =emfx(mod, type="event", post_only =false)fig =Figure()ax =Axis(fig[1, 1], xlabel ="Years post treatment", ylabel ="Effect on log teen employment", xticks =-4:3, title ="Note: Zero pre-treatment effects for illustrative purposes only.")hlines!(ax, 0, color =:black)vlines!(ax, -1, color =:black, linestyle =:dash)ok = .!isnan.(mod_es2.std_error)rangebars!(ax, mod_es2.event[ok], mod_es2.conf_low[ok], mod_es2.conf_high[ok], color =:darkcyan)scatter!(ax, mod_es2.event, mod_es2.estimate, color =:darkcyan)fig
Read the pre-treatment points with care, and note the caption on the figure. With etwfe’s default comparison group the pre-treatment estimates are forced to zero by construction, so their sitting on the line is arithmetic, not evidence for parallel trends. The Poisson example below uses cgroup = "never", which frees them and makes the pre-period a real check.
13.10.1 The same data with two other staggered estimators
ETWFE is one of several estimators built to avoid the forbidden comparisons of TWFE. The R companion fits two others on the same mpdta data, Callaway and Sant’Anna (2021) and Sun and Abraham (2021). They give ATTs of \(-0.042\) and \(-0.040\) against ETWFE’s \(-0.051\), and the same growing event-time path. The gap is the comparison group: ETWFE by default compares with the not-yet-treated cohorts as well as the never-treated, and with never-treated controls only it gives \(-0.042\) with the covariate and \(-0.040\) without it, matching the other two.
13.11 Example 2: Staggered DiD
To see whether ETWFE recovers what it should, we switch to simulated data where the answer is recorded in the file.
data/did_staggered_6.dta is Wooldridge’s simulated staggered panel: 500 units observed annually from 2001 to 2006, 3,000 observations. Units are treated in 2004 (119 units), 2005 (83) or 2006 (36), and 262 are never treated. The outcome is y, x is a covariate, d4, d5 and d6 are cohort dummies, and f04, f05, f06 are year dummies. What makes the file useful is te4, te5 and te6: the true unit-level treatment effect each unit would experience under each cohort’s treatment date. The effects are heterogeneous across units and grow with time since treatment, which is precisely the configuration that breaks plain TWFE.
Code
# now we do staggered did.did_data =DataFrame(readstat("data/did_staggered_6.dta"))did_data.first_treat = [r.d4 ==1 ? 2004: r.d5 ==1 ? 2005: r.d6 ==1 ? 2006:0 for r ineachrow(did_data)]first(select(did_data, :id, :year, :y, :x, :d4, :d5, :d6, :te4, :te5, :te6, :first_treat), 6)
6×11 DataFrame
Row
id
year
y
x
d4
d5
d6
te4
te5
te6
first_treat
Int16
Int16
Float32
Float32
Int8
Int8
Int8
Float32
Float32
Float32
Int64
1
1
2001
18.3596
0.899984
0
0
0
0.0
0.0
0.0
0
2
1
2002
18.1016
0.899984
0
0
0
0.0
0.0
0.0
0
3
1
2003
18.5956
0.899984
0
0
0
0.0
0.0
0.0
0
4
1
2004
16.5003
0.899984
0
0
0
1.43223
0.0
0.0
0
5
1
2005
19.9573
0.899984
0
0
0
2.57319
2.24723
0.0
0
6
1
2006
19.8659
0.899984
0
0
0
5.06752
4.23316
0.785892
0
Code
combine(groupby(did_data, :first_treat), nrow)
4×2 DataFrame
Row
first_treat
nrow
Int64
Int64
1
0
1572
2
2004
714
3
2005
498
4
2006
216
The counts are observations, six per unit: 1,572 never-treated, 714 in the 2004 cohort, 498 in 2005, 216 in 2006.
Because the true effects are in the data, we can compute the target before estimating it. Grouping the true effects by cohort and year gives the true ATT in each cohort-year cell.
display(combine(groupby(dropmissing(did_data, :treated_cohort2), :treated_cohort2), :te5 => mean =>:mean5))display(combine(groupby(dropmissing(did_data, :treated_cohort3), :treated_cohort3), :te6 => mean =>:mean6))
2×2 DataFrame
Row
treated_cohort2
mean5
String
Float32
1
d5f05
2.73754
2
d5f06
3.51606
1×2 DataFrame
Row
treated_cohort3
mean6
String
Float32
1
d6f06
1.84886
So the true cohort-year ATTs are: the 2004 cohort gains 3.76, 4.02 and 4.58 in 2004, 2005 and 2006; the 2005 cohort gains 2.74 and 3.52 in 2005 and 2006; the 2006 cohort gains 1.85 in 2006. Effects grow with time since treatment and shrink across later cohorts — heterogeneity in both directions.
Averaging those cells over the 559 treated observations gives a true overall ATT of 3.677. That is the number ETWFE has to reproduce.
Code
# this replicates Jeff's results with pooled ols or xtreg, with covariate x.mod =etwfe(did_data, @formula(y ~ x); # outcome ~ controls tvar =:year, # time variable gvar =:first_treat, # group variable vcov = Vcov.cluster(:id))show_regression_html(mod.model)
ETWFE gives 3.67 with a standard error of 0.172 and a 95% interval of \([3.33, 4.01]\), against a true 3.677. It recovers the ATT to three decimals.
The same holds for the disaggregations. By time since treatment:
Code
mod_es =emfx(mod, type="event")mod_es
3×5 DataFrame
Row
event
estimate
std_error
conf_low
conf_high
Int64
Float64
Float64
Float64
Float64
1
0
3.10909
0.212614
2.69237
3.5258
2
1
4.01879
0.248267
3.5322
4.50539
3
2
4.20954
0.330621
3.56154
4.85755
Estimated 3.11, 4.02 and 4.21 at event times 0, 1 and 2, against true values of 3.11, 3.81 and 4.58. Every interval covers its truth, and the estimates reproduce the growth in the effect with exposure.
And by calendar year:
Code
mod_es2 =emfx(mod, type="calendar")mod_es2
3×5 DataFrame
Row
calendar
estimate
std_error
conf_low
conf_high
Int64
Float64
Float64
Float64
Float64
1
2004
3.5099
0.303131
2.91578
4.10403
2
2005
3.73388
0.253321
3.23738
4.23038
3
2006
3.70073
0.249441
3.21183
4.18962
Estimated 3.51, 3.73 and 3.70 in 2004, 2005 and 2006, against true values of 3.76, 3.49 and 3.80. Again all three intervals cover.
Note that the calendar profile is nearly flat while the event-time profile rises. There is no contradiction: later calendar years mix an older cohort with large accumulated effects and a newly treated cohort with small ones, and the two movements offset. This is why the aggregation has to be chosen to match the question being asked.
13.12 Nonlinear ETWFE: Count and Binary Outcomes
Related reading: The theory behind nonlinear ETWFE — Wooldridge’s conditional parallel-trends assumption on the linear index, the incidental parameters argument for cohort rather than unit intercepts, and the average partial effects that follow — is developed at length in Extended two-way fixed effects in Topics on Econometrics and Causal Inference, with count data and Poisson with exposure covering the count case in more detail.
ETWFE is not limited to linear (continuous) outcomes. When the dependent variable is a count or a binary indicator, linear TWFE can give nonsensical results — negative predicted probabilities, additive effects that ignore the bounded or non-negative nature of \(Y\). etwfe() supports the Poisson family via the family argument, which fits the model with fepois().
The key identifying assumption shifts slightly. Instead of parallel trends on \(E[Y_{it}(\infty)]\), we assume parallel trends on the linear index — that is, on \(\log E[Y_{it}(\infty)]\) for Poisson, or on \(\text{logit}\, E[Y_{it}(\infty)]\) for logit. This is Wooldridge’s (2023) Conditional Parallel Trends assumption stated on \(G^{-1}(E[Y])\). When the true treatment effect is multiplicative (e.g., a policy raises counts by 50% regardless of baseline), this assumption is more natural than additive PT on \(Y\) itself.
One implementation detail matters: the nonlinear ETWFE specification uses cohort fixed effects (one intercept per treatment cohort) plus year fixed effects — not individual unit fixed effects. etwfe() handles this automatically. In the linear case the two are numerically equivalent (Wooldridge 2021), but in nonlinear models unit fixed effects raise the incidental-parameters problem and make average partial effects uncomputable — the unit intercepts cannot be averaged out of the nonlinear link. Wooldridge (2023) instead uses cohort intercepts (a Mundlak device), which is what etwfe implements.
13.12.1 Simulated example: staggered count data
We simulate \(N = 400\) units over \(T = 6\) periods, 2,400 observations. Units are split into four groups of 100 by id: the first is treated from period 3, the second from period 4, the third from period 5, and the fourth never. Each unit draws a fixed effect \(\alpha_i \sim N(0, 0.3^2)\). The log mean is \(\log \mu_{it} = 1 + 0.2t + \alpha_i + 0.4 D_{it}\), and the outcome is \(Y_{it} \sim \text{Poisson}(\mu_{it})\).
The treatment effect is multiplicative and homogeneous on the log scale: every treated unit’s expected count rises by a factor of \(\exp(0.4)\), that is by \(\exp(0.4) - 1 = 0.492\), or 49%. Parallel trends holds on the log scale by construction. Here it also holds on the level scale. Cohort membership is independent of the unit effects \(\alpha_i\), so every cohort’s untreated mean, \(\exp(1 + 0.2t)\,E[e^{\alpha_i}]\), follows the same path. What differs across scales is the effect: a constant proportional effect is a larger absolute effect where the baseline is higher, so level-scale effects change over calendar time. A design where level parallel trends fails would give cohorts different untreated baseline multipliers while keeping common proportional growth.
On the count scale the ATT is not 0.492. It is \(E[\mu_{it}(0) \mid \text{treated}] \times (\exp(0.4)-1)\), and the mean untreated count among treated observations is 7.518, so the true ATT is \(7.518 \times 0.4918 = 3.698\) counts.
The table below reports mean counts by cohort and treatment status.
Code
Random.seed!(42)N =400; Tmax =6unit_fe_vals =randn(N) .*0.3df_count =DataFrame([(id = i, year = t) for i in1:N for t in1:Tmax])cohort_grp = ((df_count.id .-1) .÷100) .+1df_count.first_treat = [3, 4, 5, 0][cohort_grp] # 0 = never treateddf_count.treated = (df_count.first_treat .>0) .& (df_count.year .>= df_count.first_treat)df_count.unit_fe = unit_fe_vals[df_count.id]df_count.log_mu =1.+0.2.* df_count.year .+ df_count.unit_fe .+0.4.* df_count.treateddf_count.count =rand.(Poisson.(exp.(df_count.log_mu)))# true count-scale ATT: mean untreated mean among treated observations times exp(0.4) - 1mu0 =exp.(df_count.log_mu .-0.4.* df_count.treated)@printf("mean untreated count among treated = %.3f, true ATT = %.3f\n",mean(mu0[df_count.treated]), mean(mu0[df_count.treated]) * (exp(0.4) -1))combine(groupby(df_count, [:first_treat, :treated]), :count => mean =>:mean_count)
mean untreated count among treated = 7.518, true ATT = 3.698
7×3 DataFrame
Row
first_treat
treated
mean_count
Int64
Bool
Float64
1
0
false
5.75
2
3
false
3.75
3
3
true
10.59
4
4
false
4.31667
5
4
true
11.8167
6
5
false
4.5
7
5
true
12.12
The never-treated group averages 5.75 counts. Treated cohorts average 3.75, 4.32 and 4.50 before treatment and 10.6, 11.8 and 12.1 after. The pre-treatment means look low only because they are drawn from earlier periods, and the time trend adds 0.2 to the log mean each period. This is exactly the comparison that a raw before-after difference would get wrong.
13.12.2 Poisson ETWFE
Pass family = "poisson" to etwfe(). Everything else — cohort dummies, emfx(), event study — works identically to the linear case. We use cgroup = "never" so that pre-treatment estimates are not mechanistically forced to zero.
Code
mod_pois =etwfe(df_count, @formula(count ~1); tvar =:year, gvar =:first_treat, family ="poisson", cgroup ="never", vcov = Vcov.cluster(:id));
Code
emfx(mod_pois)
1×5 DataFrame
Row
type
estimate
std_error
conf_low
conf_high
String
Float64
Float64
Float64
Float64
1
ATT
3.62343
0.34363
2.94993
4.29693
The estimate is 3.62 counts with a standard error of 0.34 and a 95% interval of \([2.95, 4.30]\), against the true 3.698 derived above. The interval covers it.
emfx() returns average marginal effects — the average difference \(E[Y(1)] - E[Y(0)]\) in count units across treated observations. This is the ATT on the count scale. The underlying model imposes PT on the log scale, so each cohort-time treatment coefficient in the raw model can be exponentiated to get the incidence rate ratio for that cell (here they share a common value because the simulated effect is homogeneous).
13.12.3 Event study
Because we passed cgroup = "never", the pre-treatment estimates are free parameters rather than zeros by construction, so the pre-period is an actual test here. On the count scale the post-treatment effect should also grow with event time even though the log-scale effect is constant, because the baseline count grows with the time trend: the true values are 3.06, 3.74, 4.18 and 4.55 at event times 0 through 3.
Code
mod_pois_es =emfx(mod_pois, type="event", post_only =false)display(mod_pois_es)fig_p =Figure()ax_p =Axis(fig_p[1, 1], xlabel ="Years post treatment", ylabel ="ATT (count units)", xticks =-4:3, title ="Nonlinear ETWFE event study (Poisson)")hlines!(ax_p, 0, color =:black)vlines!(ax_p, -1, color =:black, linestyle =:dash)ok = .!isnan.(mod_pois_es.std_error)rangebars!(ax_p, mod_pois_es.event[ok], mod_pois_es.conf_low[ok], mod_pois_es.conf_high[ok], color =:darkcyan)scatter!(ax_p, mod_pois_es.event, mod_pois_es.estimate, color =:darkcyan)fig_p
8×5 DataFrame
Row
event
estimate
std_error
conf_low
conf_high
Int64
Float64
Float64
Float64
Float64
1
-4
0.673962
0.284111
0.117115
1.23081
2
-3
-0.045772
0.235216
-0.506785
0.415241
3
-2
0.0470628
0.176909
-0.299671
0.393797
4
-1
0.0
NaN
NaN
NaN
5
0
3.09953
0.262425
2.58519
3.61387
6
1
3.74512
0.357564
3.04431
4.44593
7
2
3.84242
0.565125
2.7348
4.95004
8
3
4.39207
0.797697
2.82861
5.95552
The pre-treatment estimates at event times \(-3\) and \(-2\) are close to zero. The one at \(-4\) is 0.67 with a standard error of 0.28, and its interval excludes zero. It rests on a single cohort-period, the period-5 cohort in period 1. Parallel trends holds by construction in this simulation, so this is one rejection in three pre-period tests at the 5% level, which chance produces often enough. With real data it would call for a closer look. The post-treatment estimates are 3.10, 3.75, 3.84 and 4.39, each with an interval that covers its true value. They rise with event time, which is the count-scale consequence of a constant log-scale effect applied to a growing baseline, not evidence of a growing treatment effect.
13.12.4 Comparison: linear ETWFE on log(count + 1)
A common alternative is to log-transform the count and run linear ETWFE. This is biased when zeros are present (the \(+1\) shift distorts the linear index) and misinterprets the scale of the effect. For comparison:
The linear model returns 0.40 with a 95% interval of \([0.336, 0.463]\). That number is neither the count-scale ATT of 3.62 nor the log-scale parameter 0.4, though it happens to sit near the latter because the counts here are large enough that \(\log(Y+1) \approx \log Y\). With many zeros the approximation breaks and the estimate drifts.
The linear model estimates the ATT on the \(\log(Y+1)\) scale — not the same quantity as the Poisson ATT and harder to interpret. When treatment effects are multiplicative, Poisson ETWFE is the more appropriate model.
13.13 Spatial Interference
Everything in this chapter so far assumes SUTVA: one unit’s outcome does not depend on another unit’s treatment. That is not always plausible. A treated municipality may affect deforestation in nearby untreated municipalities. A vaccinated household may reduce transmission to nearby households. A labor-market policy in one commuting zone may change flows to its neighbors. With this kind of spatial spillover, the usual DiD estimand no longer has the interpretation we want. Xu (2023) shows that ignoring interference can produce an estimand that is neither a direct effect nor a spillover effect.
Xu (2023, 2026) develops a doubly robust DiD that keeps the identifying logic of conditional parallel trends but adds an exposure mapping \(G_{it} = G(i, W_{-it})\) for unit \(i\)’s neighborhood treatment status. The estimand is the direct ATT at exposure level \(g\),
where \(C_i\) is unit \(i\)’s first treatment period (so \(\{C_i > t\}\) is the not-yet-directly-treated comparison group), \(S_M = \{C_i = c\} \cup \{C_i > t\}\), and \(g\) is a chosen exposure level. The DR plug-in averages three pieces over \(S_M\): an IPW term from the treated cohort, an IPW term from the not-yet-treated, and a regression-imputation term, with three propensity models (\(\eta_{tc}\) for cohort, \(\eta_{tcg}\) and \(\eta_{t\infty g}\) for exposure) and two outcome-change regressions. It is consistent if either all three propensities or both outcome models are correctly specified.
The companion package DidInterference.jl implements this. The 2x2 base case (Xu 2023):
Code
usingDidInterference, DataFrames# Wide-format two-period data with a binary exposure G.res =did_int_2x2(panel; yname =:Y_post, yname_pre =:Y_pre, treat =:W, exposure =:G, g =1, covariates = [:z1, :z2], trim =0.01) # Xu (2026) uses 0.01 in the Brazil applicationprintln(res.estimate, " ", res.ci)
For staggered adoption (Xu 2026), did_int_staggered() loops over (cohort, time) cells with \(t \geq c\), restricts to \(S_M\) in each cell, fits the DR estimator, and aggregates across cells using joint-IF stacking (per-cell IFs share the never-treated comparison group, so independence-style SEs underestimate uncertainty noticeably). The R port didint has identical estimators; its vignettes/brazil_amazon.Rmd vignette replicates Section III of Xu (2026), the Lista de Municípios Prioritários policy on Amazon deforestation, using the public Assunção-McMillan-Murphy-Souza-Rodrigues replication archive on Zenodo.
13.14 Persistent Outcomes and Heterogeneous Dynamics
leave the dynamics of \(Y\) unmodelled. Three things get run together here and are worth separating.
The first is serial correlation in \(U_{it}\). That is an inference problem rather than an identification one: with exogenous treatment timing the event-time coefficients remain consistent, but conventional standard errors are wrong, which is why DiD is routinely clustered by unit.
The second is dynamic selection. If units are treated because of their recent outcomes, then treatment timing is related to lagged \(Y\) and the parallel-trends restriction the specification relies on no longer holds. That is an identification failure, and no amount of clustering repairs it.
The third is what motivates the rest of this section. When the outcome is genuinely persistent — earnings, employment, consumption, anything with habits or adjustment costs — the structural process carries its own lag, and Equation 13.13 is a static equation fitted to dynamic data. Which target the event-time coefficients estimate then matters. Under permanent treatment in \(Y_{it} = \rho Y_{i,t-1} + \delta D_{it} + U_{it}\), the total effect at horizon \(k\) is \(\delta \sum_{j=0}^{k} \rho^j\), the immediate effect carried forward through the lag. A well-identified event study estimates that total effect. Its gap from the structural coefficient \(\delta\) grows with the horizon (Botosaru and Liu, 2025, Figure 1), but that gap is bias only if the target is \(\delta\). Persistence in the residual alone does not produce it.
Botosaru and Liu (2025) introduce a dynamic panel with correlated random coefficients that handles both persistence and unit-level heterogeneity in dynamic responses:
The latent \(\lambda_i = (\alpha_i, \delta_{i0})\) is a unit-specific correlated random coefficient. A two-step semiparametric estimator: step 1 is quasi-maximum likelihood for the common parameters \((\rho_Y, \rho_\delta, \sigma_U^2, \sigma_\varepsilon^2, \beta)\) under a Gaussian working assumption on \(\lambda_i\) (consistent under misspecification of that working assumption); step 2 is Tweedie / Gaussian-conjugate empirical Bayes for the unit-level posterior trajectories \(\{\delta_{i,j}\}_{j=0}^J\), achieving asymptotic ratio optimality.
A companion paper (Botosaru and Liu 2026) adds a homogeneous-feedback extension: covariates \(X_{it}\) are allowed to adjust endogenously to past \(Y\) and treatment (the canonical example: minimum-wage policy affects wages directly and also indirectly through firms re-optimising input demand). Under the assumption that the covariate adjustment rule does not depend on \(\lambda_i\) given the observable history, the likelihood factors into a structural piece (for \(Y \mid X\), history) and a feedback piece (for \(X\) given history), each separately identified. The factorisation yields a clean decomposition of dynamic treatment effects into direct (through \(\delta_{i,j}\)) and indirect (through covariate feedback) components.
usingTVHTE# Fit on a panel with staggered cohorts and a covariatefit =tvhte(panel_Y, baseline_Y; t0 = cohort, J = max_event_time, X = panel_X)# Feedback model + direct/indirect counterfactual decompositionfb =fit_feedback(panel_Y, baseline_Y, panel_X, baseline_X)cf =simulate_counterfactual(fit, fb, alt_cohort)
The biggest problem with DiD is the PT assumption. Synthetic control and synthetic DiD replace it with weighted comparisons. The chapter Synthetic Control, DiD, and TASC covers both, with the California Proposition 99 example.
13.16 Summary
DiD replaces unconfoundedness with parallel trends and no anticipation. The untreated trend of the treated group is taken from the control group. With staggered timing, a single TWFE coefficient averages over comparisons that can use already-treated units as controls. ETWFE fixes this by giving each cohort its own effect in each period and then aggregating. A count outcome calls for the Poisson version, which assumes parallel trends on the log scale. Spillovers, persistent outcomes and a failure of parallel trends each need their own tools: interference-robust DiD, dynamic panels, and synthetic control or synthetic DiD, which the next chapter takes up.
On the minimum-wage data, ETWFE gives an ATT of \(-0.0506\) (0.0125). On Wooldridge’s simulated panel it returns 3.67 against a true 3.677. In the count simulation, Poisson ETWFE gives 3.62 (0.34) counts against a true 3.698, while linear ETWFE on \(\log(Y+1)\) returns 0.40, a number on a different scale.
Botosaru, Irene, and Laura Liu. 2025. “Time-Varying Heterogeneous Treatment Effects in Event Studies.”arXiv Preprint arXiv:2509.13698. https://arxiv.org/abs/2509.13698.
Callaway, Brantly, and Pedro H. C. Sant’Anna. 2021. “Difference-in-Differences with Multiple Time Periods.”Journal of Econometrics 225 (2): 200–230.
Goodman-Bacon, Andrew. 2021. “Difference-in-Differences with Variation in Treatment Timing.”Journal of Econometrics 225 (2): 254–77.
Sun, Liyang, and Sarah Abraham. 2021. “Estimating Dynamic Treatment Effects in Event Studies with Heterogeneous Treatment Effects.”Journal of Econometrics 225 (2): 175–99.
Wooldridge, Jeffrey M. 2021. “Two-Way Fixed Effects, the Two-Way Mundlak Regression, and Difference-in-Differences Estimators.”SSRN Working Paper.
Xu, Ruonan. 2023. “Difference-in-Differences with Interference.”arXiv Preprint arXiv:2306.12003. https://arxiv.org/abs/2306.12003.