Made for: Master's dissertation student
Your data is ready. The model isn't cooperating.
Sound familiar?
- The Hausman test says one thing and your supervisor says another
- Stata or EViews throws errors you can't decode at 1 a.m.
- You're not sure your results are even the right ones to report
- The deadline is fixed, and your supervisor has 20 other students
We diagnose your model, run it with you, and explain every number so you can defend it.
The idea
Compare outcomes before and after a policy for a treated group and a control group:
| Before | After | Change | |
|---|---|---|---|
| Treated | 10 | 16 | +6 |
| Control | 9 | 11 | +2 |
| Difference-in-differences | +4 |
The control group's change (+2) estimates what would have happened to the treated group anyway. The DiD estimate (+4) is the policy's effect, if the two groups would have followed parallel trends without the policy.
The regression
yᵢₜ = α + β·Treatedᵢ + γ·Postₜ + δ·(Treatedᵢ × Postₜ) + controls + εᵢₜ
δ is the DiD estimate. With panel data, replace Treated and Post with unit and time fixed effects (two-way FE).
* Stata
gen treat_post = treated * post
reg y treated post treat_post controls, vce(cluster id)
* Two-way FE version
xtreg y treat_post controls i.year, fe vce(cluster id)
* Stata 17+: built-in
didregress (y controls) (treat_post), group(id) time(year)
library(fixest)
m <- feols(y ~ treat_post + controls | id + year, data = df, cluster = ~id)
Checking parallel trends
You can't test the assumption directly, but you can make it credible:
- Plot average outcomes for treated and control groups over time. Pre-treatment lines should move together.
- Event-study regression: interact treatment with dummies for each period relative to the policy. Pre-treatment coefficients ("leads") should be close to zero and insignificant; post-treatment coefficients ("lags") show how the effect evolves.
es <- feols(y ~ i(rel_year, treated, ref = -1) | id + year, data = df, cluster = ~id)
iplot(es)
- Placebo tests: pretend the policy happened earlier, or use an untreated outcome; you should find no effect.
The staggered-adoption problem
If units adopt the policy at different times, the standard two-way FE DiD can be badly biased, because already-treated units act as controls for later-treated ones (Goodman-Bacon, 2021). With staggered timing, use a heterogeneity-robust estimator:
- Callaway & Sant'Anna (2021):
csdidin Stata,didin R - Sun & Abraham (2021):
eventstudyinteract(Stata),sunab()in fixest (R) - de Chaisemartin & D'Haultfœuille (2020):
did_multiplegt
Examiners increasingly expect this discussion, so one paragraph on it strengthens your methodology chapter considerably.
Inference
Cluster standard errors at the level of treatment assignment (e.g. region or firm). With few treated clusters, use wild cluster bootstrap.
How to report it
Example: Using a two-way fixed-effects DiD, the reform increased SME credit by 12.4% (δ = 0.117, SE = 0.034, p < .01). Event-study estimates show no significant pre-trends (joint F-test on leads: p = .58). Because adoption was staggered, we confirm the result with the Callaway-Sant'Anna estimator (ATT = 0.109, p < .01).
Common mistakes
- No pre-trend evidence.
- Treated and control groups that differ fundamentally (e.g. capital city vs rural regions).
- Using TWFE with staggered adoption and heterogeneous effects.
- Clustering at the wrong level.
- "Bad controls": controls affected by the treatment itself.
Frequently asked questions
What if there's no obvious control group?
Consider synthetic control (one treated unit, many potential donors), regression discontinuity (a threshold rule), or Instrumental variables (IV/2SLS).
Can I use DiD with only two years of data?
Yes (the classic 2×2), but you can't check pre-trends. Several pre-treatment periods make the design much more convincing.