stacked_did
Estimates staggered-adoption treatment effects by stacking per-cohort sub-experiments with clean controls, avoiding contamination from late-treated units.
Instructions
Stacked DiD (Cengiz, Dube, Lindner, Zipperer 2019). For each treatment cohort, constructs a sub-experiment with only that cohort + clean (never-treated or not-yet-treated) controls, then TWFE on the stacked panel. Robust to staggered-adoption contamination at the cost of dropping late-treated units in early sub-experiments. Validation: certified parity evidence. Do NOT use when: there is a single adoption cohort -- stacking produces one sub-experiment and is equivalent to sp.did(method='2x2'). Cost: Duplicates rows into one sub-experiment per treated cohort: the stacked dataset is roughly O(n x number of cohorts) before the event window trims it. Narrow window= to bound memory. Assumptions: Parallel trends within each sub-experiment; No anticipation within window; SUTVA. Pre-conditions: staggered adoption with >= 2 cohorts; window horizon available per cohort (else dropped). Failure modes: No clean controls for the latest cohort -> Late cohort's sub-experiment is dropped; check coverage in model_info. Consider sp.callaway_santanna. Alternatives: sp.callaway_santanna, sp.sun_abraham, sp.did_imputation. Typical minimum N: 100.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| y | Yes | Outcome variable column name or outcome array. | |
| time | Yes | Time period column. | |
| alpha | No | Significance level for confidence intervals and tests. | |
| group | Yes | Unit identifier | |
| detail | No | Payload depth: 'minimal' (~150 tokens) for sub-step calls where only the point estimate is needed; 'standard' (~1K tokens) for diagnostics + coefficient table; 'agent' (~2K tokens, default) adds violations / next_steps / suggested_functions so the LLM can plan its next call without another round-trip. | agent |
| window | No | Event-time (lead, lag) window per sub-experiment | |
| cluster | No | Cluster identifier column for clustered standard errors. | |
| controls | No | Control-variable column names. | |
| as_handle | No | If true, cache the fitted result on the server and return result_id + result_uri alongside the JSON payload so a subsequent tools/call can chain without re-running. | |
| data_path | Yes | Absolute path or URL to a data file. Supported: .csv / .tsv / .txt (delimited), .parquet / .pq, .feather / .arrow, .xlsx / .xls, .dta (Stata), .json / .jsonl. Schemes: file://, s3://, gs://, https://. | |
| result_id | No | Optional handle to a previously-fitted result (returned by an earlier call when as_handle=true). Tools that operate on a fitted object accept this in place of re-supplying data_path + columns. | |
| first_treat | Yes | first_treat parameter (str). | |
| data_columns | No | Optional column projection. Parquet/Feather/Stata loaders honour this for fast partial reads. | |
| data_sample_n | No | Optional uniform random subsample size (seed=0, deterministic) — useful on huge panels. | |
| never_treated_only | No | Use only never-treated as controls (drops late-treated) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||