Skip to content
Back to search

StatsPAI

StatsPAI is the first Agent-native Python library for causal inference and applied econometrics — unified API, broad cross-method coverage, structured result objects, machine-readable schemas, Skills, an MCP server, and R/Stata parity validation.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/brycewang-stanford/StatsPAI with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/brycewang-stanford/StatsPAI'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/brycewang-stanford--statspai/badge.svg)](/listings/brycewang-stanford--statspai)

HTML

<a href="/listings/brycewang-stanford--statspai"><img src="/api/listings/brycewang-stanford--statspai/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

pip install statspai

支持 Python 3.10 – 3.13(Linux 与 macOS)。核心安装已包含估计、诊断、内置数据集,以及 `.xlsx` / `.docx` / LaTeX 导出。画图和较重的后端是可选 extras:

| Extra | 增加 | 用途 | | --- | --- | --- | | `statspai[plotting]` | matplotlib、seaborn、plotly | `.plot()`、`sp.ggdid()`、`sp.interactive()` 等图形 | | `statspai[fixest]` | pyfixest(Python ≥ 3.10) | `sp.fixest.*` 封装,以及交叉验证中的 pyfixest 引擎 | | `statspai[bayes]` | PyMC、ArviZ | 贝叶斯估计器 | | `statspai[neural]` / `statspai[deepiv]` | PyTorch | 神经网络因果模型、DeepIV | | `statspai[performance]` | JAX | 加速后端 | | `statspai[spatial]` | geopandas、libpysal、shapely | shapefile / 几何空间权重 |

交互式图表编辑器在 Jupyter 里还需要 `ipywidgets`。

import statspai as sp

print(sp.datasets.list_datasets()[["name", "design", "source"]])

StatsPAI 内置 14 个可离线加载的数据集。大部分是真实的已发表数据(`source == "bundled CSV"`):Card (1995) NLSYM 教育回报数据、带 PSID 对照组的 LaLonde/NSW、R `rdrobust` 附带的美国参议院 RD 数据、California Proposition 99、castle-doctrine 面板、NHEFS 等。少数是按已发表设计校准的**确定性模拟复刻**(`source == "simulated"`),包括下面用到的 Callaway–Sant'Anna `mpdta` 面板——它们的数字不是原始数据上的数字。

一眼概览:1,413 个注册函数,分布在 89 个子模块;528k 行核心代码 + 352k 行测试。运行 `python scripts/registry_stats.py` 可复现这些数字。

