|
| 1 | +# Staggered Difference-in-Differences — Callaway & Sant'Anna (2021) |
| 2 | + |
| 3 | +StatsPAI implements the Callaway–Sant'Anna estimator from first |
| 4 | +principles, matching the R `did` package's core functionality while |
| 5 | +adding new convenience layers on top. |
| 6 | + |
| 7 | +## Basic usage |
| 8 | + |
| 9 | +```python |
| 10 | +import statspai as sp |
| 11 | + |
| 12 | +cs = sp.callaway_santanna( |
| 13 | + df, |
| 14 | + y='earnings', # outcome |
| 15 | + g='first_treat', # first-treatment period (0 = never-treated) |
| 16 | + t='year', # time period |
| 17 | + i='worker_id', # unit id |
| 18 | + estimator='dr', # 'dr' (default), 'ipw', or 'reg' |
| 19 | + control_group='nevertreated', # or 'notyettreated' |
| 20 | + anticipation=0, # periods of anticipation (CS2021 §3.2) |
| 21 | +) |
| 22 | + |
| 23 | +print(cs.summary()) |
| 24 | +cs.detail # one row per (group, time) with ATT + pointwise CI |
| 25 | +cs.model_info['event_study'] # event-study aggregation |
| 26 | +cs.model_info['pretrend_test'] # joint Wald pre-trend test |
| 27 | +``` |
| 28 | + |
| 29 | +## Aggregation with uniform bands |
| 30 | + |
| 31 | +The raw `callaway_santanna()` result is a grid of ATT(g, t) estimates. |
| 32 | +Collapse to a scalar or an event-study curve with `aggte()`, which |
| 33 | +layers the Mammen (1993) multiplier bootstrap on top and returns |
| 34 | +*simultaneous* confidence bands: |
| 35 | + |
| 36 | +```python |
| 37 | +es = sp.aggte(cs, type='dynamic', |
| 38 | + n_boot=500, random_state=0, |
| 39 | + balance_e=3) # balance across cohorts for e ≤ 3 |
| 40 | + |
| 41 | +print(es.detail) |
| 42 | +# relative_time att se ci_lower ci_upper cband_lower cband_upper ... |
| 43 | +``` |
| 44 | + |
| 45 | +The `cband_lower` / `cband_upper` columns give a sup-t uniform band — |
| 46 | +valid for simultaneous inference across the entire event window, |
| 47 | +unlike the pointwise CI. |
| 48 | + |
| 49 | +Other aggregation types: |
| 50 | + |
| 51 | +| `type=` | Meaning | |
| 52 | +| --- | --- | |
| 53 | +| `'simple'` | cohort-share-weighted overall ATT | |
| 54 | +| `'dynamic'` | event-study curve ATT(e) | |
| 55 | +| `'group'` | per-cohort average ATT(g) | |
| 56 | +| `'calendar'` | per-calendar-time ATT(t) | |
| 57 | + |
| 58 | +## Repeated cross-sections |
| 59 | + |
| 60 | +Pass `panel=False` when observations are not matched across time |
| 61 | +(e.g. CPS pooled cross-sections). The estimator switches to the |
| 62 | +unconditional 2×2 cell-mean DID with observation-level influence |
| 63 | +functions; downstream `aggte`, `cs_report`, `ggdid`, and `honest_did` |
| 64 | +all work unchanged. |
| 65 | + |
| 66 | +```python |
| 67 | +cs_rcs = sp.callaway_santanna( |
| 68 | + survey_df, |
| 69 | + y='wage', g='first_treat', t='year', i='respondent_id', |
| 70 | + estimator='reg', # only 'reg' supported in RCS mode |
| 71 | + x=['age', 'education'], # optional covariate residualisation |
| 72 | + panel=False, |
| 73 | +) |
| 74 | +``` |
| 75 | + |
| 76 | +## Sensitivity — Rambachan & Roth (2023) |
| 77 | + |
| 78 | +Every event-study result (from CS, SA, BJS, or `aggte`) feeds into |
| 79 | +the Rambachan–Roth sensitivity framework: |
| 80 | + |
| 81 | +```python |
| 82 | +sens = sp.honest_did(es, e=2) # robust CI at e=2 across an M grid |
| 83 | +m_star = sp.breakdown_m(es, e=2) # largest M* under which effect is significant |
| 84 | +``` |
| 85 | + |
| 86 | +## One-call report |
| 87 | + |
| 88 | +For a ready-to-publish summary — raw estimation + four aggregations |
| 89 | +with uniform bands + pre-trend Wald + R-R breakdown M\* per post |
| 90 | +event time — call [`cs_report()`](cs_report.md). |
0 commit comments