A previous release had provenance metadata, but this release does not. View details.
ETWFE: Extended Two-Way Fixed Effects
A Python implementation of the Extended Two-Way Fixed Effects (ETWFE) estimator from Wooldridge (2021, 2023) for difference-in-differences estimation with heterogeneous treatment effects.
Installation
pip install etwfe
For development:
pip install etwfe[dev,full]
Quick Start
import pandas as pd
from etwfe import etwfe
# Load your panel data
df = pd.read_csv("your_data.csv")
# Fit ETWFE model
model = etwfe(
fml="outcome ~ 0", # outcome variable (no controls)
tvar="year", # time period variable
gvar="first_treat_year", # treatment cohort variable
data=df,
ivar="unit_id" # unit identifier for FE
)
# View summary
model.summary()
# Compute marginal effects
att = model.emfx(type="simple") # Overall ATT
event = model.emfx(type="event") # Event study
cohort = model.emfx(type="group") # By treatment cohort
calendar = model.emfx(type="calendar") # By calendar time
# Plot event study
model.plot(type="event")
Features
- Wooldridge (2021, 2023) ETWFE methodology: Properly handles heterogeneous treatment effects in staggered DiD settings
- Multiple control group options: "notyet" (not-yet-treated) or "never" (never-treated)
- GLM support: Poisson, logit, probit, and Gaussian families
- Heterogeneous effects: Support for treatment effect heterogeneity via
xvar - Flexible fixed effects: Unit and time fixed effects
- Standard errors: Heteroskedasticity-robust and clustered standard errors via pyfixest
- Marginal effects: Simple ATT, event study, cohort-specific, and calendar-time effects
- Visualization: Built-in plotting for event studies
API Reference
ETWFE Class
from etwfe import ETWFE
model = ETWFE(
fml="y ~ x1 + x2", # Formula: outcome ~ controls
tvar="year", # Time variable
gvar="first_treat", # Treatment cohort variable
data=df,
ivar="id", # Unit ID (optional, for unit FE)
xvar="group", # Heterogeneity variable (optional)
tref=2000, # Reference time period (optional)
gref=9999, # Reference cohort (optional)
cgroup="notyet", # Control group: "notyet" or "never"
family=None, # GLM family: None, "poisson", "logit", "probit"
vcov="hetero", # Variance-covariance estimator
)
model.fit()
Convenience Function
from etwfe import etwfe
# Creates and fits in one step
model = etwfe("y ~ 0", tvar="year", gvar="first_treat", data=df)
Marginal Effects
# Simple overall ATT
model.emfx(type="simple")
# Event study (by event time)
model.emfx(type="event")
# By treatment cohort
model.emfx(type="group")
# By calendar time
model.emfx(type="calendar")
# Options
model.emfx(
type="event",
by_xvar=True, # Separate effects by xvar
compress=True, # Compress data for speed
predict="response", # "response" or "link" for GLM
post_only=True, # Post-treatment only
vcov=False, # Skip SE computation
window=5, # Event window [-5, +5]
)
Plotting
# Event study plot
model.plot(type="event")
# Cohort effects
model.plot(type="group")
# Calendar time effects
model.plot(type="calendar")
Requirements
- Python >= 3.9
- numpy >= 1.21.0
- pandas >= 1.3.0
- matplotlib >= 3.4.0
- pyfixest >= 0.18.0
Optional:
- patsy >= 0.5.3 (for model matrix construction)
- scipy >= 1.7.0 (for probit link function)
References
- Wooldridge, J. M. (2021). "Two-Way Fixed Effects, the Two-Way Mundlak Regression, and Difference-in-Differences Estimators." Working Paper.
- Wooldridge, J. M. (2023). "Simple Approaches to Nonlinear Difference-in-Differences with Panel Data." The Econometrics Journal.
License
MIT License
Metadata
Release files for etwfe 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Loss of provenance
These files do not have provenance metadata, despite files in a prior release including this data.
We recommend further investigation before installing these files. View details.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| etwfe-0.1.4.tar.gz | 14.5 kB | Without provenance | Details for etwfe-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| etwfe-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for etwfe-0.1.4-py3-none-any.whl |
Total release size: 28.2 kB
Release files / etwfe-0.1.4.tar.gz
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | etwfe-0.1.4.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4011e5c4669ed6e09253711beaf924218bca82c08917c73c93758ab6d716e76
|
|
BLAKE2b-256 checksum How to use checksums |
18a49fbfb6f776a6fddb01c2012075ca529cd1dcd07015a576b56982895f225a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / etwfe-0.1.4-py3-none-any.whl
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | etwfe-0.1.4-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5aae31d0963ee9aad0c4ad277909dfa664f69cea3c4353e7418bc4c4fd143cb6
|
|
BLAKE2b-256 checksum How to use checksums |
db241f452284a491c737366adbdda11f33ff6cb4c718e33b00641f9d544093b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Security for etwfe 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Loss of provenance
A previous release of these files had provenance metadata, but this release does not.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
Release comparison
- Removed 0.1.0 2 files With provenance
- Added 0.1.4 2 files Without provenance
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.