Two-stage difference-in-differences (did2s)
@misc{did2s,
title = {did2s},
author = {Butts and Gardner},
howpublished = {\url{https://kylebutts.github.io/did2s/}},
note = {Software / documentation}
}Follow the analysis.
Select a node to explore the method
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
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
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")
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
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
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
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)
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Inputs & data
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
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.
Discuss the workflow (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.