Extended TWFE on mpdta

Wooldridge’s estimator with not-yet-treated controls and a covariate (log county population) on R did’s minimum-wage example.

import polars as pl

from diff_stream import did_extended_twfe

panel = pl.read_csv("tests/data/mpdta.csv")
fit = did_extended_twfe(
    "lemp ~ lpop",
    panel,
    panel=("countyreal", "year"),
    cohort="first.treat",
    control_group="not_yet_treated",
    n_threads=2,
)
print(fit.aggregate().tidy())
print(fit.aggregate("overall").tidy())

Output:

shape: (4, 5)
┌─────────────┬───────────┬────────────┬───────────┬──────────┐
│ Coefficient ┆ Estimate  ┆ Std. Error ┆ t value   ┆ Pr(>|t|) │
│ ---         ┆ ---       ┆ ---        ┆ ---       ┆ ---      │
│ str         ┆ f64       ┆ f64        ┆ f64       ┆ f64      │
╞═════════════╪═══════════╪════════════╪═══════════╪══════════╡
│ event::0    ┆ -0.033212 ┆ 0.013513   ┆ -2.457842 ┆ 0.013977 │
│ event::1    ┆ -0.057346 ┆ 0.017936   ┆ -3.197227 ┆ 0.001388 │
│ event::2    ┆ -0.13787  ┆ 0.033831   ┆ -4.075239 ┆ 0.000046 │
│ event::3    ┆ -0.109539 ┆ 0.032255   ┆ -3.396029 ┆ 0.000684 │
└─────────────┴───────────┴────────────┴───────────┴──────────┘
shape: (1, 5)
┌─────────────┬───────────┬────────────┬───────────┬──────────┐
│ Coefficient ┆ Estimate  ┆ Std. Error ┆ t value   ┆ Pr(>|t|) │
│ ---         ┆ ---       ┆ ---        ┆ ---       ┆ ---      │
│ str         ┆ f64       ┆ f64        ┆ f64       ┆ f64      │
╞═════════════╪═══════════╪════════════╪═══════════╪══════════╡
│ ATT         ┆ -0.050627 ┆ 0.012986   ┆ -3.898442 ┆ 0.000097 │
└─────────────┴───────────┴────────────┴───────────┴──────────┘