Skip to content

About

A staggered-rollout evaluator that rebuilds the two-way fixed-effects estimate from its 2x2 comparisons to expose already-treated controls, then recovers planted effects with group-time ATTs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

staggerwise

CI

staggerwise

staggerwise evaluates a staggered rollout with difference-in-differences. It rebuilds a two-way fixed-effects (TWFE) estimate exactly as a weighted sum of 2x2 comparisons (Goodman-Bacon), shows how much weight lands on comparisons that use already-treated units as controls, and then recovers planted effects with Callaway-Sant'Anna group-time ATTs, a multiplier bootstrap with uniform bands, and a pre-trend test. The data is synthetic: a restaurant chain installing self-order kiosks in four waves, with a generator that plants the true effects so every estimate can be checked against truth.json.

The problem

A quick-service chain with 120 company-operated restaurants installed self-order kiosks in four waves over 18 months; 20 restaurants never got them. Finance estimated the kiosk effect on average check with a TWFE regression (restaurant and week effects plus a treated dummy), found it modest, and the rollout to the last restaurants is in doubt. With staggered timing and an effect that grows as guests adopt the kiosks, that regression uses already-treated restaurants as controls for later waves, which drags the estimate down, and nobody can show how much of the number comes from those comparisons.

How it works

flowchart TD
    A["Restaurant-week panel<br/>restaurants.csv + weekly.csv"] --> B["Validator<br/>unique keys, no missing weeks,<br/>treatment absorbing"]
    B --> C["TWFE path<br/>double demeaning,<br/>clustered CR1 errors"]
    B --> D["Group-time path<br/>ATT(g,t) with never or<br/>not-yet-treated controls"]
    C --> E["Bacon decomposition<br/>coefficient rebuilt from<br/>weighted 2x2 comparisons"]
    D --> F["Influence functions<br/>one vector per restaurant"]
    F --> G["Aggregations<br/>simple, group, event, calendar"]
    F --> H["Multiplier bootstrap<br/>pointwise CIs and sup-t band"]
    F --> I["Pre-trend test<br/>7 event times before each base period"]
    E --> J["report.md + event_study.png"]
    G --> J
    H --> J
    I --> J
Loading

Modules in src/staggerwise/: panel.py (validation), twfe.py (static and dynamic TWFE), bacon.py (decomposition), att.py (group-time ATTs and influence functions), aggregation.py (weights shared with the truth), inference.py (bootstrap, uniform band), pretest.py, generate.py (seeded data and truth), report.py and cli.py.

Quick start

python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"

staggerwise generate --seed 11 --out data/
staggerwise twfe --data data/ --outcome avg_check
staggerwise bacon --data data/ --outcome avg_check
staggerwise att --data data/ --anticipation 2                 # simple ATT
staggerwise att --data data/ --anticipation 2 --agg event     # event study with uniform band
staggerwise att --data data/ --control notyet --agg group
staggerwise att --data data/ --anticipation 2 --by format
staggerwise pretest --data data/ --anticipation 2
staggerwise report --data data/ --out out/                    # out/report.md, out/event_study.png
pytest

Analysis commands take --data DIR and --outcome avg_check|labour_min_per_txn. att also takes --control never|notyet, --anticipation K, --agg simple|group|event|calendar|gt|all and --seed for the bootstrap.

Example output

All numbers below come from staggerwise generate --seed 11 --out data/ followed by the commands shown.

staggerwise bacon --data data/ --outcome avg_check

comparison type                             2x2s  total weight  weighted mean  contribution
------------------------------------------  ----  ------------  -------------  ------------
treated vs never-treated                       4        0.4360         +1.001       +0.4363
earlier vs later (not-yet-treated control)     6        0.2275         +0.726       +0.1651
later vs earlier (already-treated control)     6        0.3365         -0.033       -0.0111
all (sums to static TWFE)                     16        1.0000         +0.590       +0.5903

static TWFE coefficient 0.5903

Static TWFE, Callaway-Sant'Anna with never-treated and not-yet-treated controls, and the planted truth (staggerwise report, simple ATT on average check):

estimator simple ATT se 95% CI
static TWFE +0.590 0.052 +0.489 to +0.691
Callaway-Sant'Anna, never, anticipation 0 +0.996 0.057 +0.884 to +1.107
Callaway-Sant'Anna, never, anticipation 2 +1.085 0.056 +0.975 to +1.195
Callaway-Sant'Anna, notyet, anticipation 2 +1.089 0.055 +0.982 to +1.196
truth (planted) +1.107

staggerwise pretest --data data/

