σ StatsDoge Causal inference workflows
8
Workflow·4 steps·branched

Synthetic difference-in-differences (synthdid)

Source synthdid — Arkhangelsky, Athey, Hirshberg, Imbens & Wager
Summary by StatsDoge

Solve for unit weights (so pre-treatment fit is nearly exact) AND time weights (so periods that look like the treatment period count more), then run a weighted DiD on the reweighted panel. More robust than plain SC when parallel trends only approximately hold.

1

Input · what goes in

A balanced panel (unit × time), with one or a few treated units that switch on at a known time.

Show data format & exampleHide example

Format — a unit × time outcome matrix; treatment turns on for some units after T0.

 unit  2010 2011 2012* 2013*
   A    8.1  8.4   9.0   9.3   # treated after 2011
   B    7.9  8.0   8.1   8.2
2

Pipeline · the recipe ⑂ has parallel branches

↑ Click any step in the diagram to read its logic, code, assumptions & discussion.

1
Data prep

Balanced panel + treated block

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

What happens here

Reshape to a (unit × time) outcome matrix with the treated cells marked.

Formula
\hat au^{\mathrm{sdid}}=\arg\min_{ au,\mu,\alpha,eta} extstyle\sum_{i,t}\hat\omega_i\hat\lambda_tig(Y_{it}-\mu-\alpha_i-eta_t-W_{it} auig)^2
Reads from the input data Feeds into the final output
Key code
library(synthdid)
setup <- panel.matrices(panel)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
2
Estimation

Solve for unit & time weights

The core estimate — where the causal quantity itself is computed.

What happens here

Unit weights match pre-trends; time weights downweight uninformative periods.

Formula
\hat\omega=\arg\min_{\omega}\ \lVert Y_{ ext{pre}}^{ ext{ctrl}}\omega - Y_{ ext{pre}}^{ ext{treat}} Vert^2 + \zeta\lVert\omega Vert^2
Reads from the input data Feeds into the final output
Key code
tau.hat <- synthdid_estimate(setup$Y, setup$N0, setup$T0)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
3
Inference

Placebo / jackknife standard errors

Uncertainty quantification — standard errors, intervals, and aggregation.

What happens here

Variance from placebo reassignments or a jackknife over control units.

Formula
\widehat{\mathrm{se}}^2= frac{N_0-1}{N_0} extstyle\sum_j(\hat au_{(-j)}-ar{\hat au})^2
Reads from the input data Feeds into the final output
Key code
se <- sqrt(vcov(tau.hat, method = 'placebo'))

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
4
Reporting

Plot trajectories & the gap

Reporting — turn the numbers into a figure or table a reader can act on.

What happens here

Treated vs synthetic path, with the estimated effect shaded.

Reads from the input data Feeds into the final output
Key code
plot(tau.hat)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
3

Output · what you get

⚠️ Unofficial community showcase of synthdid. Not affiliated with the authors; all credit to them.

Reweight both control units and pre-periods to build a synthetic control, then apply a DiD correction — robust where plain SC or TWFE struggle.

Discussion (0)

  • No comments yet — start the conversation.