Skip to main content

Empirical economics and causal inference in Python - a scikit-learn-style unified API with Stata/R-grade numerical parity.

Project description

open-econs

PyPI version Python versions CI License: MIT Downloads

open-econs is a Python library for empirical economics and causal inference that reproduces Stata and R results to a verified numerical tolerance — built for researchers migrating off Stata/R and for Python users who need causal inference, it is the econometrics toolkit a Stata/R researcher would reach for, but native in Python.

Unlike statsmodels, linearmodels, or fixest, open-econs is validated against Stata and R across the whole causal-inference stack: 550+ parity tests (330+ vs Stata, 220+ vs R) run in CI on every release, and a numerical mismatch fails the build before it ships. New methods are checked to ≤1e-6; IV, Arellano-Bond, and synthetic control reproduce reference results to machine precision.

It covers 40+ estimators in one consistent API: OLS, fixed effects, IV/2SLS, GMM & Arellano-Bond, logit/probit/mlogit, Oaxaca-Blinder, nonlinear least squares, the full difference-in-differences family (Callaway-Sant'Anna, Sun-Abraham, Gardner DID2S, event studies), regression discontinuity, propensity-score & coarsened-exact matching, synthetic control with permutation inference, and a time-series module (ARIMA, VAR/VECM, GARCH, ARDL/UECM with the Pesaran-Shin-Smith bounds test, unit-root & cointegration).

Install

pip install open-econs                      # core estimators
pip install open-econs[plot]                # + matplotlib for .plot()
pip install open-econs[nls]                 # + sympy for nls()
pip install open-econs[dev,lint]            # + development & linting tools

Requires Python ≥ 3.10.

Quick start

import open_econs as oe
import pandas as pd

df = pd.DataFrame({
    "income":    [30, 45, 55, 70, 85, 40, 60, 95],
    "education": [10, 12, 14, 16, 18, 11, 15, 20],
    "age":       [25, 30, 35, 40, 45, 28, 38, 50],
    "female":    [0,  0,  0,  0,  1,  1,  1,  1],
    "province":  ["A","A","B","B","C","C","A","B"],
})

r = oe.ols("income ~ education + age", data=df, cluster="province")
print(r.tidy())        # coefficient table (named pd.DataFrame)
print(r.summary())     # full OLS results

# Causal estimators use the same API:
oe.did_cs("y ~ x1 + x2 | group + time", data=panel_df)   # Callaway-Sant'Anna DiD
oe.psm("treat ~ x1 + x2", data=df)                        # propensity-score matching
oe.synth(...)                                            # synthetic control

Every result returns named pd.Series / pd.DataFrame outputs and exports to JSON, CSV, LaTeX, or HTML with one call — .export(), .to_latex(), .to_html(). Results are immutable after estimation.

Stata / R → open-econs (top mappings)

Stata / R open-econs
regress (Stata) oe.ols()
xtreg, fe (Stata) oe.fe()
ivregress 2sls / AER::ivreg oe.iv()
xtabond2 (Stata) oe.abond()
csdid (Stata) / did (R) oe.did_cs()
eventstudyinteract (Stata) / fixest::sunab (R) oe.did_sa()
did2s (Stata) / fixest::did2s (R) oe.did_gardner()
rdrobust (Stata) oe.rdd()
teffects psmatch (Stata) / MatchIt (R) oe.psm()
synth_runner (Stata) / synth (R) oe.synth() / oe.placebo_space() / oe.placebo_time()

Full mapping: docs/stata-r-mapping.md. Migration guides: Stata / R.

Performance

v1.0.3 hardens hot loops with bit-identical vectorization/parallelization — no parity tolerance loosened: psm is ~4× faster (k-NN + variance loops batched), _hac_S Newey-West accumulation is a single einsum, and did_cs bootstrap runs through an opt-in parallel= pool. GPU offload was evaluated and deliberately declined (BLAS is already CPU-threaded). Full detail: docs/performance.md.

Compare

open-econs is the only Python library covering the full causal-inference stack and enforcing Stata/R parity. The side-by-side matrix against statsmodels, linearmodels, and fixest is here: docs/comparison.md.

Documentation

Development

pip install -e ".[dev]"
python -m pytest tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open_econs-1.4.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

open_econs-1.4.1-py3-none-any.whl (264.4 kB view details)

Uploaded Python 3

File details

Details for the file open_econs-1.4.1.tar.gz.

File metadata

  • Download URL: open_econs-1.4.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for open_econs-1.4.1.tar.gz
Algorithm Hash digest
SHA256 cc3175d0a1fe72bad366d4e22c3a73f278bb5865e7760000dc0172e6cc5d505b
MD5 8a6d677258fa9d99ed4a81e80b6435b0
BLAKE2b-256 356796c566de786c06686a32c75b6fd4a49643e51678d0f826182bb2eb58f9aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_econs-1.4.1.tar.gz:

Publisher: publish.yml on qmanhbeo/open-econs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file open_econs-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: open_econs-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 264.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for open_econs-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce826f3961efe4d9fe76f56ccbf2d34582ae370948e2c546baf4829a6f8d9548
MD5 faa20f32339d81010bafddb34beac10d
BLAKE2b-256 ab7f31f3a0f0318cde63e8f5430038bd8b0195dbaa34a1ead5c8355c7faf6f9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_econs-1.4.1-py3-none-any.whl:

Publisher: publish.yml on qmanhbeo/open-econs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page