pre-trend test (avg_check, never controls, anticipation 0)
cohort      statistic    df  p-value  mean pre ATT  largest (event time)
----------  ---------  ----  -------  ------------  --------------------
wk 27            5.00   3.0   0.5444        -0.030           -7 (-0.159)
wk 40            4.63   3.0   0.5772        -0.059           -3 (-0.101)
wk 53          106.37   2.7  <0.0001        -0.309           -8 (-0.452)
wk 66            8.83   2.1   0.2837        -0.078           -5 (-0.169)
joint Wald     153.42  28.0  <0.0001                            28 cells
Cohort rows: sum of squared t, Satterthwaite effective df. Joint row: Wald, chi-square df = cells (tends to over-reject with few controls).
Robustness, joint sum of squared t: 124.83 on 9.3 eff. df, p = <0.0001

staggerwise pretest --data data/ --anticipation 2

pre-trend test (avg_check, never controls, anticipation 2)
cohort      statistic    df  p-value  mean pre ATT  largest (event time)
----------  ---------  ----  -------  ------------  --------------------
wk 27            8.81   2.6   0.2866        -0.066           -7 (-0.172)
wk 40            2.26   3.6   0.8418        +0.044           -8 (+0.085)
wk 53           15.26   3.1   0.0868        -0.111           -8 (-0.208)
wk 66            8.62   3.2   0.2964        +0.042           -8 (+0.168)
joint Wald      48.22  28.0   0.0102                            28 cells
Cohort rows: sum of squared t, Satterthwaite effective df. Joint row: Wald, chi-square df = cells (tends to over-reject with few controls).
Robustness, joint sum of squared t: 34.96 on 10.9 eff. df, p = 0.2486

staggerwise att --data data/ --agg event --anticipation 2 (the reference event time is -3 because the base period is g - 1 - 2):

event time  estimate     se  ci low  ci high  band low  band high   truth
----------  --------  -----  ------  -------  --------  ---------  ------
-8            +0.004  0.049  -0.091   +0.099    -0.136     +0.145  +0.000
-7            -0.038  0.041  -0.117   +0.042    -0.155     +0.080  +0.000
-6            -0.034  0.047  -0.125   +0.058    -0.168     +0.101  +0.000
-5            -0.044  0.049  -0.140   +0.052    -0.186     +0.098  +0.000
-4            -0.016  0.039  -0.093   +0.060    -0.129     +0.097  +0.000
-3            +0.000  0.000  +0.000   +0.000    +0.000     +0.000  +0.000
-2            +0.050  0.048  -0.044   +0.143    -0.088     +0.188  +0.000
-1            +0.106  0.046  +0.016   +0.195    -0.027     +0.238  +0.000
0             +0.074  0.043  -0.010   +0.158    -0.050     +0.197  +0.050
1             +0.077  0.045  -0.012   +0.166    -0.054     +0.208  +0.100
2             +0.132  0.043  +0.048   +0.215    +0.009     +0.255  +0.150
3             +0.192  0.045  +0.104   +0.280    +0.062     +0.322  +0.200
4             +0.227  0.043  +0.142   +0.312    +0.101     +0.353  +0.250
5             +0.272  0.044  +0.186   +0.358    +0.145     +0.399  +0.300
6             +0.365  0.037  +0.293   +0.438    +0.258     +0.472  +0.350
7             +0.348  0.044  +0.263   +0.434    +0.222     +0.474  +0.400
8             +0.425  0.049  +0.328   +0.522    +0.282     +0.568  +0.450
9             +0.463  0.044  +0.377   +0.548    +0.337     +0.589  +0.500
10            +0.517  0.040  +0.439   +0.595    +0.402     +0.632  +0.550
11            +0.565  0.049  +0.470   +0.661    +0.425     +0.706  +0.600
12            +0.629  0.056  +0.519   +0.739    +0.466     +0.792  +0.650
13            +0.719  0.049  +0.624   +0.814    +0.578     +0.860  +0.700
14            +0.737  0.055  +0.629   +0.846    +0.578     +0.897  +0.750
15            +0.769  0.048  +0.674   +0.864    +0.629     +0.909  +0.800
16            +0.857  0.054  +0.751   +0.963    +0.700     +1.014  +0.850
uniform band critical value 2.894

staggerwise att --data data/ --by format --anticipation 2

simple ATT by format (avg_check, never controls, anticipation 2)
format      restaurants     ATT     se            95% CI   truth
----------  -----------  ------  -----  ----------------  ------
drive-thru           61  +0.677  0.039  +0.601 to +0.753  +0.702
in-line              59  +1.509  0.051  +1.408 to +1.610  +1.528

