https://github.com/bernardodionisi/differences
difference-in-differences in Python
https://github.com/bernardodionisi/differences
causal-inference difference-in-differences econometrics panel-data
Last synced: 1 day ago
JSON representation
difference-in-differences in Python
- Host: GitHub
- URL: https://github.com/bernardodionisi/differences
- Owner: bernardodionisi
- License: gpl-3.0
- Created: 2022-11-08T02:59:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2026-04-12T20:39:53.000Z (3 months ago)
- Last Synced: 2026-06-13T17:09:59.981Z (17 days ago)
- Topics: causal-inference, difference-in-differences, econometrics, panel-data
- Language: Python
- Homepage: https://bernardodionisi.github.io/differences/latest/
- Size: 13.9 MB
- Stars: 110
- Watchers: 4
- Forks: 27
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
- awesome-ai-for-economists - differences - Python implementation of Callaway and Sant'Anna staggered difference-in-differences with multiple periods and triple differences.  (Causal Inference and Econometrics / Frontier Tools)
README

difference-in-differences estimation and inference for Python
**For the following use cases**
- Balanced panels, unbalanced panels & repeated cross-section
- Two + Multiple time periods
- Fixed + Staggered treatment timing
- Binary + Multi-Valued treatment
- Heterogeneous treatment effects & triple difference
- Parallelized estimation & multiplier bootstrap (joblib, via `n_jobs`)
see the [Documentation](https://bernardodionisi.github.io/differences/latest/) for more details.
## Installing
The latest release can be installed using pip
```bash
pip install differences
```
requires Python >= 3.10
## Quick Start
### ATTgt
the ATTgt class implements the estimation procedures suggested by [Callaway and Sant'Anna (2021)
](https://www.sciencedirect.com/science/article/abs/pii/S0304407620303948), [Sant'Anna and Zhao
(2020)](https://www.sciencedirect.com/science/article/abs/pii/S0304407620301901) and the
multi-valued treatment case discussed
in [Callaway, Goodman-Bacon & Sant'Anna (2021)](https://arxiv.org/abs/2107.02637)
```python
import differences
df = differences.generate_data() # requires the [all] extra: pip install differences[all]
att_gt = differences.ATTgt(data=df, cohort_column='cohort')
att_gt.fit(formula='y', n_jobs=-1)
att_gt.aggregate('event')
```
*differences* ATTgt was inspired by
- Callaway & Sant'Anna's [did](https://github.com/bcallaway11/did)
- Sant'Anna and Zhao's [DRDID](https://github.com/pedrohcgs/DRDID)