RepositoryPythonCNChina
ZhenHaoFu810

ZhenHaoFu810/StataFlow

Stata-aligned econometrics for Python, with field-level validation across the documented support surface.

171stars
2forks
0issues
3views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: difference-in-differences

#1 Repository of the week

1
TINIX TRENDING·Topic: stata

#1 Repository of the week

1
TINIX TRENDING·Topic: fixed-effects

#1 Repository of the week

StataFlow

Stata-aligned econometrics for Python, with field-level validation across the documented support surface.

简体中文

CI PyPI version Downloads Python versions License Typing Stata validation

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.0, 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, and rdrobust. The exported rdplot companion 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

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()

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

FamilyAvailable viaEstimators and VCE
Linearregress, areg, xtreg_fe, reghdfeOLS with ols, robust (HC1), and command-specific clustering; reghdfe also supports dkraay panel HAC
IVivregress_2sls, ivreghdfe2SLS, GMM2S, LIML, Fuller/k-class, first-stage diagnostics, weak-IV tests
Binary / Countlogit, probit, poissonMLE with ols, robust, and cluster VCE
PPML + HDFEppmlhdfeIRLS with fixed effects, offset/exposure, separation checks, eform, and common prediction types
DIDdid_imputation, csdid, eventstudyinteractBJS imputation, Callaway-Sant'Anna, and Sun-Abraham IW estimators
RDrdrobustSharp/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).

FamilyCovered commandsStata 17 comparisonsMax coefficient deviationMax SE deviation
Linear / FEregress, areg, xtreg_fe, reghdfe18/182.48e-72.25e-7
IVivregress_2sls, ivreghdfe5/51.16e-83.74e-8
Binary / countlogit, probit, poisson, ppmlhdfe12/121.33e-78.42e-8
DIDdid_imputation, csdid, eventstudyinteract2/2 + 1 functional check8.13e-85.13e-8
RDrdrobust3/39.23e-82.96e-8
Total14 public estimation commands40/402.48e-72.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

Running Tests

# Unit and integration tests
pytest tests/ -v

# Reproducible Stata validation cases (require local Stata 17)
pytest tests/stata_validation/ -v -s

Community

License

This project is licensed under the MIT License. See LICENSE for details.

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
igerber/diff-diff

Difference-in-Differences causal inference in Python. Callaway-Sant'Anna, Synthetic DiD, Honest DiD, event studies. sklearn-like API, validated against R.

417
Dec 1, 2026
RepositoryPython
brycewang-stanford/StatsPAI

StatsPAI is an 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.

392
Nov 30, 2026
RepositoryR
RobsonTigre/everyday-ci

R & Python code and datasets for Everyday Causal Inference — a free book on experiments, DiD, IV, RDD, and causal time series for business

147
Oct 18, 2026
RepositoryPython
py-econometrics/pyfixest

Fast High-Dimensional Fixed Effects Regression in Python following fixest-syntax

371
Dec 2, 2026
RepositoryPython
bernardodionisi/differences

difference-in-differences in Python

116
Apr 12, 2026
RepositoryC++
tensorflow/tensorflow

An Open Source Machine Learning Framework for Everyone

201.9k
Dec 1, 2026
RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026
RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
RepositoryPython
TheAlgorithms/Python

All Algorithms implemented in Python

226.6k
Nov 13, 2026