psmatch2
Matches treated and control units on propensity scores, then returns ATT, standard errors, and balance diagnostics.
Instructions
Stata psmatch2-faithful supported propensity-score matching paths (nearest-neighbour, kernel, radius, local linear regression, Mahalanobis): returns matched-sample variables (_pscore _treated _support _weight _y; plus _n1 through _nn _pdif for nearest-neighbour), the psmatch2 analytic ATT standard error, plus post-matching balance (.pstest() reproduces Stata pstest exactly), common-support plotting, and weighted PSM-DID. Validation: certified parity evidence. Assumptions: Unconfoundedness / CIA: Y(d) perp D | X; Overlap / common support on the propensity score; SUTVA: no interference between matched units. Pre-conditions: binary treatment 0/1; covariates are pre-treatment (temporally prior to D); enough control units for each treated unit under k:1 matching. Failure modes: Residual imbalance after matching (max |SMD| > 0.1) -> Tighten caliper, add covariate interactions (ps_poly), or switch to sp.ebalance; Treated units off common support -> Pass common_support='minmax' (Stata common) or sp.trimming. Alternatives: sp.match, sp.psm, sp.ebalance, sp.cbps. Typical minimum N: 200.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ai | No | Abadie-Imbens (2006) robust SE with J within-arm matches (Stata ai(J)) | |
| se | No | Standard-error estimator. 'bootstrap' re-estimates the propensity score each replication and is the only valid choice for method='llr' (Stata reports seatt = . there). | psmatch2 |
| treat | Yes | Binary treatment column (0/1) | |
| bwidth | No | Kernel bandwidth (method='kernel') | |
| 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 |
| kernel | No | Kernel type (method='kernel' or 'llr'). NOTE: Stata's psmatch2 does not run LLR with kerneltype(epan) -- it substitutes lpoly-smoothed nearest-neighbour matching. Use 'tricube' to reproduce psmatch2's own LLR routine. | epan |
| method | No | Matching algorithm | neighbor |
| caliper | No | Max PS distance / radius bandwidth | |
| outcome | No | Outcome variable (Stata outcome(); optional) | |
| neighbor | No | Number of nearest neighbours k | |
| 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 | Covariate matrix, DataFrame, or column names. | |
| 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. | |
| bootstrap_reps | No | Bootstrap replications when se='bootstrap' | |
| bootstrap_seed | No | Seed for the bootstrap resampler (pass for reproducibility) | |
| common_support | No | Common-support trimming | none |
| llr_stata_compat | No | method='llr' only: reproduce Stata psmatch2's SUBSTITUTE for LLR (lpoly-smoothed outcome + nearest-neighbour matching) instead of genuine local linear regression. Set only to reconcile a published psmatch2 number. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||