Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 015
Research workflow/5 steps

Difference-in-differences with multiple periods (did)

Source did — Callaway & Sant'Anna
01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 5 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 5
01
Data prep

Build the staggered panel

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

One row per (unit, period); never-treated units get group 0 / Inf.

Reads fromNot specified Feeds into#2
Key code
# id · period · first.treat (group) · Y
head(panel)
Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

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
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

A long panel with staggered treatment timing: unit id, period, the unit's first-treatment period (group), and an outcome.

Show data format & exampleHide example

Format — one row per (unit, period). first.treat = the period a unit is first treated (0 / Inf = never treated).

 id  period  first.treat   Y
  1     2004        2006    8.1
  1     2005        2006    8.4
  2     2004           0    7.9   # never treated
03
Read the evidence

Results & interpretation

4 figures Workflow discussion 2
01FigureGroup-time ATT(g,t) from att_gt() — the effect for each treatment cohort in each period.
02FigureRaw outcome paths by group — the picture before any aggregation.
03FigureEvent-study aggregation (aggte, dynamic): effect by length of exposure, with pre-period placebo checks.
04FigureGroup / calendar aggregations summarising the ATT a few different ways.

Figures reproduced from did — Callaway & Sant'Anna — unofficial community showcase; all credit to the original authors.

Context & interpretation

The flagship 'did' vignette (Callaway & Sant'Anna). Estimate ATT(g,t) against not-yet-treated controls, then aggregate to a dynamic event study. Unofficial summary.

Peer notes

Discuss the workflow (2)

  • 4

    The whole point: never compare a treated unit to an already-treated one. att_gt() bakes that in. TWFE users, please switch.

    4

    And the dynamic aggregation gives you the event study for free, with simultaneous bands. Chef's kiss.

  • 6

    The not-yet-treated control group is what makes this robust to heterogeneous timing. Great default.

IN THE MARGINS

Peer discussion