- Introduced by
- Chernozhukov et al. (double/debiased ML framework); Sant'Anna & Zhao (2020) for DR-DiD
- Year
- 2018-2020
- Type
- Causal inference / semiparametric
- Family
- Quasi-experimental / causal inference
What does it do?
Machine learning-augmented difference-in-differences (ML-DiD) applies the standard DiD comparison of treated and untreated groups before and after treatment, but estimates the nuisance functions (the outcome model and the treatment probability given covariates) with machine learning methods rather than fixed linear specifications.
The approach follows the double/debiased machine learning framework of Chernozhukov et al. (2018), which uses Neyman-orthogonal estimating equations and cross-fitting to make inference on a low-dimensional causal parameter valid when the nuisance functions are high-dimensional.
The intuition behind the method
Standard DiD adjusts for covariates with a linear regression, which is unreliable when many covariates enter the treatment-selection or outcome process in nonlinear or interacting ways. ML-DiD replaces these linear plug-in models with flexible learners, such as lasso, random forests, or boosted trees, to estimate the outcome regression for the control group and the probability of treatment given covariates. Plugging these learners naively into the DiD calculation would bias the estimate, because regularisation shrinks the fitted functions and flexible fitting can overfit the same data used for the treatment effect. The method addresses this in two ways: the estimating equation is built so that small errors in the nuisance fits have little first-order effect on the estimate, and cross-fitting ensures that each observation's nuisance prediction comes from models fitted without that observation. The parallel-trends assumption still has to hold; the ML components only improve how observed covariates are adjusted for.
History
Chernozhukov et al. (2018), published in The Econometrics Journal, introduced double/debiased machine learning, a general framework for root-n consistent inference on low-dimensional parameters when the nuisance functions are estimated by machine learning. The DML results are the foundation on which ML-DiD estimators are built. Callaway and Sant'Anna (2021) developed difference-in-differences methods for multiple time periods and staggered treatment adoption; the link between that work and machine learning nuisance estimators is not established by the cited source.
When to use it
Choose ML-DiD when the design is a difference-in-differences setting, with panel data or repeated cross-sections, treated and comparison groups, and pre- and post-treatment periods, and when the covariate set is large or the relationship between covariates, treatment and outcome seems unlikely to be linear. It is most useful when treatment assignment depends on many observed characteristics in complicated ways and a researcher wants the adjustment to rely less on a single parametric specification. Do not use it to address a violation of parallel trends; more flexible covariate adjustment does not repair a design in which the treated and comparison groups were already diverging. When the sample is small or the covariate set is modest, a standard DiD with linear controls is usually easier to interpret and less dependent on tuning choices.
Limitations and considerations
- ML nuisance estimators need enough observations to fit the outcome and treatment models well; with small samples the residuals and the estimate can be unstable.
- The method only changes how observed covariates are adjusted for. Unobserved trends or a violation of parallel trends are not addressed.
- The result depends on the tuning of the chosen learners, so estimates should be checked under alternative learners and tuning choices.
- The double-robustness property often associated with this design is not demonstrated by the estimating formula on this page. It should be checked for the estimator actually implemented, against its source.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Cross-fitting separates the data used to fit the nuisance functions from the data used to estimate the effect, which removes the overfitting bias that flexible learners would otherwise add to the estimate.
- The orthogonal form of the estimating equation reduces sensitivity to errors in the nuisance fits; Chernozhukov et al. (2018) show that, under their stated conditions, this supports root-n consistent and approximately normal estimates even when the nuisance learners are flexible.
- The nuisance step accepts several learner types, including lasso, random forests, boosted trees and neural networks, so the choice can follow the structure of the covariates.
- When the nuisance models are correctly specified, the estimate should be close to a linear-control DiD benchmark, which is worth reporting alongside the ML estimate. Parallel trends must still hold for either estimate.
Applications
- Evaluating a policy where the probability of treatment depends on many firm or worker characteristics in nonlinear ways, so that the propensity model benefits from a flexible learner.
- Comparing treated and comparison groups in administrative data with a large set of covariates, where the outcome model is unlikely to be linear.
- Staggered-adoption settings in which covariate balance differs across adoption cohorts and the adjustment must be recalculated within each cohort.
How it works
How it works
Estimate two nuisance functions with a machine learning method of choice: the conditional mean of the outcome given covariates among untreated units, and the propensity score, the probability of treatment given covariates. These functions carry the covariate adjustment that linear controls would otherwise provide.
Formula
\hat{\ell}(X) = E[Y|X,\,D=0],\quad \hat{p}(X) = P(D=1|X)Form residuals by subtracting the estimated control-group outcome from the observed outcome, and subtracting the estimated propensity score from the treatment indicator. Both the outcome and the treatment are thereby centred on their covariate-predicted values.
Formula
\tilde{Y}_{it} = Y_{it} - \hat{\ell}(X_{it}),\quad \tilde{D}_{it} = D_{it} - \hat{p}(X_{it})Split the sample into K folds. Fit the nuisance functions on K minus one folds and compute residuals for the held-out fold, repeating so that every observation is predicted by a model that did not use it. Cross-fitting removes the overfitting bias that would otherwise arise when the same data fit the nuisance functions and estimate the effect; the orthogonal form of the estimating equation handles the regularisation bias.
Compute the DiD estimate on the residualised data. The expression in the mechanics is a schematic of the residual-based construction, not a validated estimator: it contains no explicit inverse-propensity or doubly-robust weights, so it should not be implemented as written. For an implementation, follow a doubly-robust DiD construction from the published literature and check its weights against that source.
Formula
\hat{\tau}_{ATT} = \frac{1}{n}\sum_{i}\left[\tilde{Y}_{i,post} - \tilde{Y}_{i,pre}\right] \cdot \frac{\tilde{D}_i}{E[\tilde{D}_i^2]}Standard errors and confidence intervals are derived from the influence function of the orthogonal estimating equation, which is the usual route to valid inference for DML estimators. This page does not give the variance expression, so the exact form and the cross-fitting standard error procedure should be taken from Chernozhukov et al. (2018) before intervals are reported.
Common pitfalls
- Treating improved covariate adjustment as evidence that parallel trends hold. Pre-period trends still need to be examined directly.
- Omitting cross-fitting and fitting the nuisance functions and the treatment effect on the same sample, which invalidates the standard errors.
- Using one heavily regularised learner on a small sample and reporting the result without checking how sensitive it is to the learner.
- Applying the single-period estimator to staggered adoption without adapting it to treatment timing; group-time methods such as the one in Callaway and Sant'Anna (2021) address this setting.
Frequently asked questions
Is ML-DiD the same as running DiD after propensity-score matching with a machine learning model?
No. Propensity-score matching selects a matched sample and then runs DiD on it, and it does not use an outcome model. ML-DiD instead estimates both an outcome model and a treatment model, uses residuals from both, and applies cross-fitting before estimating the treatment effect.
Which machine learning algorithm should I use for the nuisance functions?
Chernozhukov et al. (2018) require the nuisance estimation errors to shrink fast enough that their product vanishes at the root-n rate. The page's n^{-1/4} figure illustrates when this holds; it is not a per-learner requirement. Check the exact norm and conditions in that source before relying on a particular learner. Lasso, random forests and gradient boosting are common choices. It is good practice to try more than one learner and check whether the estimates are stable.
Does ML-DiD still require the parallel-trends assumption?
Yes. The ML components improve covariate adjustment only. The parallel-trends condition must hold, possibly conditional on covariates, for the ATT to have a causal interpretation.
What is cross-fitting and why is it necessary?
Cross-fitting splits the data into folds, fits the nuisance functions on some folds, and computes residuals on the held-out fold, repeating so that every observation is predicted out of sample. This prevents the flexible learners from overfitting the data used to estimate the treatment effect, which would otherwise bias the estimate and invalidate standard errors.
How does ML-DiD relate to the Callaway and Sant'Anna estimator?
Callaway and Sant'Anna (2021) develop group-time treatment effect estimators for multiple periods and staggered adoption. Using machine learning inside that framework is an extension that the cited source does not itself establish, so any such implementation should be documented and checked separately.
Related methods
Sources
Chernozhukov, V., Chetverikov, D., Demirer, M., Duflo, E., Hansen, C., Newey, W., & Robins, J. (2018). Double/debiased machine learning for treatment and structural parameters. The Econometrics Journal, 21(1), C1-C68.
Open DOI referenceCallaway, B., & Sant'Anna, P. H. C. (2021). Difference-in-Differences with multiple time periods. Journal of Econometrics, 225(2), 200-230.
Open DOI reference