Skip to main content
ModernDiD

Modern Difference-in-Differences in Python

License PyPI version Python versions Ruff Code coverage Build status Documentation

Install guide | Features | Changelog | Documentation

What is ModernDiD?

ModernDiD is a Python library for difference-in-differences (DiD), designed for applied researchers, economists, and data scientists who estimate the effects of policies and treatments.

A two-way fixed effects regression, long the default way to run DiD in applied settings, can give misleading answers when treatment effects differ across groups or change over time. ModernDiD implements the estimators that recent research developed to avoid that problem.

Every estimator reports analytical or bootstrap standard errors for the effects it estimates. Most can also cluster those errors by a variable such as state. The staggered, triple-difference, continuous-treatment, and nonparametric IV estimators can build simultaneous confidence bands too. Estimation runs in parallel threads on one machine and supported estimators also run on NVIDIA GPUs for large panels.

ModernDiD is under active development so expect sharp edges. Please help by trying it out, reporting bugs, and telling us what you think. If you're new to DiD, the introduction covers the ideas behind the methods before any code.

Installation

ModernDiD requires Python 3.12 or later. In a project managed by uv, add it as a dependency.

uv add moderndid

With pip, install it into your environment instead.

pip install moderndid

Extras add optional dependencies and work the same way with either tool.

uv add "moderndid[plots]"            # Core estimators and plotting
uv add "moderndid[all]"              # All estimator extras and plots
uv add "moderndid[didcont,plots]"    # Choose individual extras
uv add "moderndid[gpu]"              # CUDA 12 GPU dependencies

The all extra includes didml and leaves out gpu. The installation guide covers every extra, GPU setup, and troubleshooting. The development version installs straight from GitHub.

uv add "moderndid[all] @ git+https://github.com/jordandeklerk/moderndid.git"

Features

ModernDiD covers the main research designs in the modern DiD literature.

Every estimator also comes with the tools the rest of an analysis needs.

  • Estimators accept any Arrow-compatible DataFrame, such as polars, pandas, pyarrow, or a DuckDB result.
  • Inference covers analytical and bootstrap standard errors, plus clustering and simultaneous confidence bands where the estimator supports them.
  • Plots return plotnine ggplot objects that take any further plotnine layer or theme.
  • Results work directly with maketables to build LaTeX, HTML, Word, and Typst tables.
  • Parallel threads speed up estimation on one machine.
  • Supported estimators also run on NVIDIA GPUs through CuPy for large panels.

Quickstart

The example below estimates how state minimum wage increases that took effect in different years affected teen employment. The staggered adoption example works through the same question at a deeper level.

import moderndid as did

# County teen employment and state minimum wage increases from 2003 to 2007
data = did.load_mpdta()

# An average effect for each treatment cohort and year
result = did.att_gt(
    data=data,
    yname="lemp",
    tname="year",
    idname="countyreal",
    gname="first.treat",
)

# An event study by time relative to treatment, plotted with the plots extra
event_study = did.aggte(result, type="dynamic")
did.plot_event_study(event_study)

Documentation

  • User Guide: installation, a first analysis, data preparation, results, and computation.
  • Examples: analyses for each treatment design.
  • API Reference: function signatures, parameters, and result objects.
  • Background: the assumptions, identification, and inference behind each estimator.
  • Comparisons with R: each estimator's results beside those of the R package for the same method.
  • FAQ: answers to common questions about data, estimators, and results.
  • Development: architecture, new estimators, debugging, and benchmarking.
  • Contributing: setup, workflow, testing, and releases.
  • Changelog: changes between versions.

Acknowledgements

ModernDiD builds on methods and implementations developed by researchers across the DiD literature. The acknowledgements list the papers and software behind each estimator.

Metadata

Release files for moderndid 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moderndid 0.3.1
File Size Uploaded
moderndid-0.3.1.tar.gz 1.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for moderndid 0.3.1
File Interpreter ABI Platform
moderndid-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 3.3 MB

Release files / moderndid-0.3.1.tar.gz

Download URL moderndid-0.3.1.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
238534aa7c4ca3ca05963d4e8f996050e75b05a5fbe695d0eaa32a1278afdffd
BLAKE2b-256 checksum
How to use checksums
87dd112a8facd91668f2831b92b7ce86d932985bb79d2d4577eaeca2e7adf47c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / moderndid-0.3.1-py3-none-any.whl

Download URL moderndid-0.3.1-py3-none-any.whl
Size 1.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5d2a8ab016c4a1c794f43bb55e17643107a980d9673c587fdd2f876810718a41
BLAKE2b-256 checksum
How to use checksums
5ab3f882fb4831b823fa790c11a3e38471ed1d0aefa814d3b25a4f0865558166
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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