Overview
StatsPAI is a Python package from Stanford's REAP project, aiming to consolidate fragmented causal-inference tooling (Stata's proprietary environment, R's 20+ incompatible packages, Python's gap on DID/RD/DML) into one import. At v1.16.0 it ships 1,000+ registered functions across 23 method families, 310k lines of core code, and 156k lines of tests.
Key points
- Agent-first interface layer: Every function exposes machine-readable metadata via
sp.list_functions(),sp.describe_function(), andsp.function_schema()(OpenAI/Anthropic tool-calling format). A bundled MCP server scaffold (sp.agent.mcp_server) lets external LLMs invoke registered functions in natural language. The library treats agents as first-class users rather than retrofitting a human-oriented API. - Validation-tiered honesty: Each function carries a
validation_statusflag (certified,validated,api_stable,experimental). Thextabond(Arellano-Bond dynamic panel GMM) estimator was rewritten to achieve machine-precision parity with Stata before being promoted tocertified. - Unified
CausalResultobject: All estimators return the same object with.summary(),.plot(),.to_latex(),.to_word(),.to_excel(), and.cite()methods. Thesp.regtablehelper merges results across DID, IV, RD, and DML into journal-styled tables (AER/QJE/Econometrica templates) in a single line. - Honest cross-tool comparison: The README concedes where Stata (40+ years of production validation,
svy:survey support, reviewer trust) and R (frontier-method first-movers such asfixest,did2s,HonestDiD, plus ggplot2 and CRAN peer review) still lead. - Causal "full stack" coverage: Classical econometrics (DID variants, 2SLS/LIML/GMM, CCT/robust RD, ADH/ASCM/gsynth/SDID, PSM/CEM/entropy balancing), ML causal (DML, GRF causal forests, S/T/X/R/DR meta-learners, TMLE, DeepIV), neural causal (TARNet, CFRNet, DragonNet), and frontier methods (NOTEARS/PC/LiNGAM discovery, conformal causal inference, Mendelian randomization, Bayesian causal forests, policy learning). Each family ships with a method-selection decision tree, assumption checklist, and diagnostic flow rather than bare API docs.
- Publication-grade output pipeline:
sp.regtablereplaces multi-step LaTeX formatting with.to_word()/.to_excel()/.to_latex(); handles mixed-magnitude formatting and automatic asterisk annotations. - Estimand-first workflow DSL:
sp.causal_question(...)forces researchers to declare treatment, outcome, population, estimand, and design before estimation. The returnedIdentificationPlancan be frozen into a pre-registration markdown file viaplan.to_markdown(). - Automated robustness "interrogation":
sp.spec_curve()explores the full grid of control sets × subsamples × standard-error types;sp.oster_bounds()computes Oster (2019) selection bounds;sp.sensitivity_dashboard()summarizes every check on a single page. - Certified coverage is still a minority of the 1,000+ functions; most sit at
api_stableorvalidated. - Compared to Stata's 40+ years of production hardening, edge-case handling and large-sample performance are unproven.
- Schema exposure does not eliminate LLM hallucination risk on method choice or assumption interpretation;
sp.causal_questionmitigates but does not replace human judgment on complex designs. - R remains the first-mover for frontier econometric methods, so StatsPAI must continuously track upstream packages to avoid a perpetual catch-up posture.
- GitHub: https://github.com/brycewang-stanford/statspai
- PyPI: https://pypi.org/project/StatsPAI/
Limitations
Takeaway
StatsPAI's strategic contribution is not any single estimator but its architectural bet: schema layers as system calls, validation tiers as a certification regime, and the unified CausalResult object as a data-exchange format. If certified coverage expands and adoption grows inside the LLM-agent ecosystem, it could become the default causal-inference standard library for Python + AI-agent settings rather than a replacement for Stata or R.