DiDToolbox

Toolbox to conduct econometric DiD analyses of causal relationships in the context of staggered treatments.
0 download
Aggiornato 30 ott 2025
DiD-Toolbox for Matlab
Purpose
The DiD Toolbox is a set of Matlab tools designed for applied statisticians and econometricians to conduct Difference-in-Differences (DiD) analyses, particularly focusing on designs involving staggered treatment timing. The traditional Two-Way Fixed Effects (TWFE) estimator, while common, yields estimates that may be biased and difficult to interpret when treatment effects are heterogeneous across groups or vary over time. The primary goal of this toolbox is to address these methodological challenges by providing modern, robust estimators that yield valid causal estimates in complex multi-period, staggered adoption scenarios.
Disclaimer
  • The toolbox is under development, and needs more internal structure. Do use with care and be aware that the current state may not be "production ready" yet.
  • However, I backtested all of the estimators and corresponding results using simulated data with Stata 18, utilizing implementations by Stata Corp. itself and some of the packages designed by the underlying paper's authors. Also see the provided example file, which has a Stata log-file for comparison.
  • The Wooldridge and Callaway/Sant'Anna estimators have been tested for unbiasedness via Monte Carlo-simulation.
  • Most of the code base was developed with the help of ChatGPT 5 Thinking. The documentation was developed also using features of NotebookLM by Google.
If researchers with interest in the topic and OOP skills in Matlab are interested in joining this project, I'd very much appreciate collaboration.
Overview Codebase and Theoretical Foundations
The methodologies of the toolbox are grounded in foundational and recent academic literature. The software implementation uses Object-Oriented Programming (OOP) within Matlab.
Theoretical Papers: The toolbox implements methods developed or discussed in the following key papers:
  • Goodman-Bacon (2021): Provides the mathematical foundation for the decomposition of the TWFE estimator, explaining how it operates as a weighted average of DiD estimates and identifying the source of bias from "negative weights" due to treatment effect heterogeneity.
  • Wooldridge (2021): Establishes the algebraic equivalence between the Two-Way Fixed Effects (TWFE) estimator and the Two-Way Mundlak (TWM) regression, enabling flexible implementation using pooled OLS.
  • Borusyak, Jaravel, and Spiess (2024): Derives the efficient and robust imputation estimator (BJS) for staggered DiD, which estimates counterfactual outcomes using only untreated observations to calculate heterogeneous causal effects, providing efficiency and avoiding spurious identification.
  • de Chaisemartin and D'Haultfœuille (2020): Proposes the estimator, which estimates a robust Average Treatment Effect across switching cells () and introduces robustness measures for assessing TWFE bias, particularly in designs where weights may be negative. And the unique feature is that the estimator can handle an on/off treatment, while all other estimators assume that treatment is an absorptive state.
  • Callaway / Sant'Anna (2021): CS focus on cohort/time based analyses, looking at with a focus on taking covariates into account. They derive identification, estimation, and inference strategies assuming parametric nuisance models (i.e. linear outcome regression, logit for propensity scores) that admit standard regularity conditions. In an extension, the interaction weighted estimator by Sun/Abraham (2021) builds on this work, showing how get unbiased event studies in this setting.

Cita come

Ralf Elsas (2025). DiDToolbox (https://github.com/relsas/DiDToolbox/releases/tag/v0.9.01), GitHub. Recuperato .

Compatibilità della release di MATLAB
Creato con R2025a
Compatibile con R2021b fino a R2025a
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
0.9.01

Per visualizzare o segnalare problemi su questo componente aggiuntivo di GitHub, visita GitHub Repository.
Per visualizzare o segnalare problemi su questo componente aggiuntivo di GitHub, visita GitHub Repository.