StataFlow
Stata-aligned econometrics for Python, with field-level validation across the documented support surface.
Installation · Quick Start · Validation · Documentation · Contributing
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 have Stata validation across the documented support surface, backed by synthetic cases, public real-data cases, and field-level comparisons.
The latest release is 1.3.1, covering 14 Stata-style commands.
Features
- 14 estimation commands in Python:
regress,xtreg_fe,areg,reghdfe,ivregress_2sls,ivreghdfe,logit,probit,poisson,ppmlhdfe,did_imputation,eventstudyinteract,csdid, andrdrobust. The exportedrdplotcompanion is a helper and is not counted as an estimation command. - Two API layers: a Stata-compatible command layer (
stataflow.compat.stata) and a Python-native estimator layer (stataflow.estimators). - Command-aware Stata-style output:
result.display()prints a complete, adaptive result table with the statistics and diagnostics relevant to each command; notebooks receive the same content as escaped HTML. - 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, command-specific analytic-weight support, multiple fixed effects, common VCE choices, and hard rejection of unsupported parameters.
- Validation-first development: public commands have field-level Stata validation across the documented support surface.
Installation
pip install StataFlow
StataFlow requires Python 3.10 or later. The current release is tested on Python 3.10-3.14. 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()
Working with Results
result.display() # Full output with 95% CI
result.display(detail="compact") # Header, coefficients, core fit
result.display(show_ci=False) # Hide confidence intervals
text = result.summary(width=100) # Return the same table as text
html = result.to_html() # Escaped HTML for reports/notebooks
Supported Models
| Family | Available via | Estimators and VCE |
|---|---|---|
| Linear | regress, areg, xtreg_fe, reghdfe |
OLS with ols, robust (HC1), and command-specific clustering; reghdfe also supports 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 the Command Support Matrix and Known Issues for exact support boundaries.
Validation
The July 2026 table is the 1.2.0 estimator-validation snapshot retained for
1.3.0; the actual comparison environment was Stata 17.
The retained snapshot covers the coefficient and standard-error comparisons reported below.
It does not cover result statistics first added in 1.3.0.
Relative deviation is |Python - Stata| / max(|Stata|, 1e-15).
| Family | Covered commands | Stata 17 comparisons | Max coefficient deviation | Max SE deviation |
|---|---|---|---|---|
| Linear / FE | regress, areg, xtreg_fe, reghdfe |
18/18 | 2.48e-7 | 2.25e-7 |
| IV | ivregress_2sls, ivreghdfe |
5/5 | 1.16e-8 | 3.74e-8 |
| Binary / count | logit, probit, poisson, ppmlhdfe |
12/12 | 1.33e-7 | 8.42e-8 |
| DID | did_imputation, csdid, eventstudyinteract |
2/2 + 1 functional check | 8.13e-8 | 5.13e-8 |
| RD | rdrobust |
3/3 | 9.23e-8 | 2.96e-8 |
| Total | 14 public estimation commands | 40/40 | 2.48e-7 | 2.25e-7 |
Full local Stata validation checks: 856 passed, 12 skipped. The public,
self-contained suite passes 10/10 reproducible validation cases with Stata
17. The values above are stored in
evidence-summary.json.
Documentation
- User Guide (中文)
- Cookbook (中文)
- Examples — nine deterministic demo scripts covering all 14 public commands; no network or local Stata required
- Validation Evidence (JSON)
- Validation Evidence (readable)
- Changelog
Running Tests
# Unit and integration tests
pytest tests/ -v
# Reproducible Stata validation cases (require local Stata 17)
pytest tests/stata_validation/ -v -s
Community
- Contributing Guide — development workflow, testing requirements, and PR checks
- Security Policy — supported versions and private vulnerability reporting
- Code of Conduct
License
This project is licensed under the MIT License. See LICENSE for details.
Metadata
Release files for StataFlow 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stataflow-1.3.1.tar.gz | 193.0 kB | Without provenance | Details for stataflow-1.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stataflow-1.3.1-py3-none-any.whl | Python 3 | none | any | Details for stataflow-1.3.1-py3-none-any.whl |
Total release size: 354.6 kB
Release files / stataflow-1.3.1.tar.gz
| Download URL | stataflow-1.3.1.tar.gz |
|---|---|
| Size | 193.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9dd8529cf543c686b005ed960120f6c61c1cca32789e7d660fa6a7eb22ba5d8
|
|
BLAKE2b-256 checksum How to use checksums |
c5bbffa0f84a89f92b406f9cf07c96035122409f43f1eab3ab3148d06c210b87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|
Release files / stataflow-1.3.1-py3-none-any.whl
| Download URL | stataflow-1.3.1-py3-none-any.whl |
|---|---|
| Size | 161.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4be8f3eddf592b049ebf555b187d9551d73e7f50fd9d2c08e2a201fa5eee9cf
|
|
BLAKE2b-256 checksum How to use checksums |
55ca1f12c235cebf51ef8431363a8a941e33e44316089ee93b38d86a9dfd2d2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|
Security for StataFlow 1.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.