@misc{did2s,
title = {did2s},
author = {Butts and Gardner},
howpublished = {\url{https://kylebutts.github.io/did2s/}},
note = {Software / documentation}
}Gardner's 2-stage estimator for staggered DiD: residualize on the untreated, then estimate the event study — fast and timing-robust.
Input · what goes in
A staggered panel: unit id, period, treatment indicator, relative event time.
Show data format & exampleHide example
Format — one row per (unit, period).
id year treat rel_year y
1 2003 0 -2 4.0
1 2005 1 0 5.2
2 2003 0 NA 3.9
Pipeline · the recipe
↑ Click any step in the diagram to read its logic, code, assumptions & discussion.
Staggered panel + relative event time
Data preparation — shapes the raw inputs into what the estimator expects.
Unit × period; treatment indicator and event time relative to first treatment.
# id · year · treat · rel_year · y
- No comments on this step yet — be the first.
Log in to comment on this step.
[did2s] Two-stage difference-in-differences
The core estimate — where the causal quantity itself is computed.
Two-stage estimation: FE on untreated, then residuals on treatment.
Two-stage difference-in-differences — Gardner's two-stage estimator: remove unit/time fixed effects from untreated obs, then regress residuals on treatment — robust to heterogeneous timing.
did2s(df, yname="y", first_stage=~0|id+year, second_stage=~i(rel_year), treatment="treat", cluster_var="id")
- No comments on this step yet — be the first.
Log in to comment on this step.
Compare to TWFE / CS
A robustness check — does the headline result survive a different lens?
Overlay against naive TWFE and Callaway-Sant'Anna to confirm agreement.
# plot did2s vs TWFE vs CS event-study
- No comments on this step yet — be the first.
Log in to comment on this step.
Event-study plot
Reporting — turn the numbers into a figure or table a reader can act on.
Plot the dynamic effects with confidence bands.
iplot(est)
- No comments on this step yet — be the first.
Log in to comment on this step.
Output · what you get 3 figures
Figures reproduced from did2s — Butts & Gardner — unofficial community showcase; all credit to the original authors.
The did2s vignette. A lightweight alternative to Callaway-Sant'Anna for staggered designs. Unofficial summary.
Discussion (2)
Log in to join the discussion.
Gardner's 2-stage trick is elegant: residualize on the untreated, then the second stage is just OLS. Fast on huge panels.
And it lines up with Callaway-Sant'Anna in practice — nice to show both agree.
did2s + fixest under the hood = blazing. My default for big staggered panels now.