did_timevarying_covariates
Estimate difference-in-differences treatment effects in staggered adoption by freezing time-varying covariates at baseline, preventing bad-controls bias when treatment affects covariates.
Instructions
DiD with time-varying covariates frozen at baseline (Caetano, Callaway, Payne & Rodrigues 2022 [pending verification]). Avoids the bad-controls bias that arises when treatment affects the covariates: freezes X at period g + baseline_offset (default g-1) per cohort and uses the frozen values as controls in a per-(g, t) outcome-regression DiD. Aggregates via cohort-size weights. Assumptions: Conditional parallel trends given frozen baseline X; No anticipation; SUTVA. Pre-conditions: staggered adoption with >= 1 never-treated unit; covariates column(s) exist for the baseline period per cohort; integer-valued time column. Failure modes: No observation at baseline period for some units -> Fallback uses the first observed period; review detail coverage; Covariate measured with error or missing -> Impute (sp.mice_impute) or restrict to a complete sub-sample before calling; Pre-trend joint test p < 0.05 (or underpowered at 0.10) -> Use sp.sensitivity_rr (Rambachan & Roth honest CI) or switch to sp.callaway_santanna. Alternatives: sp.callaway_santanna, sp.drdid, sp.wooldridge_did, sp.sun_abraham. Typical minimum N: 150.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| y | Yes | Outcome variable column name or outcome array. | |
| seed | No | Random seed for reproducible stochastic steps. | |
| time | Yes | Time period column. | |
| unit | Yes | Unit identifier column. | |
| alpha | No | Significance level for confidence intervals and tests. | |
| cohort | Yes | First-treatment period (never_value = never-treated) | |
| 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 |
| n_boot | No | Number of bootstrap replications. | |
| 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. | |
| covariates | Yes | Time-varying covariates to freeze at baseline | |
| never_value | No | never_value parameter. | |
| 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. | |
| baseline_offset | No | Offset relative to first-treatment period for freezing |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||