StataFlow
A Python econometrics toolkit designed to reproduce Stata 17 estimation results with field-level validation.
from stataflow.compat.stata import reghdfe
result = reghdfe(
df,
y="lwage",
x=["exper", "edu"],
absorb="firm_id year_id",
vce="cluster",
cluster="firm_id",
)
result.display()
Why StataFlow
StataFlow is for researchers who want Python workflows without giving up the empirical conventions they rely on in Stata. The project is not a generic statistics library: public capabilities are validated against Stata 17 with synthetic cases, public real-data cases, and Stata/Python dual-run evidence where Stata is available.
The current public line is 1.1.0 Stable, with an additional v1.2.0+ correctness-hardening release-candidate sync prepared on July 9, 2026.
Features
- 14 Stata-style commands in Python:
regress,xtreg_fe,areg,reghdfe,ivregress_2sls,ivreghdfe,logit,probit,poisson,ppmlhdfe,did_imputation,eventstudyinteract,csdid, andrdrobust. - Two API layers: a Stata-compatible command layer (
stataflow.compat.stata) and a Python-native estimator layer (stataflow.estimators). - Stata-style output:
result.display()prints compact regression tables with coefficients, standard errors, test statistics, p-values, and fit statistics. - High-dimensional fixed effects: MAP absorption for large FE designs, multi-FE workflows, singleton handling, individual slopes, and cluster-aware VCE paths.
- Instrumental variables: 2SLS, GMM2S, LIML, Fuller/k-class, first-stage diagnostics, weak-instrument tests, and overidentification tests.
- Binary, count, and PPML models: Logit, Probit, Poisson, and PPML-HDFE with robust and clustered covariance estimators.
- Causal inference: BJS DID imputation, Sun-Abraham event-study interactions, Callaway-Sant'Anna DID, and sharp/fuzzy regression discontinuity.
- Stata-compatible syntax subsets: factor variables, analytic weights, multiple fixed effects, common VCE choices, and hard rejection of unsupported parameters.
- Validation-first development: public commands are backed by field-level Stata 17 comparison evidence.
Installation
pip install StataFlow
Python 3.10, 3.11, or 3.12 is required. Core dependencies are NumPy, pandas, SciPy, scikit-learn, and PyYAML.
Quick Start
Stata-Compatible API
from stataflow.compat.stata import regress, reghdfe, logit, ivregress_2sls, ppmlhdfe
# OLS with robust standard errors
result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
result.display()
# High-dimensional fixed effects
result = reghdfe(
df,
y="wage",
x=["edu", "exper"],
absorb="firm_id year_id",
vce="cluster",
cluster="industry",
)
# Logit
result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
result.display()
# 2SLS with robust VCE
result = ivregress_2sls(
df,
y="lwage",
x_exog=["educ"],
x_endog=["exper"],
instruments=["age", "kidslt6"],
vce="robust",
)
# PPML with high-dimensional fixed effects
result = ppmlhdfe(
df,
y="trade",
x=["lndist", "contig", "fta"],
absorb=["exporter", "importer", "year"],
vce="cluster",
cluster="exporter",
)
Native Python API
from stataflow import OLS, AbsorbingOLS, Logit
model = OLS(data=df, y="wage", x=["edu", "exper"])
result = model.fit(vce="robust")
result.display()
Programmatic Results
result.display(show_ci=True)
for coef in result.coefficients:
print(f"{coef.name}: b={coef.beta:.6f}, se={coef.std_err:.6f}, t={coef.t_stat:.2f}")
print(f"R2 = {result.fit.r2:.4f}, N = {result.sample.nobs}")
Supported Models
| Family | Available via | Estimators and VCE |
|---|---|---|
| Linear | regress, areg, xtreg_fe, reghdfe |
OLS with ols, robust (HC1), cluster (1-way, 2-way where supported), and dkraay panel HAC |
| IV | ivregress_2sls, ivreghdfe |
2SLS, GMM2S, LIML, Fuller/k-class, first-stage diagnostics, weak-IV tests |
| Binary / Count | logit, probit, poisson |
MLE with ols, robust, and cluster VCE |
| PPML + HDFE | ppmlhdfe |
IRLS with fixed effects, offset/exposure, separation checks, eform, and common prediction types |
| DID | did_imputation, csdid, eventstudyinteract |
BJS imputation, Callaway-Sant'Anna, and Sun-Abraham IW estimators |
| RD | rdrobust |
Sharp/fuzzy RD, MSE/CER bandwidth selectors, covariates, weights, mass points, and cluster/nncluster VCE |
See Open-Source Status and Known Issues for exact support boundaries.
Validation
Recent local release-candidate checks (July 9, 2026):
- Public unit/integration suite:
405 passed - Internal modular audit suite:
95 passed - Golden dual-run collection guard:
839 tests collected - Example smoke scripts: all four public demos passed
- Wheel build:
stataflow-1.1.0-py3-none-any.whlbuilt successfully - Open-source export dry-run: 150 files selected, 0 orphan removals
Golden Stata dual-run tests require a local Stata 17 installation and are not part of the public CI gate.
Documentation
Running Tests
# Unit and integration tests
pytest tests/ -v --ignore=tests/golden/ --ignore=tests/audit_v1_3
# Golden dual-run tests (require local Stata 17)
pytest tests/golden/ -v
License
This project is licensed under the MIT License. See LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stataflow-1.1.0.tar.gz.
File metadata
- Download URL: stataflow-1.1.0.tar.gz
- Upload date:
- Size: 168.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df3188563a88b05585faeafcf803ce7eac65e37712ac9614dc1fdcdddd96cc87
|
|
| MD5 |
d6e08fe141ca3b5433000f45505af528
|
|
| BLAKE2b-256 |
2761d5a520ba1f9e4d9f806b885bf05b370d8a21cc408780d2be28a423aa0be9
|
File details
Details for the file stataflow-1.1.0-py3-none-any.whl.
File metadata
- Download URL: stataflow-1.1.0-py3-none-any.whl
- Upload date:
- Size: 145.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b1cf2b6ca898b7b5b0eb4183da166bd4dd7d784746ee70d68a6741c0f4f6ee0
|
|
| MD5 |
f0ccaf3834441c94c9d7408a4016655c
|
|
| BLAKE2b-256 |
ba07da5b92bb10d3061dbab51ddf1eac3e20899ef905fc59ca55d1bcd0ccd840
|