Skip to main content

Heterogeneity-robust difference-in-differences (DID) estimators (AS, WAS, IV-WAS) with stayers, for binary, discrete, or continuous treatments. Python port of the Stata `did_multiplegt_stat` package.

Project description

did_multiplegt_stat

PyPI version Python versions License: GPL v3

Python implementation of the did_multiplegt_stat Stata package by de Chaisemartin, D'Haultfœuille, Pasquier, Sow, and Vazquez-Bare (2024) — heterogeneity-robust difference-in-differences estimators with stayers for binary, discrete, or continuous treatments (and instruments).

The package estimates the Average Slope (AS), Weighted Average Slope (WAS), and IV-WAS parameters in static designs where parallel trends is assumed conditional on the baseline treatment.

Installation

pip install did-multiplegt-stat

Optional extras:

pip install "did-multiplegt-stat[linearmodels]"   # alternative IV backend
pip install "did-multiplegt-stat[docs]"           # build docs locally
pip install "did-multiplegt-stat[dev]"            # tests + tooling

Quick start

import pandas as pd
from did_multiplegt_stat import DIDMultiplegtStat

df = pd.read_stata("gazoline_did_multiplegt_stat.dta")

# AS + WAS with 3 placebo periods (mirrors Stata example 2)
model = DIDMultiplegtStat(
    estimator=["aoss", "waoss"],
    order=1,
    placebo=3,
    aoss_vs_waoss=True,
)
model.fit(df, Y="lngca", ID="id", Time="year", D="tau")
model.summary()
model.plot()

Functional API (one-shot, mirrors the Stata command):

from did_multiplegt_stat import did_multiplegt_stat, summary_did_multiplegt_stat

res = did_multiplegt_stat(df, Y="lngca", ID="id", Time="year", D="tau",
                          estimator=["aoss", "waoss"], placebo=3,
                          aoss_vs_waoss=True)
summary_did_multiplegt_stat(res)

Backends: asinstata

Two regression backends are bundled:

Backend When to use Activate
scikit-learn (default) Default behaviour. Faster, modern numerical stack. asinstata=False
Stata-faithful Need byte-for-byte parity with the Stata ado-file. asinstata=True
Custom sklearn-style Want a RandomForest, LassoCV, etc. as the nuisance. model_deltay=..., model_stayer=...

Stata parity uses statsmodels OLS + a from-scratch Newton-Raphson logit that matches Stata's logit, asis defaults; results agree to ~1e-7 relative error.

What's supported

All Stata options are exposed, including:

  • estimator (aoss / waoss / ivwaoss)
  • estimation_method (ra / ps / dr)
  • order (scalar, 4-tuple, or 8-tuple for IV)
  • placebo(N) (multi-period placebos)
  • exact_match, noextrapolation
  • switchers (up / down)
  • aoss_vs_waoss
  • by, by_fd, by_baseline
  • controls, weight, cluster
  • other_treatments
  • cross_fitting, trimming, on_placebo_sample
  • bootstrap + seed
  • twfe (with same_sample, full_sample, percentile)
  • cross_validation (k-fold CV for polynomial order)

See the full documentation for the help-file style reference.

Citation

If you use this software in academic work, please cite the underlying paper:

de Chaisemartin, C., D'Haultfœuille, X., Pasquier, F., Sow, D., Vazquez-Bare, G. (2024). Difference-in-Differences for Continuous Treatments and Instruments with Stayers. arXiv:2201.06898.

A CITATION.cff is bundled for tooling integration.

License

GPL-3.0-or-later — see LICENSE.

Authors

Originally authored by the team behind the Stata package:

  • Clément de Chaisemartin (Sciences Po)
  • Diego Ciccia (Sciences Po)
  • Xavier D'Haultfœuille (CREST-ENSAE)
  • Felix Knau (Sciences Po)
  • Felix Pasquier (CREST-ENSAE)
  • Doulo Sow (Sciences Po)
  • Gonzalo Vazquez-Bare (UCSB)

Python port: Anzony Quispe.

Contact: chaisemartin.packages@gmail.com

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

did_multiplegt_stat-0.1.0.tar.gz (777.4 kB view details)

Uploaded Source

Built Distribution

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

did_multiplegt_stat-0.1.0-py3-none-any.whl (70.9 kB view details)

Uploaded Python 3

File details

Details for the file did_multiplegt_stat-0.1.0.tar.gz.

File metadata

  • Download URL: did_multiplegt_stat-0.1.0.tar.gz
  • Upload date:
  • Size: 777.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for did_multiplegt_stat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c05e3604284ed48b2688ee38a79fff52ccd066524afc3e619cd01eed05ceb059
MD5 4a515c958f3c25ab19627d919d403bd4
BLAKE2b-256 9120a0b6b64ea9c3143ea179f4c2b4a89e0cc15872af2df41abb126db8822710

See more details on using hashes here.

Provenance

The following attestation bundles were made for did_multiplegt_stat-0.1.0.tar.gz:

Publisher: release.yml on Credible-Answers/py_did_multiplegt_stat

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

File details

Details for the file did_multiplegt_stat-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for did_multiplegt_stat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99dd6f38d4bab3a3db4660c2d900f2b285c6e1456da0264eecdedee3dc519bd3
MD5 a61bdef45f166da5d8d83db8126b9917
BLAKE2b-256 9eae122f577bae9d1c9be7b090eb9ef23deca4c62a41eebf0b6a4c4403809ff2

See more details on using hashes here.

Provenance

The following attestation bundles were made for did_multiplegt_stat-0.1.0-py3-none-any.whl:

Publisher: release.yml on Credible-Answers/py_did_multiplegt_stat

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