did_2x2
Estimate causal treatment effects with a two-group, two-period difference-in-differences design. Compares pre/post changes between treated and control units via differencing or OLS, with optional covariates and robust/cluster SEs.
Instructions
Canonical 2x2 DID: two groups (treated / control) x two periods (pre / post). Point estimate via either group-means differencing or OLS on the treat x post interaction; optional covariates, robust / cluster SE, and sample weights. Validation: certified parity evidence. Do NOT use when: treatment timing is staggered across units -- the TWFE 2x2 estimate is a negative-weighted mix (Goodman-Bacon 2021); use sp.callaway_santanna, sp.sun_abraham or sp.did_imputation. Assumptions: Parallel trends; No anticipation; SUTVA (no spillovers). Pre-conditions: data has exactly two time periods (pre, post); treat is 0/1 constant within unit (unit-level, not time-varying); at least a handful of treated and control units. Failure modes: Staggered timing (> 2 periods with varying treat start) -> Use sp.callaway_santanna / sp.sun_abraham / sp.did_imputation; Very few clusters at the group level -> Use wild cluster bootstrap via sp.wild_cluster_bootstrap; 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.drdid, sp.did_analysis, sp.callaway_santanna, sp.sun_abraham. Typical minimum N: 30.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| y | Yes | Outcome variable | |
| time | Yes | Time / period indicator | |
| alpha | No | Significance level for confidence intervals and tests. | |
| treat | Yes | Binary treatment-group indicator (0/1) | |
| 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 |
| robust | No | Heteroskedasticity-robust SE when no cluster provided | |
| cluster | No | Column for cluster-robust SE (defaults to treat) | |
| weights | No | Optional column name for sampling weights | |
| 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 | No | Covariates included additively; for DR use sp.drdid | |
| 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. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||