Skip to content

Commit e59badf

Browse files
Add advanced econometrics modules: DID extensions, inference, RD, output tables, and more
New modules: decomposition (Oaxaca-Blinder), power analysis, QTE, selection (stepwise), MHT (Romano-Wolf), DGP utilities. Extended DID (CIC, imputation, multiplegt, pretrends, stacked, Wooldridge), inference (Conley, jackknife, PATE, two-way cluster), RD (honest CI, RDiT, RKD), diagnostics (estat, LATE test), matching (PS diagnostics), output (estimates, regression tables), bounds (partial identification), bartik (Adao correction), bunching (notch). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 43e811a commit e59badf

51 files changed

Lines changed: 18805 additions & 27 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# StatsPAI: The Causal Inference & Econometrics Toolkit for Python
1+
# StatsPAI: The Agent-Native Causal Inference & Econometrics Toolkit for Python
22

33
[![PyPI version](https://img.shields.io/pypi/v/StatsPAI.svg)](https://pypi.org/project/StatsPAI/)
44
[![Python versions](https://img.shields.io/pypi/pyversions/StatsPAI.svg)](https://pypi.org/project/StatsPAI/)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/brycewang-stanford/statspai/blob/main/LICENSE)
66
[![Tests](https://github.com/brycewang-stanford/statspai/workflows/CI%2FCD%20Pipeline/badge.svg)](https://github.com/brycewang-stanford/statspai/actions)
77
[![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)
88

9-
StatsPAI is a unified Python package for causal inference and applied econometrics. One `import`, 170+ functions, covering the complete empirical research workflow — from classical econometrics to cutting-edge ML/AI causal methods to publication-ready tables in Word, Excel, and LaTeX.
9+
StatsPAI is the **agent-native** Python package for causal inference and applied econometrics. One `import`, 280+ functions, covering the complete empirical research workflow — from classical econometrics to cutting-edge ML/AI causal methods to publication-ready tables in Word, Excel, and LaTeX.
10+
11+
**Designed for AI agents**: every function returns structured result objects with self-describing schemas (`list_functions()`, `describe_function()`, `function_schema()`), making StatsPAI the first econometrics toolkit purpose-built for LLM-driven research workflows — while remaining fully ergonomic for human researchers.
1012

1113
It brings R's [Causal Inference Task View](https://cran.r-project.org/web/views/CausalInference.html) (fixest, did, rdrobust, gsynth, DoubleML, MatchIt, CausalImpact, ...) and Stata's core econometrics commands into a single, consistent Python API.
1214

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "StatsPAI"
7-
version = "0.4.0"
8-
description = "The Causal Inference & Econometrics Toolkit for Python"
7+
version = "0.5.0"
8+
description = "The Agent-Native Causal Inference & Econometrics Toolkit for Python"
99
readme = "README.md"
1010
license = {text = "MIT"}
1111
authors = [

src/statspai/__init__.py

Lines changed: 125 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
>>> sp.outreg2(result, filename="results.xlsx")
2323
"""
2424

25-
__version__ = "0.4.0"
25+
__version__ = "0.5.0"
2626
__author__ = "Bryce Wang"
2727
__email__ = "bryce@copaper.ai"
2828

@@ -33,36 +33,48 @@
3333
from .did import (
3434
did, did_2x2, ddd, callaway_santanna, sun_abraham,
3535
bacon_decomposition, honest_did, breakdown_m, event_study,
36-
did_analysis, DIDAnalysis,
36+
did_analysis, DIDAnalysis, did_multiplegt, did_imputation, stacked_did, cic,
37+
wooldridge_did, drdid, twfe_decomposition,
38+
pretrends_test, pretrends_power, sensitivity_rr, SensitivityResult, pretrends_summary,
3739
parallel_trends_plot, bacon_plot, group_time_plot, did_plot,
3840
enhanced_event_study_plot, treatment_rollout_plot,
3941
sensitivity_plot, cohort_event_study_plot,
4042
)
41-
from .rd import rdrobust, rdplot, rdplotdensity, rdbwsensitivity, rdbalance, rdplacebo, rdsummary
43+
from .rd import rdrobust, rdplot, rdplotdensity, rdbwsensitivity, rdbalance, rdplacebo, rdsummary, rkd, rd_honest, rdit
4244
from .synth import (
4345
synth, SyntheticControl, synthplot, sdid, augsynth,
4446
demeaned_synth, robust_synth, gsynth, staggered_synth, conformal_synth,
4547
synthdid_estimate, sc_estimate, did_estimate,
4648
synthdid_placebo, synthdid_plot, synthdid_units_plot, synthdid_rmse_plot,
4749
california_prop99,
4850
)
49-
from .matching import match, MatchEstimator, ebalance, balanceplot, psplot
51+
from .matching import (
52+
match, MatchEstimator, ebalance, balanceplot, psplot,
53+
propensity_score, overlap_plot, trimming, love_plot,
54+
ps_balance, PSBalanceResult,
55+
)
5056
from .dml import dml, DoubleML
5157
from .deepiv import deepiv, DeepIV
5258
from .panel import panel, panel_compare, PanelResults, PanelCompareResults, PanelRegression
5359
from .causal_impact import causal_impact, CausalImpactEstimator, impactplot
5460
from .mediation import mediate, MediationAnalysis
55-
from .bartik import bartik, BartikIV
61+
from .bartik import bartik, BartikIV, ssaggregate, shift_share_se
5662
from .output.outreg2 import OutReg2, outreg2
5763
from .output.modelsummary import modelsummary, coefplot
5864
from .output.sumstats import sumstats, balance_table
5965
from .output.tab import tab
60-
from .postestimation import margins, marginsplot, test, lincom
61-
from .diagnostics import oster_bounds, mccrary_test, diagnose, het_test, reset_test, vif, sensemakr, rddensity, hausman_test, anderson_rubin_test, evalue, evalue_from_result, diagnose_result
62-
from .inference import wild_cluster_bootstrap, aipw, ri_test, ipw, bootstrap, BootstrapResult
66+
from .output.estimates import eststo, estclear, esttab
67+
from .output.regression_table import regtable, RegtableResult, mean_comparison, MeanComparisonResult
68+
from .postestimation import margins, marginsplot, margins_at, margins_at_plot, contrast, pwcompare, test, lincom
69+
from .diagnostics import oster_bounds, mccrary_test, diagnose, het_test, reset_test, vif, sensemakr, rddensity, hausman_test, anderson_rubin_test, evalue, evalue_from_result, diagnose_result, estat, kitagawa_test, KitagawaResult
70+
from .inference import wild_cluster_bootstrap, aipw, ri_test, ipw, bootstrap, BootstrapResult, twoway_cluster, conley, pate, PATEEstimator, fisher_exact, FisherResult, jackknife_se, cr2_se, wild_cluster_boot
6371
from .spatial import sar, sem, sdm, SpatialModel
6472
from .plots import binscatter, set_theme, list_themes, use_chinese, interactive, get_code
65-
from .utils import label_var, label_vars, get_label, get_labels, describe, pwcorr, winsor, read_data
73+
from .utils import (
74+
label_var, label_vars, get_label, get_labels, describe, pwcorr, winsor, read_data,
75+
dgp_did, dgp_rd, dgp_iv, dgp_rct, dgp_panel, dgp_observational,
76+
dgp_cluster_rct, dgp_bunching, dgp_synth, dgp_bartik,
77+
)
6678
from .gmm import xtabond
6779
from .metalearners import metalearner, SLearner, TLearner, XLearner, RLearner, DRLearner
6880
from .metalearners import cate_summary, cate_by_group, cate_plot, cate_group_plot, predict_cate, compare_metalearners, gate_test, blp_test
@@ -75,16 +87,21 @@
7587
from .policy_learning import policy_tree, PolicyTree, policy_value
7688
from .conformal_causal import conformal_cate, ConformalCATE
7789
from .bcf import bcf, BayesianCausalForest
78-
from .bunching import bunching, BunchingEstimator
90+
from .bunching import bunching, BunchingEstimator, notch, NotchResult
7991
from .matrix_completion import mc_panel, MCPanel
8092
from .dose_response import dose_response, DoseResponse
81-
from .bounds import lee_bounds, manski_bounds
93+
from .bounds import lee_bounds, manski_bounds, BoundsResult, horowitz_manski, iv_bounds, oster_delta, selection_bounds, breakdown_frontier
8294
from .interference import spillover, SpilloverEstimator
8395
from .dtr import g_estimation, GEstimation
8496
from .multi_treatment import multi_treatment, MultiTreatment
8597
from .robustness import spec_curve, SpecCurveResult, robustness_report, RobustnessResult, subgroup_analysis, SubgroupResult
8698
from .survey import svydesign, SurveyDesign, svymean, svytotal, svyglm
8799
from .dag import dag, DAG, dag_example, dag_examples, dag_example_positions, dag_simulate
100+
from .power import power, PowerResult, power_rct, power_did, power_rd, power_iv, power_cluster_rct, power_ols, mde
101+
from .decomposition import oaxaca, gelbach, OaxacaResult, GelbachResult
102+
from .selection import stepwise, lasso_select, SelectionResult
103+
from .qte import qdid, qte, QTEResult
104+
from .mht import romano_wolf, RomanoWolfResult, adjust_pvalues, bonferroni, holm, benjamini_hochberg
88105
from .registry import list_functions, describe_function, function_schema, search_functions, all_schemas
89106

90107
__all__ = [
@@ -108,6 +125,15 @@
108125
"event_study",
109126
"did_analysis",
110127
"DIDAnalysis",
128+
"did_multiplegt",
129+
"did_imputation",
130+
"stacked_did",
131+
"cic",
132+
"pretrends_test",
133+
"pretrends_power",
134+
"sensitivity_rr",
135+
"SensitivityResult",
136+
"pretrends_summary",
111137
"parallel_trends_plot",
112138
"bacon_plot",
113139
"group_time_plot",
@@ -116,6 +142,10 @@
116142
"treatment_rollout_plot",
117143
"sensitivity_plot",
118144
"cohort_event_study_plot",
145+
# Wooldridge / DR-DID / TWFE Decomposition
146+
"wooldridge_did",
147+
"drdid",
148+
"twfe_decomposition",
119149
# RD
120150
"rdrobust",
121151
"rdplot",
@@ -124,6 +154,9 @@
124154
"rdbalance",
125155
"rdplacebo",
126156
"rdsummary",
157+
"rkd",
158+
"rd_honest",
159+
"rdit",
127160
# Synthetic Control
128161
"synth",
129162
"SyntheticControl",
@@ -148,6 +181,13 @@
148181
"ebalance",
149182
"balanceplot",
150183
"psplot",
184+
# PS Diagnostics
185+
"propensity_score",
186+
"overlap_plot",
187+
"trimming",
188+
"love_plot",
189+
"ps_balance",
190+
"PSBalanceResult",
151191
# Double ML
152192
"dml",
153193
"DoubleML",
@@ -174,6 +214,13 @@
174214
"sumstats",
175215
"balance_table",
176216
"tab",
217+
"eststo",
218+
"estclear",
219+
"esttab",
220+
"regtable",
221+
"RegtableResult",
222+
"mean_comparison",
223+
"MeanComparisonResult",
177224
# Plots
178225
"binscatter",
179226
"set_theme",
@@ -199,6 +246,10 @@
199246
# Post-estimation
200247
"margins",
201248
"marginsplot",
249+
"margins_at",
250+
"margins_at_plot",
251+
"contrast",
252+
"pwcompare",
202253
"test",
203254
"lincom",
204255
# Mediation
@@ -207,6 +258,8 @@
207258
# Bartik IV
208259
"bartik",
209260
"BartikIV",
261+
"ssaggregate",
262+
"shift_share_se",
210263
# Diagnostics
211264
"oster_bounds",
212265
"mccrary_test",
@@ -221,13 +274,25 @@
221274
"evalue",
222275
"evalue_from_result",
223276
"diagnose_result",
277+
"estat",
278+
"kitagawa_test",
279+
"KitagawaResult",
224280
# Inference
225281
"wild_cluster_bootstrap",
226282
"aipw",
227283
"ri_test",
228284
"ipw",
229285
"bootstrap",
230286
"BootstrapResult",
287+
"twoway_cluster",
288+
"conley",
289+
"pate",
290+
"PATEEstimator",
291+
"fisher_exact",
292+
"FisherResult",
293+
"jackknife_se",
294+
"cr2_se",
295+
"wild_cluster_boot",
231296
# Spatial Econometrics
232297
"sar",
233298
"sem",
@@ -279,6 +344,8 @@
279344
# Bunching
280345
"bunching",
281346
"BunchingEstimator",
347+
"notch",
348+
"NotchResult",
282349
# Matrix Completion
283350
"mc_panel",
284351
"MCPanel",
@@ -288,6 +355,12 @@
288355
# Bounds
289356
"lee_bounds",
290357
"manski_bounds",
358+
"BoundsResult",
359+
"horowitz_manski",
360+
"iv_bounds",
361+
"oster_delta",
362+
"selection_bounds",
363+
"breakdown_frontier",
291364
# Interference
292365
"spillover",
293366
"SpilloverEstimator",
@@ -317,10 +390,51 @@
317390
"dag_examples",
318391
"dag_example_positions",
319392
"dag_simulate",
393+
# Power Analysis
394+
"power",
395+
"PowerResult",
396+
"power_rct",
397+
"power_did",
398+
"power_rd",
399+
"power_iv",
400+
"power_cluster_rct",
401+
"power_ols",
402+
"mde",
403+
# Decomposition
404+
"oaxaca",
405+
"gelbach",
406+
"OaxacaResult",
407+
"GelbachResult",
408+
# Variable Selection
409+
"stepwise",
410+
"lasso_select",
411+
"SelectionResult",
412+
# Quantile Treatment Effects
413+
"qdid",
414+
"qte",
415+
"QTEResult",
416+
# Multiple Hypothesis Testing
417+
"romano_wolf",
418+
"RomanoWolfResult",
419+
"adjust_pvalues",
420+
"bonferroni",
421+
"holm",
422+
"benjamini_hochberg",
320423
# AI / Agent Registry
321424
"list_functions",
322425
"describe_function",
323426
"function_schema",
324427
"search_functions",
325428
"all_schemas",
429+
# Data Generating Processes
430+
"dgp_did",
431+
"dgp_rd",
432+
"dgp_iv",
433+
"dgp_rct",
434+
"dgp_panel",
435+
"dgp_observational",
436+
"dgp_cluster_rct",
437+
"dgp_bunching",
438+
"dgp_synth",
439+
"dgp_bartik",
326440
]

src/statspai/bartik/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"""
1818

1919
from .shift_share import bartik, BartikIV
20+
from .adao_correction import ssaggregate, shift_share_se
2021

21-
__all__ = ['bartik', 'BartikIV']
22+
__all__ = ['bartik', 'BartikIV', 'ssaggregate', 'shift_share_se']

0 commit comments

Comments
 (0)