Skip to main content

pymte

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-or-later. This package is a derivative work of the R package ivmte (Copyright Joshua Shea and Alexander Torgovitsky), distributed under the same licence. See LICENSE for the full text.

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.0.tar.gz (657.6 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.0-py3-none-any.whl (520.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymte-1.0.0.tar.gz
  • Upload date:
  • Size: 657.6 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.0.tar.gz
Algorithm Hash digest
SHA256 0c7378ed9c361c0c8308c2de8d514172bd90b775c41758dcd46a448ccb643be3
MD5 88d4fc813e1a3997c94600bfbf953373
BLAKE2b-256 70ade6ed1ce6fd365e4aafc85c31d9f923fb1d9e98bc2c384eb9d444254bb560

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pymte-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 520.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d06e3f4fd537f02a72cbec1747ad4ed04053b47a57d5362e0e3cd2726721514
MD5 92b51c9b10136d27fd2dd9cf9b98a1e7
BLAKE2b-256 2ad33d4f2101022a8260c38bc160b98fdee790a6ea4a22a57de57d762a9026dc

See more details on using hashes here.

Provenance

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

1.0.1

2 files

This release

1.0.0 This release

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