Quickstart¶
Callaway-Sant’Anna, Sun-Abraham and BJS on a simulated panel of 2,000 units over 8 periods, whose effects grow with time since treatment and differ by cohort. Each prints its overall ATT.
from diff_stream import did_bjs, did_callaway_santanna, did_sun_abraham
from diff_stream.simulate import simulate_panel
data = simulate_panel(2000, 8)
for estimator in [did_callaway_santanna, did_sun_abraham, did_bjs]:
fit = estimator("y ~ 1", data, panel=("id", "time"), cohort="first_treat", n_threads=4)
fit.aggregate("overall").summary()
Output:
### y ~ 1
estimator: cs; units: 2,000
vcov: CRV0
obs: 16,000
unit clustered; normal; analytic scores
shape: (1, 5)
┌─────────────┬──────────┬────────────┬───────────┬─────────────┐
│ Coefficient ┆ Estimate ┆ Std. Error ┆ t value ┆ Pr(>|t|) │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
╞═════════════╪══════════╪════════════╪═══════════╪═════════════╡
│ ATT ┆ 1.667837 ┆ 0.046788 ┆ 35.646433 ┆ 2.6761e-278 │
└─────────────┴──────────┴────────────┴───────────┴─────────────┘
### y ~ 1
estimator: sunab; units: 2,000
vcov: CRV0
obs: 16,000
unit clustered; normal; analytic scores
shape: (1, 5)
┌─────────────┬──────────┬────────────┬───────────┬─────────────┐
│ Coefficient ┆ Estimate ┆ Std. Error ┆ t value ┆ Pr(>|t|) │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
╞═════════════╪══════════╪════════════╪═══════════╪═════════════╡
│ ATT ┆ 1.667837 ┆ 0.046717 ┆ 35.700556 ┆ 3.8754e-279 │
└─────────────┴──────────┴────────────┴───────────┴─────────────┘
### y ~ 1
estimator: bjs; units: 2,000
vcov: CRV0
obs: 16,000
unit clustered; normal; BJS smart residual averaging
shape: (1, 5)
┌─────────────┬──────────┬────────────┬──────────┬──────────┐
│ Coefficient ┆ Estimate ┆ Std. Error ┆ t value ┆ Pr(>|t|) │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
╞═════════════╪══════════╪════════════╪══════════╪══════════╡
│ ATT ┆ 1.629492 ┆ 0.040883 ┆ 39.85702 ┆ 0.0 │
└─────────────┴──────────┴────────────┴──────────┴──────────┘