Skip to main content

pymte

PyPI DOI CI

Instrumental variables and marginal treatment effects in Python.

Documentation: https://pymte.readthedocs.io

pymte estimates treatment parameters such as the ATE, ATT or a policy relevant treatment effect from instrumental variables data, using the marginal treatment effect (MTE) framework of Heckman and Vytlacil (2005) and the moment-based implementation of Mogstad, Santos and Torgovitsky (2018). The user specifies parametric or nonparametric (spline) marginal treatment response functions, optional shape restrictions such as boundedness or monotonicity, and a set of IV-like estimands. The package returns either a point estimate (when the model is point identified) or sharp bounds obtained by linear or quadratically constrained programming, together with bootstrap confidence intervals and specification tests.

This package is a port of the R package ivmte by Joshua Shea and Alexander Torgovitsky, released under the GPL-3. It reproduces the R package's estimands, options and numerical results; the API follows Python conventions.

Installation

pip install pymte

Linear programs are solved with HiGHS (through SciPy) and quadratically constrained programs with Clarabel (through CVXPY); both are installed automatically. MOSEK and Gurobi can be used instead when licensed:

pip install "pymte[mosek]"
pip install "pymte[gurobi]"
pip install "pymte[plots]"   # matplotlib for plot_mtr, plot_mte, plot_weights

Quick start

import pymte

ae = pymte.load_ae()
r = pymte.ivmte(
    ae,
    target="att",
    m0="~ u + yob",
    m1="~ u + yob",
    ivlike="worked ~ morekids + samesex + morekids*samesex",
    propensity="morekids ~ samesex + yob",
)
print(r)
Bounds on the target parameter: [-0.1028836, -0.07818869]
Audit terminated successfully after 1 round(s)
MTR coefficients: 6
Independent/total moments: 4/4
Minimum criterion: 0
Solver: highs

Add bootstraps=50 for confidence regions, point=True for GMM when the model is point identified, or replace ivlike with outcome="worked" for the regression approach.

The full user guide, a theory primer and the API reference are on Read the Docs.

Contributing

pymte is a new project. If you find a bug, want a feature, see a way to make something faster, or have an application that the package does not yet cover, open an issue or a pull request on GitHub. Small fixes, new examples, and documentation improvements are as welcome as new estimators. If you would prefer to talk first, or want to discuss a larger piece of work, email me at alex.ronczewski@gmail.com.

Citing

If you use this package, please cite the papers that developed the methodology:

  • Mogstad, M., A. Santos and A. Torgovitsky (2018). Using Instrumental Variables for Inference About Policy Relevant Treatment Parameters. Econometrica 86(5), 1589-1619. doi:10.3982/ECTA15463.
  • Shea, J. and A. Torgovitsky (2023). ivmte: An R Package for Extrapolating Instrumental Variable Estimates Away From Compliers. Observational Studies 9(2), 1-42.
  • Heckman, J. J. and E. Vytlacil (2005). Structural Equations, Treatment Effects, and Econometric Policy Evaluation. Econometrica 73(3), 669-738.
  • Mogstad, M. and A. Torgovitsky (2018). Identification and Extrapolation of Causal Effects with Instrumental Variables. Annual Review of Economics 10, 577-613.

BibTeX entries are in the documentation under "Citing". The AE dataset is derived from Angrist and Evans (1998), American Economic Review 88(3).

Licence

GPL-3.0-only. This package is a derivative work of the R package ivmte, Copyright (C) 2018-2024 Joshua Shea and Alexander Torgovitsky, which its authors distribute under GPL-2 or GPL-3; this port takes it under version 3 and is distributed under the same version. See LICENSE for the licence text and NOTICE for the copyright notices.

Download files

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

Source Distribution

pymte-1.0.1.tar.gz (658.1 kB view details)

Uploaded Source

Built Distribution

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

pymte-1.0.1-py3-none-any.whl (521.5 kB view details)

Uploaded Python 3

File details

Details for the file pymte-1.0.1.tar.gz.

File metadata

  • Download URL: pymte-1.0.1.tar.gz
  • Upload date:
  • Size: 658.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pymte-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a2a73249951ba88c0ba9c21eba0e2869ba6687c2eaea12207ab253df8807fae5
MD5 037ef4b7285ab6152e8feaedab1604d9
BLAKE2b-256 956cabd8eda009382a28d8fdb15d71a777c6336d1c15b0a1003f5d6649342feb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymte-1.0.1.tar.gz:

Publisher: release.yml on Alexr951/pymte

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

File details

Details for the file pymte-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pymte-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 521.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pymte-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 018e57eea205ff8ed0b839a719ee29031b65220f1a25ca7dad37de3c17f1df64
MD5 11251bfc18fccd44e9e1ec2e7129cd7e
BLAKE2b-256 60b796e2e72f227d7c4978d71cc67d9d3eb6c7e52eda5970756c72b2a29cdd53

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymte-1.0.1-py3-none-any.whl:

Publisher: release.yml on Alexr951/pymte

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

Release history Release notifications | RSS feed

1.0.2

2 files

This release

1.0.1 This release

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page