---

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 960 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. [简体中文](https://github.com/brycewang-stanford/statspai/blob/main/README_CN.md) | English
  2. <!-- mcp-name: io.github.brycewang-stanford/statspai -->
  3. <p align="center">
  4. <img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/logo/readme-1.png" alt="StatsPAI - Python-native Stata and R replacement for applied causal inference" width="780">
  5. </p>
  6. # StatsPAI: an Agent&Python-native Stata/R replacement for applied causal inference
  7. [![PyPI version](https://img.shields.io/pypi/v/StatsPAI.svg)](https://pypi.org/project/StatsPAI/)
  8. [![Python versions](https://img.shields.io/pypi/pyversions/StatsPAI.svg)](https://pypi.org/project/StatsPAI/)
  9. [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/brycewang-stanford/statspai/blob/main/LICENSE)
  10. [![Tests](https://github.com/brycewang-stanford/statspai/workflows/CI%2FCD%20Pipeline/badge.svg)](https://github.com/brycewang-stanford/statspai/actions)
  11. [![Docs](https://img.shields.io/badge/docs-mkdocs--material-blue.svg)](https://brycewang-stanford.github.io/StatsPAI/)
  12. [![PyPI Downloads](https://static.pepy.tech/personalized-badge/statspai?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/statspai)
  13. [![JOSS](https://joss.theoj.org/papers/10.21105/joss.10604/status.svg)](https://doi.org/10.21105/joss.10604)
  14. [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.19933900-blue.svg)](https://doi.org/10.5281/zenodo.19933900)
  15. <p align="center">
  16. <img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/logo/stanford-reap-logo.png" alt="Stanford Rural Education Action Program (REAP) - Center on China's Economy &amp; Institutions" height="94">
  17. &nbsp;&nbsp;&nbsp;&nbsp;
  18. <a href="https://doi.org/10.21105/joss.10604"><img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/logo/joss-logo.png" alt="JOSS - The Journal of Open Source Software" height="72"></a>
  19. <br>
  20. Developed and maintained by the <strong>Stanford REAP</strong> team
  21. <br>
  22. Published in the <strong><em>Journal of Open Source Software</em> (JOSS)</strong>: Wang &amp; Rozelle (2026), 11(125), 10604 · <a href="https://doi.org/10.21105/joss.10604">doi:10.21105/joss.10604</a>
  23. </p>
  24. StatsPAI is for empirical researchers who would normally jump between Stata, R,
  25. and Python. Its goal is to make common Stata/R econometrics and causal-inference
  26. workflows feel native in Python: load a dataset, estimate a model, inspect
  27. diagnostics, export tables, and hand the result to an agent or notebook without
  28. leaving one API.
  29. It is meant to be a practical replacement path for new Python-first work:
  30. - Stata-style routines: `regress`, `ivregress`, `reghdfe`, `csdid`, `rdrobust`,
  31. `synth`, `psmatch2`, `esttab` / `outreg2`.
  32. - R-style routines: `lm`, `fixest`, `did`, `rdrobust`, `Synth`, `DoubleML`,
  33. `MatchIt`, `modelsummary`, `broom`.
  34. - Stata conventions where they matter: `vce="robust"` / `vce="cluster firm"`
  35. on `regress`, `ivreg` and the likelihood estimators, Stata's small-sample
  36. factors and z / t reference distributions, `test` / `lincom` /
  37. `margins, dydx()` after any fit, and `sp.stata("...", data=df)` to run
  38. Stata command lines you already have.
  39. - Python-native outputs: `.summary()`, `.tidy()`, `.plot()`, `.to_latex()`,
  40. `.to_docx()`, `.to_agent_summary()` where supported by the result object.
  41. - Agent-native access: every public function is registered with a
  42. machine-readable schema (`sp.list_functions()`, `sp.describe_function()`,
  43. `sp.function_schema()`), and the bundled `statspai-mcp` server exposes the
  44. estimators to MCP clients such as Claude Code, Claude Desktop, and Cursor.
  45. - Companion Stata tooling: our own
  46. [`stata-code`](https://github.com/brycewang-stanford/stata-code/) can work
  47. with StatsPAI so agents can understand existing Stata workflows, translate
  48. them into Python, and cross-check results more smoothly.
  49. - Companion skill repos:
  50. [`Auto-Empirical-Research-Skills`](https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills),
  51. [`AER-Skills`](https://github.com/brycewang-stanford/AER-Skills),
  52. [`Awesome-Journal-Skills`](https://github.com/brycewang-stanford/Awesome-Journal-Skills),
  53. and [`Paper-WorkFlow`](https://github.com/brycewang-stanford/Paper-WorkFlow)
  54. can work alongside StatsPAI and an agent as the methods, journal, manuscript,
  55. and reproducibility skill layer.
  56. StatsPAI is not a promise that every Stata/R command is bit-for-bit identical.
  57. The API is broad, and the numerical evidence behind it is uneven: some
  58. estimators are checked against R/Stata on identical data, others only against
  59. known-truth simulations, and many are API-stable without a numerical-parity
  60. claim yet. Every function carries a `validation_status` that says which case
  61. applies: `validation_status` distinguishes certified/validated evidence from API-stable breadth. See
  62. [Validation](#validation-what-has-been-checked-and-what-has-not) before relying
  63. on a number for publication.
  64. ---
  65. ## Install
  66. ```bash
  67. pip install statspai
  68. ```
  69. Python 3.10 – 3.13 on Linux and macOS. The core install covers estimation, diagnostics, the bundled
  70. datasets, `.xlsx` / `.docx` / LaTeX export, and matplotlib figures (`.plot()`,
  71. `sp.ggdid()` and the rest). seaborn / plotly styles and heavier backends are
  72. optional extras:
  73. | Extra | Adds | Needed for |
  74. | --- | --- | --- |
  75. | `statspai[plotting]` | seaborn, plotly (matplotlib is a core dependency) | seaborn-styled and interactive plotly figures |
  76. | `statspai[fixest]` | pyfixest (Python ≥ 3.10) | `sp.fixest.*` wrappers and the pyfixest cross-validation engine |
  77. | `statspai[bayes]` | PyMC, ArviZ | Bayesian estimators |
  78. | `statspai[neural]` / `statspai[deepiv]` | PyTorch | neural causal models, DeepIV |
  79. | `statspai[performance]` | JAX | accelerated backends |
  80. | `statspai[rust]` (until the next release: `pip install statspai-hdfe`) | [statspai-hdfe](https://pypi.org/project/statspai-hdfe/) | Rust kernels for HDFE demeaning, Poisson IRLS and cluster SEs in `sp.fast.*`, `sp.hdfe_ols`, `sp.ppmlhdfe`, `sp.regress(cluster=)`; `sp.fast.backend_info()` reports whether they are used ([guide](docs/guides/rust_kernels.md)) |
  81. | `statspai[spatial]` | geopandas, libpysal, shapely | shapefile / geometry-based spatial weights |
  82. The interactive figure editor additionally needs `ipywidgets` inside Jupyter.
  83. ```python
  84. import statspai as sp
  85. print(sp.datasets.list_datasets()[["name", "design", "source"]])
  86. ```
  87. `sp` is the convention used throughout these docs, but the alias is your
  88. choice. If `sp` is already taken in your code (for example by
  89. `import scipy as sp`), `import statspai as si` works just as well.
  90. StatsPAI bundles 14 datasets that load offline. Most are real published
  91. extracts (`source == "bundled CSV"`): Card (1995) NLSYM schooling data,
  92. LaLonde/NSW with a PSID comparison group, the U.S. Senate RD data distributed
  93. with R's `rdrobust`, California Proposition 99, the castle-doctrine panel, and
  94. NHEFS, among others. A few are deterministic **simulated replicas** calibrated
  95. to a published design (`source == "simulated"`), including the
  96. Callaway–Sant'Anna `mpdta` panel used below; their numbers are not the numbers
  97. from the original data.
  98. At a glance: 1,687 registered functions across 92 submodules; 756k LOC (core) + 519k LOC (tests). Run `python scripts/registry_stats.py` to reproduce these numbers.
  99. ---
  100. ## If You Come From Stata Or R
  101. | What you used before | Stata / R examples | StatsPAI entry point |
  102. | --- | --- | --- |
  103. | OLS / robust SE | `reg y x, vce(robust)` / `lm()` + `sandwich` | `sp.regress("y ~ x", data=df, vce="robust")` |
  104. | Clustered SE | `vce(cluster firm)` / `sandwich::vcovCL()`, `feols(..., cluster = ~firm)` | `vce="cluster firm"` (or `cluster="firm"`); `sp.feols(..., cluster="firm")` |
  105. | Logit / probit / count models | `logit`, `probit`, `poisson`, `nbreg` / `glm()`, `MASS::glm.nb()` | `sp.logit()`, `sp.probit()`, `sp.poisson()`, `sp.nbreg()`, `sp.glm()` |
  106. | IV / 2SLS | `ivregress 2sls` / `AER::ivreg()` | `sp.ivreg("y ~ (d ~ z) + x", data=df)` |
  107. | High-dimensional FE | `reghdfe` / `fixest::feols()` | `sp.feols("y ~ x \| firm + year", data=df)` |
  108. | Staggered DiD | `csdid` / `did::att_gt()` | `sp.callaway_santanna()` + `sp.aggte()` |
  109. | Regression discontinuity | `rdrobust` / `rdrobust::rdrobust()` | `sp.rdrobust()` |
  110. | Synthetic control | `synth` / `Synth::synth()` | `sp.synth()` |
  111. | Matching / PSM | `psmatch2` / `MatchIt` | `sp.psmatch2()`, `sp.match()` |
  112. | Double machine learning | `ddml` / `DoubleML` | `sp.dml()` |
  113. | Post-estimation | `test`, `lincom`, `margins, dydx()` | `fit.test()`, `fit.lincom()`, `sp.margins(fit)` |
  114. | Publication tables | `esttab`, `outreg2` / `modelsummary` | `sp.regtable()` |
  115. | Run Stata lines as they are | a `.do` snippet | `sp.stata("logit y x, vce(cluster id)\nmargins, dydx(x)", data=df)` |
  116. | Translate a command | — | `sp.from_stata("reghdfe y x, absorb(id year)")`, `sp.from_r("feols(...)")` |
  117. On `regress`, `ivreg`, `glm`, `logit`, `probit`, `poisson`, `nbreg`, the
  118. ordered / multinomial / conditional logits, the zero-inflated and hurdle
  119. models, `liml` and more, `vce=` / `robust=` follow Stata's `vce()` grammar
  120. (`sp.feols` keeps fixest's `vcov=` / `cluster=`): `True`, `"robust"`,
  121. `"vce(robust)"`, `"oim"`, `"hc0"`–`"hc3"`, and a cluster variable written
  122. inline (`"cluster firm"`, `"vce(cluster firm)"`, `"cl firm"`). A spelling an
  123. estimator does not implement raises an error instead of quietly falling back
  124. to different standard errors. Robust and cluster SEs apply Stata's
  125. small-sample factors, clustered OLS / IV use t(G-1), and likelihood-based fits
  126. report z. The oim / robust / cluster standard errors of 29 estimators are
  127. pinned to Stata 18 at the 1e-6 parity budget (three documented exceptions
  128. where the two optimisers stop at slightly different points). See the
  129. [shared argument grammar](docs/guides/grammar.md) guide.
  130. Causal entry points also accept one shared set of argument names next to each
  131. estimator's native spelling: `id=` for the panel unit, `time=`,
  132. `first_treat=` for adoption cohorts, `covariates=`, and `running=` /
  133. `cutoff=` for RD. `sp.callaway_santanna(data=mp, y="lemp", time="year",
  134. id="countyreal", first_treat="first_treat")` is the same call as the
  135. `t=` / `i=` / `g=` version below; a misspelt keyword names the closest one
  136. (`runing=` → "did you mean 'running'?"), and
  137. `sp.describe_function(name)["aliases"]` lists the accepted spellings.
  138. `sp.esttab()`, `sp.outreg2()`, and `sp.modelsummary()` still exist, but they are
  139. deprecated thin wrappers over `sp.regtable()` and emit a `DeprecationWarning`.
  140. ---
  141. ## Compared With Other Python Packages
  142. StatsPAI aims to be one broad Stata/R-style workbench. Several focused Python
  143. packages do one part of that job, often with a longer track record; if you only
  144. need that part, they are good choices.
  145. | Package | What it focuses on | How StatsPAI relates |
  146. | --- | --- | --- |
  147. | [`pyfixest`](https://github.com/py-econometrics/pyfixest) | fixest-style OLS / IV / GLM with high-dimensional fixed effects, event-study DiD, wild bootstrap, tables | StatsPAI has its own `sp.feols` (checked against R `fixest`) and uses pyfixest as an optional wrapper and cross-validation engine. |
  148. | [`linearmodels`](https://github.com/bashtage/linearmodels) | panel models, IV / GMM, system estimation | A core StatsPAI dependency for parts of the panel module, and an independent engine in `sp.cross_validate`. |
  149. | [`DoubleML`](https://github.com/DoubleML/doubleml-for-py) | double/debiased ML (PLR, PLIV, IRM, IIVM), with an R twin | `sp.dml` is checked against DoubleML on identical learners and folds. |
  150. | [`EconML`](https://github.com/py-why/EconML) | heterogeneous treatment effects: DML, causal forests, DR learners, IV, policy learning | `sp.metalearner` is checked against EconML's S/T/X learners. |
  151. | [`DoWhy`](https://github.com/py-why/dowhy) | graph-based model → identify → estimate → refute workflow; graphical causal models | StatsPAI has DAG and causal-discovery tools, but is estimator-first rather than graph-first. |
  152. | [`CausalPy`](https://github.com/pymc-labs/CausalPy) | Bayesian-first quasi-experiments in PyMC (plus OLS via scikit-learn): DiD, synthetic control, RD, ITS, IV | StatsPAI centres frequentist econometric conventions (clustered / robust SEs, bias-corrected RD, CS-DiD aggregation) and cross-language parity evidence. |
  153. | [`causallib`](https://github.com/BiomedSciAI/causallib) | scikit-learn-style IPW, standardization, doubly robust estimation, and causal evaluation | StatsPAI covers these alongside regression, panel, DiD, RD, and synthetic-control workflows in one API. |
  154. Use StatsPAI when you want one package, one function registry, and one agent
  155. interface across the everyday Stata/R empirical workflow.
  156. ---
  157. ## Beginner Examples With Results
  158. The outputs below were produced with StatsPAI 1.29.0 on the bundled
  159. datasets and are pinned by `tests/test_readme_examples.py`, so they cannot
  160. drift from the code silently. Example 6 uses the Stata `vce()` grammar and
  161. post-estimation commands introduced in 1.29.0; on an older release install
  162. from source with
  163. `pip install "statspai @ git+https://github.com/brycewang-stanford/StatsPAI"`.
  164. Long summaries are abridged (`...` marks omitted lines); the numbers are pinned
  165. by `tests/test_readme_examples.py` and `tests/test_synth_placebo_pvalue.py`, so
  166. they cannot silently drift from the code again.
  167. ### 1. OLS: the first `regress` / `lm` replacement
  168. Question: how much higher is log wage for one more year of schooling in the
  169. Card (1995) NLSYM data?
  170. ```python
  171. import statspai as sp
  172. card = sp.datasets.card_1995()
  173. ols = sp.regress(
  174. "lwage ~ educ + exper + expersq + black + south + smsa",
  175. data=card,
  176. robust="hc1",
  177. )
  178. print(ols.summary())
  179. ```
  180. Result:
  181. ```text
  182. Model: OLS
  183. Method: Least Squares
  184. Dependent Variable: lwage
  185. ...
  186. Coefficient Std. Error t-statistic P>|t| [0.025 0.975]
  187. Intercept 4.7337 0.0702 67.4718 0.0000 4.5961 4.8712
  188. educ 0.0740 0.0036 20.3208 0.0000 0.0669 0.0812
  189. exper 0.0836 0.0067 12.4165 0.0000 0.0704 0.0968
  190. expersq -0.0022 0.0003 -7.0443 0.0000 -0.0029 -0.0016
  191. black -0.1896 0.0174 -10.8781 0.0000 -0.2238 -0.1555
  192. south -0.1249 0.0154 -8.1339 0.0000 -0.1550 -0.0948
  193. smsa 0.1614 0.0152 10.6374 0.0000 0.1317 0.1912
  194. Model Diagnostics:
  195. --------------------
  196. R-squared : 0.2905
  197. ...
  198. ```
  199. Read it like a Stata/R regression table: conditional on experience, race,
  200. region, and SMSA, one more year of schooling is associated with about `0.074`
  201. higher log wage (roughly 7.4%). This is a correlation, not yet a causal return:
  202. schooling is plausibly correlated with unobserved ability, which motivates the
  203. IV in example 2. The HC1 standard errors follow Stata's `vce(robust)` /
  204. `sandwich::vcovHC(type = "HC1")` convention.
  205. ### 2. IV / 2SLS: replace `ivregress 2sls` or `AER::ivreg`
  206. Question: instrument schooling with growing up near a four-year college
  207. (`nearc4`).
  208. ```python
  209. import statspai as sp
  210. card = sp.datasets.card_1995()
  211. iv = sp.ivreg(
  212. "lwage ~ (educ ~ nearc4) + exper + expersq + black + south + smsa",
  213. data=card,
  214. )
  215. print(iv.summary())
  216. ```
  217. Result:
  218. ```text
  219. Model: IV-2SLS
  220. Method: Two-Stage Least Squares
  221. Dependent Variable: lwage
  222. ...
  223. Coefficient Std. Error t-statistic P>|t| [0.025 0.975]
  224. ...
  225. educ 0.1323 0.0492 2.6870 0.0072 0.0358 0.2288
  226. Model Diagnostics:
  227. ...
  228. First-stage F (educ) : 16.7176
  229. ...
  230. Partial R² (educ) : 0.0055
  231. Hausman F-stat : 1.5390
  232. Hausman p-value : 0.2149
  233. ```
  234. The IV estimate (`0.132`) is larger than OLS but about 13 times less precise.
  235. The instrument is not strong — `nearc4` explains only 0.55% of the residual
  236. variation in schooling (first-stage F ≈ 16.7) — and the Hausman test does not
  237. reject exogeneity of `educ` (p = 0.21). Default standard errors are the
  238. unadjusted ones with the small-sample correction used by `AER::ivreg` (Stata:
  239. `ivregress 2sls ..., small`); pass `robust="hc1"` for heteroskedasticity-robust
  240. errors, and the first-stage F then uses the same variance estimator, as Stata's
  241. `estat firststage` does.
  242. With a first stage this modest, report a weak-instrument-robust interval too:
  243. ```python
  244. ar = sp.anderson_rubin_ci(
  245. y="lwage", endog="educ", instruments=["nearc4"],
  246. exog=["exper", "expersq", "black", "south", "smsa"], data=card,
  247. )
  248. print(ar.summary())
  249. ```
  250. ```text
  251. Anderson-Rubin (AR) — weak-IV-robust confidence set
  252. ------------------------------------------------------------
  253. level : 95%
  254. grid : 401 points on [-0.359, 0.624]
  255. confidence set : [0.0384, 0.2612]
  256. ```
  257. ### 3. Staggered DiD: replace `csdid` or R `did`
  258. Question: what is the average effect of minimum-wage increases on teen
  259. employment in the Callaway–Sant'Anna `mpdta` design?
  260. ```python
  261. import statspai as sp
  262. mp = sp.datasets.mpdta() # simulated replica of R did's mpdta
  263. gt = sp.callaway_santanna(
  264. data=mp,
  265. y="lemp",
  266. t="year",
  267. i="countyreal",
  268. g="first_treat",
  269. )
  270. overall = sp.aggte(gt, type="simple", bstrap=False)
  271. print(overall.summary())
  272. ```
  273. Result:
  274. ```text
  275. ==============================================================================
  276. Callaway and Sant'Anna (2021) — aggte[simple]
  277. ==============================================================================
  278. ATT: -0.0330 ***
  279. Std. Error: (0.0078)
  280. [95% CI]: [-0.0482, -0.0178]
  281. P-value: <0.001
  282. ...
  283. Observations: 2,500
  284. ...
  285. ```
  286. The aggregated ATT is about `-0.033` log points and statistically precise. The
  287. bundled `mpdta` is a calibrated simulated replica, so this is not the number R
  288. reports on the original `mpdta` data. What *is* checked: the same CSV run
  289. through R `did::att_gt()` + `aggte()` and Stata `csdid` returns the same ATT
  290. and standard error (Track A parity module `04_csdid`).
  291. ### 4. Regression discontinuity: replace `rdrobust`
  292. Question: is there a party incumbency advantage at the zero-margin cutoff in
  293. U.S. Senate elections?
  294. ```python
  295. import statspai as sp
  296. senate = sp.datasets.lee_2008_senate() # rdrobust's Senate data: x = margin, y = vote share
  297. rd = sp.rdrobust(data=senate, y="y", x="x", c=0)
  298. print(rd.summary())
  299. ```
  300. Result:
  301. ```text
  302. ==============================================================================
  303. Sharp RD Estimation
  304. ==============================================================================
  305. RD Effect: 7.51 ***
  306. Std. Error: (1.74)
  307. [95% CI]: [4.09, 10.92]
  308. P-value: <0.001
  309. ------------------------------------------------------------------------------
  310. Inference
  311. ------------------------------------------------------------------------------
  312. method estimate se z pvalue ci_lower ci_upper
  313. Conventional 7.4141 1.4587 5.0826 0.0000 4.5551 10.2732
  314. Robust 7.5065 1.7413 4.3110 0.0000 4.0937 10.9193
  315. ------------------------------------------------------------------------------
  316. Observations: 1,297
  317. ...
  318. Bandwidth H: 17.7544
  319. Bandwidth B: 28.0281
  320. ...
  321. N Effective Left: 360
  322. N Effective Right: 323
  323. ...
  324. ```
  325. The data are the extract of Cattaneo, Frandsen & Titiunik (2015,
  326. [doi:10.1515/jci-2013-0010](https://doi.org/10.1515/jci-2013-0010)) that ships
  327. with R's `rdrobust` (the loader keeps its historical name): `x` is the party's
  328. vote-share margin in the election at time t and `y` its vote share (0–100) in
  329. the election at t+2, following `rdrobust`'s own illustration. Barely winning at
  330. t raises the vote share at t+2 by about 7.4 percentage points (conventional),
  331. 7.5 with robust bias correction; the headline line reports the robust
  332. bias-corrected estimate and CI. On this data
  333. the default MSE-optimal bandwidths, estimates, and standard errors match R
  334. `rdrobust::rdrobust()` and Stata `rdrobust` (Track A parity module `06_rd`).
  335. Observations are 1,297 because 93 rows have a missing outcome.
  336. ### 5. Synthetic control: replace Stata/R `synth`
  337. Question: how did California's Proposition 99 affect cigarette sales?
  338. ```python
  339. import statspai as sp
  340. prop99 = sp.datasets.california_prop99()
  341. sc = sp.synth(
  342. data=prop99,
  343. outcome="cigsale",
  344. unit="state",
  345. time="year",
  346. treated_unit="California",
  347. treatment_time=1989,
  348. )
  349. print(sc.summary())
  350. ```
  351. Result:
  352. ```text
  353. ==============================================================================
  354. Synthetic Control Method
  355. ==============================================================================
  356. ATT: -19.5 *
  357. Std. Error: (10.8)
  358. [95% CI]: [-58.6, 19.6]
  359. P-value: 0.077
  360. ------------------------------------------------------------------------------
  361. Detailed Estimates
  362. ------------------------------------------------------------------------------
  363. unit weight
  364. Utah 0.3939
  365. Montana 0.2318
  366. Nevada 0.2049
  367. Connecticut 0.1091
  368. New Hampshire 0.0454
  369. Colorado 0.0148
  370. ...
  371. ```
  372. The estimate says California consumed about 20 fewer packs per capita per year
  373. after the intervention. The p-value is the in-space placebo rank: California's
  374. post/pre RMSPE ratio ranks 3rd of the 39 states, so p = 3/39 ≈ 0.077. This
  375. default matches on pre-treatment outcomes only; pass `covariates=` (e.g.
  376. `["lnincome", "retprice", "age15to24", "beer"]`) for an ADH-style predictor
  377. specification. That path re-solves the nested V-W problem for every placebo
  378. state and is much slower: pass `n_jobs=-1` to fit the placebos in parallel
  379. (bit-identical results), or `placebo=False` while iterating on the
  380. specification.
  381. Read this number with its caveat, which the full summary also prints:
  382. classical SCM weights are often not uniquely identified on empirical data, and
  383. different correct solvers can land on different donor weights. StatsPAI's
  384. native solver is certified on uniquely identified designs and labelled
  385. identification-dependent elsewhere. On this specification R `Synth` reaches an
  386. ATT of about `-19.59` rather than `-19.51`; pass `backend="synth"` (needs a
  387. local R with the `Synth` package; outcome-lag specification only) when you need
  388. R's exact numbers.
  389. ### 6. Logit, clustered SEs and post-estimation: Stata's `logit` + `margins`
  390. Question: in Thornton's Malawi experiment, how much did a randomly offered
  391. cash incentive raise the probability that people collected their HIV test
  392. results? Villages are the clusters.
  393. ```python
  394. import statspai as sp
  395. hiv = sp.datasets.thornton_hiv(complete_case=True)
  396. fit = sp.logit("got ~ C(any) + distvct + male + age", data=hiv,
  397. vce="cluster villnum")
  398. print(fit.summary())
  399. print(sp.margins(fit, data=hiv, variables=["any"]).round(4)) # margins, dydx(any)
  400. ```
  401. Result:
  402. ```text
  403. Model: Logit
  404. Method: Maximum Likelihood (Newton-Raphson)
  405. Dependent Variable: got
  406. ...
  407. Coefficient Std. Error z-statistic P>|z| [0.025 0.975]
  408. Intercept -0.6370 0.2010 -3.1691 0.0015 -1.0310 -0.2431
  409. C(any)[T.1.0] 2.0178 0.0994 20.3029 0.0000 1.8230 2.2126
  410. distvct -0.1696 0.0408 -4.1610 0.0000 -0.2496 -0.0897
  411. male -0.0530 0.1051 -0.5046 0.6139 -0.2590 0.1529
  412. age 0.0100 0.0034 2.9046 0.0037 0.0032 0.0167
  413. ...
  414. ```
  415. ```text
  416. variable dy/dx se z pvalue ci_lower ci_upper
  417. 0 1.any 0.45 0.0217 20.7367 0.0 0.4075 0.4926
  418. ```
  419. As in Stata, the 9 rows with a missing `age` or village id leave the
  420. estimation sample (N = 2,825, 119 villages); the 4 dropped for a missing
  421. cluster variable are reported in a `StatsPAIWarning` and in
  422. `fit.model_info["n_missing_cluster_dropped"]`.
  423. The logit coefficient is on the log-odds scale; `sp.margins` reports the effect
  424. on the probability, with a delta-method standard error. `any` is a 0/1
  425. treatment, so it enters as `C(any)` (Stata's `i.any`) and the margin is the
  426. discrete change from 0 to 1. Being offered any incentive raised the probability
  427. of collecting results by about 45 percentage points, close to the raw difference
  428. in means of 45.1 points. Without `C()` the column counts as continuous, as in
  429. Stata without `i.`, and `margins` returns the average slope (0.3558). That slope
  430. is not the effect of the offer. The coefficients, the village-clustered standard
  431. errors, and the marginal effect match Stata 18
  432. `logit got i.any distvct male age, vce(cluster villnum)` followed by
  433. `margins, dydx(any)` (0.4500223, SE 0.0217017).
  434. Tests and linear combinations use the full covariance matrix and the fit's own
  435. reference distribution (χ² / z here, F / t after OLS):
  436. ```python
  437. fit.test("distvct = 0") # chi2(1) = 17.31, p < 0.001 (Stata: test distvct)
  438. fit.lincom("1.any + male") # 1.9648, SE 0.1412 (Stata: lincom 1.any + male)
  439. ```
  440. If you already have the Stata lines, run them as they are:
  441. ```python
  442. ame = sp.stata("""
  443. logit got i.any distvct male age, vce(cluster villnum)
  444. margins, dydx(any)
  445. """, data=hiv)
  446. ```
  447. `sp.stata` returns the output of the last line — here the same marginal-effects
  448. table. A line it cannot translate faithfully (for example `xtreg, fe` without
  449. the panel id that `xtset` would have supplied) raises instead of running a
  450. different model; `sp.from_stata(line)` shows the Python call without running
  451. it.
  452. ---
  453. ## Export Results
  454. `sp.regtable()` is the single table builder behind every format. Build the table
  455. once, then write it wherever your co-authors need it:
  456. ```python
  457. import statspai as sp
  458. card = sp.datasets.card_1995()
  459. m1 = sp.regress("lwage ~ educ", data=card, robust="hc1")
  460. m2 = sp.regress("lwage ~ educ + exper + expersq", data=card, robust="hc1")
  461. m3 = sp.regress("lwage ~ educ + exper + expersq + black + south + smsa",
  462. data=card, robust="hc1")
  463. m4 = sp.ivreg("lwage ~ (educ ~ nearc4) + exper + expersq + black + south + smsa",
  464. data=card, robust="hc1")
  465. tbl = sp.regtable(
  466. m1, m2, m3, m4,
  467. model_labels=["OLS (1)", "OLS (2)", "OLS (3)", "2SLS (4)"],
  468. coef_labels={"educ": "Years of schooling", "exper": "Experience",
  469. "expersq": "Experience squared", "black": "Black",
  470. "south": "South", "smsa": "SMSA"},
  471. drop=["Intercept"],
  472. title="Returns to Schooling (Card 1995)",
  473. notes=["HC1 robust SE. Column (4) instruments schooling with nearc4."],
  474. )
  475. print(tbl) # terminal
  476. tbl.to_excel("table1.xlsx") # Excel
  477. tbl.to_word("table1.docx") # Word
  478. tbl.to_latex() # LaTeX source; also .to_markdown(), .to_html()
  479. ```
  480. <p align="center">
  481. <img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/assets/export-card-xlsx.png" alt="sp.regtable export — Card 1995 OLS + IV table" width="820">
  482. </p>
  483. <p align="center">
  484. <img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/assets/export-lalonde-xlsx.png" alt="sp.regtable export — LaLonde/NSW earnings regressions" width="720">
  485. </p>
  486. The images are the `.xlsx` files written by `tbl.to_excel()`, rendered with
  487. LibreOffice: the Card (1995) table above, and a LaLonde/NSW table regressing
  488. 1978 earnings on NSW treatment with a PSID comparison group. The LaLonde table
  489. is also a warning about observational comparisons: the treatment coefficient
  490. moves from `-635` to `+1,551` once pre-treatment earnings and demographics are
  491. controlled for. See the
  492. [export guide](docs/guides/exporting-regression-tables.md) for journal
  493. templates, standard-error formats, and single-model exports.
  494. ---
  495. ## Interactive Plot Editing
  496. If you miss Stata's Graph Editor, use `sp.interactive(fig)` on any matplotlib
  497. figure returned by StatsPAI. In Jupyter it opens an editing panel next to a
  498. live preview, so beginners can adjust a figure without learning every
  499. matplotlib option first. Requires `pip install ipywidgets`.
  500. What it is for:
  501. - change titles, labels, fonts, colors, markers, line widths, grids, legends
  502. (including entry names), axis limits, figure size, and export DPI;
  503. - recolor a series together with its error bars and confidence band, or apply
  504. a palette such as `okabe_ito` (color-blind safe) or `grayscale`;
  505. - switch among StatsPAI's publication themes (`academic`, `aea`, `minimal`,
  506. `cn_journal`) and the built-in matplotlib and seaborn styles, for this
  507. figure only;
  508. - keep the data layer locked (`protect_data=True` by default): axis limits
  509. never hide a point, error bar or band, and data cannot be made invisible;
  510. - export reproducible Python code for the edits. Tests check, pixel for
  511. pixel, that the code reproduces the edited figure and that undo restores
  512. the original;
  513. - save journal-ready PDFs with embedded TrueType fonts, and run
  514. `editor.check()` for text that is too small or series that look alike in
  515. black and white.
  516. Outside a notebook (scripts, servers, agents) pass the edits as a list:
  517. `sp.interactive(fig, actions=[{"action": "apply_theme", "theme": "aea"}])`.
  518. See the [figure editor guide](docs/guides/figure_editor.md).
  519. ```python
  520. import statspai as sp
  521. mp = sp.datasets.mpdta()
  522. gt = sp.callaway_santanna(data=mp, y="lemp", t="year",
  523. i="countyreal", g="first_treat")
  524. agg = sp.aggte(gt, type="dynamic", bstrap=False)
  525. fig, ax = sp.ggdid(agg)
  526. editor = sp.interactive(fig) # edit the plot in Jupyter
  527. print(editor.generate_code()) # copy reproducible matplotlib edits
  528. ```
  529. <p align="center">
  530. <img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/assets/StatsPAI-interactive.png" alt="StatsPAI interactive plot editor screenshot" width="820">
  531. </p>
  532. The screenshot above shows the intended workflow: preview on one side, editing
  533. controls on the other, and code export for reproducibility.
  534. ---
  535. ## Everyday Workflow
  536. ```python
  537. import statspai as sp
  538. card = sp.datasets.card_1995()
  539. r1 = sp.regress(
  540. "lwage ~ educ + exper + expersq + black + south + smsa",
  541. data=card,
  542. robust="hc1",
  543. )
  544. r2 = sp.ivreg("lwage ~ (educ ~ nearc4) + exper + expersq + black + south + smsa", data=card)
  545. print(r1.summary()) # human-readable table
  546. print(r1.tidy().head()) # broom-style dataframe
  547. print(r1.test("black = south")) # Wald test, like Stata's `test`
  548. print(r1.lincom("black - south")) # like Stata's `lincom`
  549. tbl = sp.regtable(r1, r2, model_labels=["OLS", "2SLS"])
  550. tbl.to_word("table.docx") # Word table
  551. tbl.to_excel("results.xlsx") # Excel table
  552. ```
  553. Useful docs:
  554. - [Getting started](docs/getting-started.md) and [Cookbook](docs/cookbook.md)
  555. - Choosing an estimator: [DiD](docs/guides/choosing_did_estimator.md),
  556. [IV](docs/guides/choosing_iv_estimator.md),
  557. [RD](docs/guides/choosing_rd_estimator.md),
  558. [matching](docs/guides/choosing_matching_estimator.md),
  559. [synthetic control](docs/guides/synth.md)
  560. - Migrating: [from R](docs/guides/migration-from-r.md),
  561. [Stata/R command translators](docs/guides/translator.md),
  562. [shared argument grammar](docs/guides/grammar.md)
  563. - [Exporting regression tables](docs/guides/exporting-regression-tables.md)
  564. - Agents: [agent API](docs/guides/agent_api.md),
  565. [MCP workflow for economists](docs/guides/economist_mcp_workflow.md)
  566. - Evidence: [stability and validation tiers](docs/guides/stability.md),
  567. [parity matrix](https://brycewang-stanford.github.io/StatsPAI/parity/),
  568. [tier census](docs/jss_source_audit_dossier.md)
  569. ---
  570. ## Using StatsPAI From An Agent
  571. The same registry that powers `sp.help()` is exposed three ways.
  572. **In Python** — discover functions and their schemas without reading source:
  573. ```python
  574. import statspai as sp
  575. sp.list_functions(core=True) # the ~30 everyday verbs, in order
  576. sp.list_functions(category="causal")[:5] # names
  577. sp.describe_function("rdrobust") # parameters, aliases, validation
  578. sp.function_schema("rdrobust") # JSON schema for tool calling
  579. sp.from_stata("reghdfe y x, absorb(id year) vce(cluster id)")
  580. # {'tool': 'feols', 'python_code': "sp.feols('y ~ x | id + year', data=df, cluster='id')", ...}
  581. sp.stata("regress y x, vce(cluster id)", data=df) # translate and run
  582. ```
  583. **From the shell** — `statspai list`, `statspai describe rdrobust`,
  584. `statspai search "synthetic control"`; and estimation with the same payload an
  585. MCP client gets: `statspai run callaway_santanna --data panel.csv --arg y=lemp
  586. --arg g=first_treat --arg t=year --arg i=countyreal`, or the schema-driven
  587. shortcuts `statspai did --data panel.csv --y lemp --treat treated --time year
  588. --id id`. `statspai route did --answer design=staggered` routes a question to
  589. estimators without data; `statspai mcp` starts the server.
  590. **Over MCP** — the package installs a `statspai-mcp` stdio server (pure Python,
  591. no extra dependencies). By default it lists the hand-curated estimators,
  592. workflow and pipeline tools plus three discovery meta-tools
  593. (`search_functions` → `describe_function` → `call_function`) that reach every
  594. registered function; `statspai-mcp --profile full` advertises every
  595. auto-generated tool as its own entry (several hundred, about 2 MB, more than
  596. a client context window holds; for schema dumps and debugging). Clients that
  597. connect to a URL use `statspai-mcp --transport http` (binds
  598. `127.0.0.1:8765/mcp` by default; any other address needs
  599. `STATSPAI_MCP_HTTP_TOKEN`). It also ships
  600. workflow prompts (for example `audit_did_result`, `stata_command_workflow`)
  601. and resources such as `statspai://catalog`. Tools take a `data_path` (CSV,
  602. Stata `.dta`, and other formats pandas can read) and return structured JSON
  603. with data provenance, captured runtime warnings and any unsupported
  604. arguments. For Claude Code:
  605. ```bash
  606. claude mcp add statspai -- statspai-mcp
  607. ```
  608. For Claude Desktop, Cursor, and other clients:
  609. ```json
  610. {
  611. "mcpServers": {
  612. "statspai": { "command": "statspai-mcp", "args": [] }
  613. }
  614. }
  615. ```
  616. See the [MCP workflow guide](docs/guides/economist_mcp_workflow.md) for data
  617. handoff, result handles, and the recommended detect → estimate → audit loop.
  618. **As a Claude Code skill** — `statspai skill install` copies the packaged
  619. `statspai-analysis` skill (applied-econ / epidemiology / ML-causal pipelines
  620. with paper-ready exports) into `~/.claude/skills`; `statspai skill validate`
  621. re-checks every API claim in it against the installed package, and with `--run`
  622. executes its pipelines on synthetic data. The installed skill is a copy and does
  623. not follow package upgrades: `statspai skill status` reports whether it is
  624. current, `statspai skill install --force` refreshes it. Agents using the
  625. library start at [`AGENTS.md`](AGENTS.md) and [`llms.txt`](llms.txt).
  626. ---
  627. ## Validation: What Has Been Checked, And What Has Not
  628. StatsPAI has a large API surface, so validation status matters.
  629. ```python
  630. import statspai as sp
  631. print(sp.describe_function("ivreg")["validation_status"]) # 'certified'
  632. print(sp.list_functions(validation_status="certified")[:5])
  633. ```
  634. Every registered function carries one of these tiers (counts at the last
  635. release; `sp.list_functions(validation_status=...)` gives the live numbers):
  636. | `validation_status` | Meaning | Functions |
  637. | --- | --- | ---: |
  638. | `certified` | compared with a named external reference implementation (R, Stata, or the method authors' Python package) on identical inputs, within a pre-registered tolerance | 605 |
  639. | `validated` | known-truth simulation, published-number, coverage, or documented-convention evidence, but not in the main R/Stata harness | 425 |
  640. | `api_stable` | stable public interface; unit tests exist, but **no numerical-validation claim** | 653 |
  641. | `experimental` | method or API may still change | 4 |
  642. In other words, 1,030 of the 1,687 registered functions carry numerical
  643. evidence. Breadth is not the same as validation; check the tier of the
  644. functions you depend on.
  645. The [evidence scorecard](https://brycewang-stanford.github.io/StatsPAI/scorecard/)
  646. puts the four checks a specialist makes on one page, each regenerated from
  647. committed artifacts: agreement with R / Stata on the same data, confidence
  648. interval coverage in Monte Carlo, speed against the reference on the same
  649. task, and the estimators that still have no evidence.
  650. ### Cross-language parity, made queryable
  651. The tiers above are derived from an auditable **parity index**: every verified
  652. function records what it was aligned against, to what tolerance, on which test,
  653. and how closely it matched. Each row traces to a committed test artifact (the
  654. pinned StatsPAI ↔ R ↔ Stata harness, version-locked via `renv.lock` + per-run
  655. provenance) — nothing is asserted from memory.
  656. ```python
  657. import statspai as sp
  658. s = sp.parity_status("feols")
  659. print(s)
  660. # feols: bit-exact vs fixest::feols [py/R/Stata] (headline rel_est 5.2e-15 within rel_est<=1e-06, rel_se<=1e-06)
  661. s["reference_versions"] # {'R': 'R version 4.5.2 (2025-10-31)', 'fixest': '0.14.0'}
  662. sp.parity_summary() # coverage counts, including the unverified gap
  663. sp.parity_matrix(status="bit-exact")
  664. ```
  665. Grades: `bit-exact` (headline relative error ≤ 1e-6 against a named R/Stata
  666. reference), `aligned` (a documented, pre-registered looser tolerance),
  667. `analytical-only` (recovers a known DGP truth or closed-form identity),
  668. `external-replication` (reproduces published-paper numbers), and `unverified`
  669. (registered but no parity evidence attached **yet** — the honest gap). The full,
  670. auto-generated matrix is published at
  671. [docs/parity.md](https://brycewang-stanford.github.io/StatsPAI/parity/).
  672. For your own data, `sp.cross_validate` re-runs one estimand through every
  673. independent engine installed locally and reports whether they agree:
  674. ```python
  675. card = sp.datasets.card_1995()
  676. cv = sp.cross_validate(card, "iv", y="lwage", endog=["educ"], instruments=["nearc4"],
  677. covariates=["exper", "expersq", "black", "south", "smsa"])
  678. print(cv.summary())
  679. ```
  680. ```text
  681. Engine Estimate Std.Err 95% CI status
  682. ------------------------------------------------------------------------
  683. statspai 0.13229 0.04923 [0.0358, 0.2288] ok
  684. pyfixest 0.13229 0.04923 [0.0358, 0.2288] ok
  685. linearmodels 0.13229 0.04923 [0.0358, 0.2288] ok
  686. R::fixest 0.13229 0.04923 [0.0358, 0.2288] ok
  687. ------------------------------------------------------------------------
  688. VERDICT: ✓ AGREE (4/4 engines ran)
  689. ```
  690. Engines that are not installed (pyfixest, or R with `fixest`) are skipped. Every
  691. engine is asked for the same variance estimator (including `cluster=` and
  692. `vcov=`) and the same small-sample convention, so the standard errors are
  693. compared as well as the point estimates.
  694. Beyond point-parity, a Track-B coverage study runs `B=1000` Monte Carlo
  695. replications per estimator and checks that 95% confidence intervals hit their
  696. nominal rate on known-truth DGPs, against a 99% Wilson acceptance band of
  697. `[0.935, 0.967]`. The thirteen materialized nominal rows (twelve known-truth DGPs) — OLS on an RCT (0.952),
  698. a 2×2 DiD (0.955), strong-instrument IV (0.962), Callaway–Sant'Anna staggered
  699. ATT (0.947), Sun–Abraham overall ATT (0.950), a two-way FE panel through `sp.panel` (0.948) and through `sp.fast.feols` (0.955),
  700. entropy balancing (0.945), a causal-forest AIPW ATE at 2,000 trees (0.959), DML
  701. IRM ATE (0.968), SDID with placebo SEs (0.928), sharp RD with the robust CI
  702. (0.934), and DML PLR with the default learners (0.883) — each also record bias,
  703. Monte Carlo SD and SE calibration. The SDID and RD shortfalls come with
  704. calibrated SEs (RD's intervals equal R `rdrobust`'s draw by draw); the PLR
  705. shortfall is regularisation bias of the default gradient-boosting nuisances
  706. (0.95 with the true nuisances); see `tests/coverage_monte_carlo/FINDINGS.md`. The committed artifacts live under
  707. `tests/coverage_monte_carlo/results_b1000/`.
  708. ---
  709. ## Life Cycle
  710. StatsPAI is in active development (PyPI status "Beta") and uses semantic
  711. versioning. Releases add functions and optional parameters, but a stable
  712. function is never broken without notice.
  713. The old behaviour first warns (`DeprecationWarning`, or `FutureWarning` for
  714. a changing default) for at least one minor release, and every such change
  715. is listed in [MIGRATION.md](MIGRATION.md). A fix that changes returned
  716. numbers is flagged as a correctness fix there and in the changelog. The 32
  717. core entry points (`sp.list_functions(core=True)`) have snapshot-tested
  718. signatures. A function marked `experimental` may change in any minor
  719. release and makes no numerical-validation claim; the tiers above say how
  720. far each function's numbers have been checked. The
  721. [glossary](https://brycewang-stanford.github.io/StatsPAI/guides/glossary/)
  722. defines these terms.
  723. ---
  724. ## Changelog
  725. Release notes live outside the README:
  726. - [CHANGELOG.md](CHANGELOG.md) for the full version history.
  727. - [MIGRATION.md](MIGRATION.md) for deprecations and correctness fixes that
  728. change numbers.
  729. - [Docs changelog page](https://brycewang-stanford.github.io/StatsPAI/changelog/)
  730. for the rendered documentation site.
  731. The README is intentionally focused on first-time users.
  732. ---
  733. ## Paper
  734. StatsPAI is described in a peer-reviewed paper in the *Journal of Open Source
  735. Software* (2026, 11(125), 10604): <https://doi.org/10.21105/joss.10604>.
  736. The reviewer-facing material prepared for that review remains the quickest
  737. way to audit the package:
  738. - [JOSS reviewer guide](docs/joss_reviewer_guide.md)
  739. - [JOSS validation dossier](docs/joss_validation_dossier.md)
  740. - [Design rationale and FAQ](docs/joss_reviewer_qa.md)
  741. - [Examples](examples/)
  742. - [Contributing](CONTRIBUTING.md)
  743. - [Support](SUPPORT.md)
  744. ---
  745. ## Citation
  746. If you use StatsPAI in research, cite the JOSS paper (preferred) and the
  747. underlying method papers for each estimator. `sp.citation()` returns the paper
  748. citation, `sp.citation(which="software")` the versioned software entry, and
  749. many result objects expose estimator-level citation helpers.
  750. <p align="center">
  751. <a href="https://doi.org/10.21105/joss.10604"><img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/logo/joss-paper-page.jpg" alt="The StatsPAI article page at the Journal of Open Source Software" width="720"></a>
  752. <br>
  753. <sub>The JOSS article page, published 3 September 2026</sub>
  754. </p>
  755. ```bibtex
  756. @article{wang2026statspaijoss,
  757. author = {Wang, Biaoyue and Rozelle, Scott},
  758. title = {StatsPAI: A Unified, Agent-Native Python Toolkit for
  759. Causal Inference and Applied Econometrics},
  760. journal = {Journal of Open Source Software},
  761. year = {2026},
  762. volume = {11},
  763. number = {125},
  764. pages = {10604},
  765. doi = {10.21105/joss.10604},
  766. url = {https://doi.org/10.21105/joss.10604}
  767. }
  768. @software{wang2026statspai,
  769. author = {Wang, Biaoyue and Rozelle, Scott},
  770. title = {StatsPAI: A Unified, Agent-Native Python Toolkit for
  771. Causal Inference and Applied Econometrics},
  772. year = {2026},
  773. version = {1.29.0},
  774. doi = {10.5281/zenodo.19933900},
  775. url = {https://doi.org/10.5281/zenodo.19933900},
  776. license = {MIT}
  777. }
  778. ```
  779. <p align="center">
  780. <a href="https://github.com/brycewang-stanford/StatsPAI"><img src="https://raw.githubusercontent.com/brycewang-stanford/StatsPAI/main/docs/logo/readme-footer.png" alt="StatsPAI - Agent-Native Causal Inference for Python. Scan the QR code to star the repository on GitHub" width="640"></a>
  781. </p>
  782. ---
  783. ## License
  784. MIT. See [LICENSE](LICENSE).

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.