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.2.tar.gz (659.0 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.2-py3-none-any.whl (521.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymte-1.0.2.tar.gz
  • Upload date:
  • Size: 659.0 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.2.tar.gz
Algorithm Hash digest
SHA256 d29d9b664f1c1a1dbed8c8b6ae577efd975bd2073c499111245a55a9b09030e0
MD5 4515cbc216589e38ce92ed0c0a8e5526
BLAKE2b-256 11c0d2ab0fc367b8a11ce8b795a2d3717b3c16e2a49f008a1c6becc498ec966b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymte-1.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: pymte-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 521.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 98f11ec4852eafd03614f1e7686d65afff212a484312292cbb33c9b1f9394c5f
MD5 7d4128f4d190d675c35e81e0654a8339
BLAKE2b-256 f8a2f17d96878d9aae3975439d3546b500f68f3c72df47fce5667d86e31ea825

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymte-1.0.2-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

This release

1.0.2 This release

2 files

1.0.1

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