Design decisions

  • Weights, not just a claim. bacon.py computes every 2x2 comparison and the weights from the Goodman-Bacon formulas (group shares and the share of weeks each group is treated), and tests assert the weights sum to 1 and the weighted estimates equal the static TWFE coefficient to 1e-8, on a hand fixture and on the seeded data. The cost is that the decomposition needs a balanced panel; panel.py rejects anything else and names the offending restaurant-week.
  • One truth, one set of weights. aggregation.py builds the aggregation weights for both the estimator and truth.json, so a gap between estimate and truth is estimation error rather than a weighting mismatch. Weights come from cohort sizes in the rollout plan and are held fixed in the bootstrap, which ignores uncertainty in the weights themselves. That keeps every aggregation a fixed linear map of the cell estimates.
  • Inference from influence functions. Each ATT(g,t) has a per-restaurant influence vector with an n/(n - 1) small-sample correction on each group's variance (it matters in the per-format split, where each format has only 10 never-treated controls); aggregations are linear in them, so one seeded Rademacher matrix (B = 999) serves every aggregation. Standard errors use the interquartile range of the draws, and the uniform band is the sup-t quantile over event times, floored at the pointwise 1.96 so a band is never narrower than the pointwise interval.
  • Pre-trend test: a joint Wald that over-rejects here. The headline test is the joint Wald test that all 28 pre-period ATT(g,t) cells are 0, theta' V^+ theta against chi-square(28), with V built from the influence functions. With only 20 never-treated restaurants that covariance is estimated from far fewer independent units than cells, so its inverse is noisy and the statistic tends to be too large: on 100 simulated null datasets (labour outcome, parallel trends exact) it rejected at the 5% level in 64 of them. A joint Wald over many coefficients with an estimated covariance over-rejects in a panel of this size, so a rejection is weaker evidence than its p-value suggests. Under the table the CLI prints a robustness line: the sum of squared t-statistics with a Satterthwaite chi-square approximation, which does not invert the covariance and rejected in 11 of the same 100 datasets (somewhat above nominal, and an approximation). On seed 11 with --anticipation 2 the Wald gives p = 0.0102 (statistic 48.22 on 28 df) while the robustness line gives p = 0.2486; both numbers are reported as they come out, and tests/test_pretest.py pins them.
  • Anticipation shifts the base period. --anticipation k moves each cohort's universal base period to g - 1 - k and excludes not-yet-treated controls inside the anticipation window. The planted menu-board effect in wave 3 biases the default run (the pre-test rejects, wave-3 group ATT understated by about $0.30). --anticipation 2 removes the wave-3 bias and the wave-3 cohort's pre-trend rejection, though the joint Wald still rejects (p = 0.0102, see above). The cost is two fewer pre-periods and cohorts treated in the first k + 1 weeks cannot be estimated.
  • Standard errors for TWFE. Restaurant-clustered CR1 with the small-sample factor G/(G-1) x (n-1)/(n-k), counting the regressors and the T-1 week effects but not restaurant effects, which are nested in clusters.
  • Seed-pinned numbers. The example output and some test assertions depend on numpy's seeded Generator stream; CI installs the versions in uv.lock, so a different numpy release could shift the last digits without any code change.

Testing

pytest runs 88 tests offline in a few seconds. They cover the hand fixture (3 restaurants x 4 weeks, ATT(3,3) = 3.0 with never-treated and 2.5 with not-yet-treated controls), the Bacon identity, TWFE against a dummy-variable regression, influence functions against the two-sample variance formula, panel validation, and recovery of the planted effects on the seeded data: simple ATT within $0.10 of truth with truth inside its interval, uniform band covering the true event-time effects for e = 0..16, a constant-effect control outcome where TWFE and group-time ATTs agree, the anticipation effect caught by the pre-test and its bias removed by the option, and the format split.

Project layout

src/staggerwise/
  panel.py        validation, Panel
  generate.py     seeded kiosk data and truth.json
  aggregation.py  aggregation weights
  att.py          ATT(g,t) and influence functions
  inference.py    multiplier bootstrap, pointwise and uniform bands
  pretest.py      joint Wald pre-trend test
  twfe.py         static and dynamic TWFE
  bacon.py        Goodman-Bacon decomposition
  analysis.py     format split
  sections.py     table text shared by the CLI and report
  render.py       table rendering
  report.py       report.md and event_study.png
  cli.py          typer commands
tests/            pytest suite
.github/workflows/ci.yml

License

MIT, see LICENSE.

About

A staggered-rollout evaluator that rebuilds the two-way fixed-effects estimate from its 2x2 comparisons to expose already-treated controls, then recovers planted effects with group-time ATTs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages