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
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,noextrapolationswitchers(up/down)aoss_vs_waossby,by_fd,by_baselinecontrols,weight,clusterother_treatmentscross_fitting,trimming,on_placebo_samplebootstrap+seedtwfe(withsame_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c05e3604284ed48b2688ee38a79fff52ccd066524afc3e619cd01eed05ceb059
|
|
| MD5 |
4a515c958f3c25ab19627d919d403bd4
|
|
| BLAKE2b-256 |
9120a0b6b64ea9c3143ea179f4c2b4a89e0cc15872af2df41abb126db8822710
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
did_multiplegt_stat-0.1.0.tar.gz -
Subject digest:
c05e3604284ed48b2688ee38a79fff52ccd066524afc3e619cd01eed05ceb059 - Sigstore transparency entry: 1839953534
- Sigstore integration time:
-
Permalink:
Credible-Answers/py_did_multiplegt_stat@297fa2fa44b2157ee75c0f4431d2fecbd1916a9d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Credible-Answers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@297fa2fa44b2157ee75c0f4431d2fecbd1916a9d -
Trigger Event:
push
-
Statement type:
File details
Details for the file did_multiplegt_stat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: did_multiplegt_stat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 70.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99dd6f38d4bab3a3db4660c2d900f2b285c6e1456da0264eecdedee3dc519bd3
|
|
| MD5 |
a61bdef45f166da5d8d83db8126b9917
|
|
| BLAKE2b-256 |
9eae122f577bae9d1c9be7b090eb9ef23deca4c62a41eebf0b6a4c4403809ff2
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
did_multiplegt_stat-0.1.0-py3-none-any.whl -
Subject digest:
99dd6f38d4bab3a3db4660c2d900f2b285c6e1456da0264eecdedee3dc519bd3 - Sigstore transparency entry: 1839953576
- Sigstore integration time:
-
Permalink:
Credible-Answers/py_did_multiplegt_stat@297fa2fa44b2157ee75c0f4431d2fecbd1916a9d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Credible-Answers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@297fa2fa44b2157ee75c0f4431d2fecbd1916a9d -
Trigger Event:
push
-
Statement type: