betaFeedback

WorksMathematics

Causal Mediation Analysis for Panel Data with Double/Debiased Machine Learning

Abstract

We develop a double/debiased machine learning framework for causal mediation analysis in panel data with two-way fixed effects. Binary, multivalued, or continuous treatments and continuous mediators affect outcomes via histories. We formulate partially linear models for potential outcomes and mediators, define history-specific direct, indirect, and total effects, and identify them under a sequential conditional independence assumption given unit effects, allowing arbitrary time-invariant confounding. Estimation combines first-differencing, cross-fitting sample splitting that removes period effects, and machine-learned confounding functions within a GMM framework whose score is Neyman orthogonal in all nuisance components. We establish asymptotic normality of the estimators for the structural parameters and causal estimands and provide consistent variance estimators. Simulations show small bias and near-nominal coverage under nonlinear confounding, whereas a DML-free benchmark fails severely for indirect effects. An application to U.S. county data illustrates that a stable total effect can conceal substantial sensitivity in its direct-indirect decomposition.

Introduction

Many empirical questions concern not only whether an intervention changes an outcome, but also how that change is produced. A policy may affect income through employment and wages, a medical treatment may operate through an intermediate biomarker, and an educational program may alter later outcomes through a sequence of behavioral responses. Causal mediation analysis formalizes such questions by decomposing a total effect into direct and indirect components associated with a mediator. The potential-outcome literature has developed identification and semiparametric theory for controlled, natural direct, and natural indirect effects in cross-sectional settings [14, 9, 17]. In panel data, however, both treatment and mediator may vary over time, current outcomes may depend on their histories, and the relevant counterfactual is therefore nested over an entire mediator path rather than a single intermediate variable.

Longitudinal extensions of mediation analysis, by allowing exposures and mediators to vary over time, have clarified how dynamic pathways can be defined and identified [18, 22, 7]. Yet repeated observations also create a problem that is central in many panel applications: persistent unobserved heterogeneity may jointly affect treatment, mediator, and outcome in every period. Conditioning on a rich observed history need not remove this confounding, whereas a conventional fixed-effects regression, by itself, does not identify the nested counterfactuals required for natural effects. At the same time, observed confounding may be high-dimensional and nonlinear, making a fully parametric adjustment fragile. A useful panel mediation method must therefore exploit repeated measurements to accommodate time-invariant unobservables, retain sufficient flexibility for observed confounders, and still deliver valid inference for a decomposition that depends on more than one structural equation.

Double/debiased machine learning (DML) provides a general route to inference on low-dimensional parameters in the presence of complex nuisance functions Chernozhukov et al. [4]. Within causal mediation analysis, Farbmacher et al. (2022) construct cross-sectional DML estimators for direct and indirect effects with a binary treatment, and Zenati et al. [21] study a mediated response curve with a continuous treatment. More recently, Wei et al. [19] develop cross-sectional debiased ML for ultra-high-dimensional mediation, combining orthogonal scores and cross-fitting with screening and regularization for mediator selection and inference. Two contemporaneous contributions develop mediation analysis for difference-in-differences designs: Huber and Oberhänsli [8] combine DML with conditional parallel-trends restrictions, while Deng et al. [6] derive semiparametric estimators under mediator-adjusted parallel trends. Unlike Huber and Oberhänsli [8], whose mediation effects are identified through conditional parallel trends in a DiD design, our framework targets history-specific mediation effects in a longitudinal panel system and uses sequential conditional independence together with fixed effects to accommodate time-invariant unobserved confounding.

A separate literature extends machine learning and orthogonalization to sequential and panel treatment-effect problems. Lewis and Syrgkanis [12] develop DML for dynamic treatment sequences, Semenova et al. [16] study heterogeneous effects in high-dimensional dynamic panels under weak dependence, and Clarke and Polselli [5] construct DML procedures for static fixed-effects models. Most closely related is Wu and Xiao [20], who develop DML–GMM inference for treatment effects in dynamic panels with two-way fixed effects, general treatment scales, and history-dependent potential outcomes. Their auxiliary-fold construction for eliminating period effects is particularly relevant here. However, moving from treatment effects to mediation effects is not a mechanical stacking of two panel DML regressions. The mediator is both an intermediate response and a regressor in the outcome equation; its estimated innovation is also needed to construct instruments for that equation. Natural effects involve nested counterfactual mediator histories and depend jointly on the parameters of both structural equations and on their estimation covariance. These features create identification, orthogonalization, and inference problems absent from a single-equation treatment-effect analysis.

We develop DML-based causal mediation analysis in panel data with two-way fixed effects; however, this generalization requires overcoming several difficulties. First, the identifying argument must recover nested potential outcomes in a two-equation history-dependent system rather than a single potential-outcome regression. Second, sequential exogeneity does not generally validate contemporaneous instruments after fixed-effect removal. We therefore construct GMM moments from lagged residualized treatment and mediator innovations. The outcome instrument contains an estimated mediator innovation and hence depends on the mediator coefficient. We introduce a nuisance copy of that coefficient, learned outside the score-evaluation fold, so that mediator innovations can be used without making the final GMM score nonlinear in the target parameter. Third, eliminating two-way fixed effects while preserving the independence required by cross-fitting calls for a three-way use of the sample. First differences remove unit effects, and period effects are removed with cross-sectional means computed from an auxiliary fold that is distinct from both the score-evaluation fold and the nuisance-training sample. The resulting mean-subtraction terms induce additional dependence that must be shown to be asymptotically negligible. Fourth, inference for natural effects cannot be obtained by applying a delta method to the structural coefficients alone: the estimators also average individual counterfactual contributions, and the mediator and outcome coefficients are estimated jointly. The influence function must retain both sources of variation and their covariance.

The paper makes three contributions. First, it provides a unified causal framework for history-specific mediation effects in panels. We formulate partially linear models for the potential outcome and potential mediator in which researcher-chosen dictionaries describe dynamic and heterogeneous causal components, while unknown functions flexibly absorb nonlinear observed confounding. Treatments may be binary, multivalued, or continuous, mediators are continuous, and we define history-specific controlled direct, natural direct, natural indirect, and total effects together with their derivative counterparts. Identification relies on sequential conditional independence given the observed history, the relevant unit effect, and the period effects, which permits arbitrary time-invariant confounding and translates the potential-outcome system into observed-data equations governed by the same structural parameters. A distinctive feature of this paper is that two-way fixed effects are allowed in the outcome, mediator, and treatment-assignment models, thereby exploiting repeated observations throughout the treatment–mediator–outcome system. To our knowledge, no existing procedure combines history-specific natural effects, two-way fixed effects in all three equations, sequentially valid residual instruments, and DML-based joint inference.

Second, we develop a DML–GMM procedure tailored to the two-equation mediation system. Sequential exogeneity motivates moments based on lagged residualized treatment and mediator innovations rather than contemporaneous instruments. First differences remove unit effects, while period effects are removed using cross-sectional means from an auxiliary fold that is distinct from both the nuisance-training and score-evaluation samples. Because the outcome instrument contains an estimated mediator innovation, we introduce a fold-specific nuisance copy of the mediator coefficient; this preserves an affine score and a quadratic GMM problem. Jointly stacking the two equations and estimating their full moment covariance retains the cross-equation dependence required for inference on natural direct and indirect effects.

Third, we establish an oracle representation and root-NN asymptotic normality for the joint estimator of the outcome and mediator parameters under high-level mean-square and product-rate conditions on the first stages. Auxiliary-fold demeaning is shown not to affect the first-order distribution, and a consistent sandwich variance estimator is provided. For any fixed smooth collection of level or derivative effects, we derive an asymptotic linear representation that combines sampling variation in individual counterfactual contrasts with estimation error in both parameter blocks. The resulting theory supports joint Wald inference for direct, indirect, and total effects, including collections whose exact decompositions make the covariance matrix singular.

In simulations with nonlinear time-varying confounding, correlated fixed effects, equation-specific period effects, and sequentially endogenous differenced regressors, the proposed estimator has small bias and near-nominal coverage, whereas a benchmark using the same first-stage learner can fail sharply for the mediator equation and indirect effects. In the U.S. county application, allowing treatment–covariate interactions leaves the estimated total effect essentially unchanged but reduces the estimated mediated share from about 65% to 41%, showing that stability of the total effect alone need not validate its direct–indirect decomposition.

The remainder of the paper is organized as follows. § 2 introduces the causal estimands, the panel mediation model, and the identification conditions. § 3 develops the DML–GMM algorithm and the plug-in estimators of the causal effects. § 4 establishes the asymptotic theory. § 5 and § 6 report the simulation study and empirical application, respectively, and § 7 concludes. Extension to multi- and high-dimensional mediator cases, additional theoretical and numerical results, and proofs are provided in the online supplementary material.

Problem setup

Notation and framework

We consider a balanced panel comprising NN units observed over TT periods, with units indexed by i=1,…,Ni=1,\ldots,N and periods by t=1,…,Tt=1,\ldots,T. For unit ii in period tt, let Yit∈RY_{it}\in\mathbb{R}, Mit∈RM_{it}\in\mathbb{R}, Dit∈RD_{it}\in\mathbb{R}, and Xit:=(Xit1,…,XitLX)′∈RLXX_{it}:=(X_{it1},\ldots,X_{itL_X})^{\prime}\in\mathbb{R}^{L_X} denote, respectively, the outcome, the mediator, the treatment, and a LXL_X-dimensional vector of observed covariates. In Appendix A, we discuss how to extend our framework to vector-valued or high-dimensional mediators. The framework accommodates continuous mediators and binary, multivalued, or continuous treatments. Within each period, XitX_{it} is realized before DitD_{it}, followed by MitM_{it} and then YitY_{it}.

We begin by stating the standard causal assumptions required for our analysis. The first is a mediation-specific version of the stable unit treatment value assumption (SUTVA; Imbens and Rubin, [10]).

Assumption 1 (Stable unit treatment value assumption). For each unit, the potential outcome depends only on that unit’s treatment and mediator assignments. Moreover, each treatment and mediator level has a unique version. Equivalently, there is neither interference across units nor hidden variation in treatment or mediator assignments.

We further impose a no-anticipation condition, under which future treatment and mediator assignments cannot affect current or past outcomes.

Assumption 2 (No anticipation). For every tt, a unit’s potential outcome in period tt depends only on treatment and mediator assignments through period tt and is invariant to assignments in periods after tt.

For any time-indexed variable, such as VitV_{it} or WtW_t, define V‾it:=(Vi1,…,Vit)′\overline{V}_{it}:=(V_{i1},\ldots,V_{it})^{\prime}, W‾t:=(W1,…,Wt)′\overline{W}_t:=(W_1,\ldots,W_t)^{\prime}, and W‾j:k:=(Wj,…,Wk)′\overline{W}_{j:k}:=(W_j,\ldots,W_k)^{\prime} for j≤kj\leq k. Following the potential-outcomes notation of Rubin [15], let Yit(dˉt,mˉt)Y_{it}(\bar{d}_t,\bar{m}_t) denote the potential outcome for unit ii in period tt under treatment history dˉt\bar{d}_t and mediator history mˉt\bar{m}_t, where dˉt\bar{d}_t and mˉt\bar{m}_t are possible realizations of Dˉit\bar{D}_{it} and Mˉit\bar{M}_{it}, respectively. Likewise, let Mit(dˉt)M_{it}(\bar{d}_t) denote the potential mediator for unit ii in period tt under treatment history dˉt\bar{d}_t, and define Mˉit(dˉt∗):=(Mi1(d1∗),…,Mit(dt∗))′\bar{M}_{it}(\bar{d}^{*}_t) := (M_{i1}(d^{*}_1), \ldots, M_{it}(d^{*}_t))'.

To link these potential variables to their observed counterparts, we impose the standard consistency assumption.

Assumption 3 (Consistency). For every unit ii and period tt, the observed outcome and mediator coincide with their potential counterparts under the realized treatment and mediator histories: Yit=Yit(Dˉit,Mˉit)Y_{it} = Y_{it}(\bar{D}_{it},\bar{M}_{it}) and Mit=Mit(Dˉit)M_{it} = M_{it}(\bar{D}_{it}).

Causal estimands

For two given treatment histories dˉt:=(d1,…,dt)′\bar{d}_t := (d_1,\ldots,d_t)' and dˉt∗:=(d1∗,…,dt∗)′\bar{d}^{*}_t := (d^{*}_1,\ldots,d^{*}_t)', define the nested potential outcome Yit(dˉt,Mˉit(dˉt∗))Y_{it}(\bar{d}_t,\bar{M}_{it}(\bar{d}^{*}_t)), which sets the treatment history to dˉt\bar{d}_t while setting the entire mediator history to its natural value under dˉt∗\bar{d}^{*}_t. The following estimands extend the conventional controlled direct, natural direct, and natural indirect effects to treatment and mediator histories; related longitudinal formulations are discussed by VanderWeele and Tchetgen Tchetgen [18].

References

  1. [1]Timothy J. Bartik. Who Benefits from State and Local Economic Development Policies? W. E. Upjohn Institute for Employment Research, Kalamazoo, MI, 1991.
  2. [2]Olivier Jean Blanchard and Lawrence F. Katz. Regional evolutions. Brookings Papers on Economic Activity, 1992(1):1–75, 1992.DOI
  3. [3]Augusto Cerqua, Marco Letta, and Gabriele Pinto. On the (mis)use of machine learning with panel data. Oxford Bulletin of Economics and Statistics, 88(3):506–518, 2026. doi: 10.1111/obes.70019.DOI
  4. [4]Victor Chernozhukov, Denis Chetverikov, Mert Demirer, Esther Duflo, Christian Hansen, Whitney Newey, and James Robins. Double/debiased machine learning for treatment and structural parameters. The Econometrics Journal, 21(1):C1–C68, 01 2018. ISSN 1368-4221. doi: 10.1111/ectj.12097.DOI
  5. [5]Paul S. Clarke and Annalivia Polselli. Double machine learning for static panel models with fixed effects. The Econometrics Journal, 29(1):69–86, 2026. doi: 10.1093/ectj/utaf011.
  6. [6]Yuhao Deng, Haoyu Wei, and Zhongzhe Ouyang. Difference-in-differences with a mediator. arXiv preprint arXiv:2604.24049, 2026.arxiv.org/abs/2604.24049
  7. [7]Iván Díaz, Nicholas Williams, and Kara E. Rudolph. Efficient and flexible mediation analysis with time-varying mediators, treatments, and confounders. Journal of Causal Inference, 11(1), 2023. doi: 10.1515/jci-2022-0077. Helmut Farbmacher, Martin Huber, Lukáš Lafférs, Henrika Langen, and Martin Spindler. Causal mediation analysis with double machine learning. The Econometrics Journal, 25 (2):277–300, 2022. doi: 10.1093/ectj/utac003.
  8. [8]Martin Huber and Sarina Joy Oberhänsli. Difference-in-differences for mediation analysis using double machine learning. arXiv preprint arXiv:2602.23877, 2026.arxiv.org/abs/2602.23877
  9. [9]Kosuke Imai, Luke Keele, and Teppei Yamamoto. Identification, inference and sensitivity analysis for causal mediation effects. Statistical Science, 25(1):51–71, 2010. doi: 10.1214/10-STS321.DOI
  10. [10]Guido W Imbens and Donald B Rubin. Causal inference in statistics, social, and biomedical sciences. Cambridge University Press, 2015.DOI
  11. [11]George Kapetanios. A bootstrap procedure for panel data sets with many cross-sectional units. The Econometrics Journal, 11(2):377–395, 2008.DOI
  12. [12]Greg Lewis and Vasilis Syrgkanis. Double/debiased machine learning for dynamic treatment effects. In Advances in Neural Information Processing Systems, volume 34, 2021.
  13. [13]Thomas S Richardson and James M Robins. Single world intervention graphs (swigs): A unification of the counterfactual and graphical approaches to causality. Center for the Statistics and the Social Sciences, University of Washington Series. Working Paper, 128 (30), 2013.
  14. [14]James M. Robins and Sander Greenland. Identifiability and exchangeability for direct and indirect effects. Epidemiology, 3(2):143–155, 1992. doi: 10.1097/00001648-199203000-00013.DOI
  15. [15]Donald B Rubin. Estimating causal effects of treatments in randomized and nonrandomized studies. Journal of educational Psychology, 66(5):688, 1974.DOI
  16. [16]Vira Semenova, Matt Goldman, Victor Chernozhukov, and Matt Taddy. Inference on heterogeneous treatment effects in high-dimensional dynamic panels under weak dependence. Quantitative Economics, 14(2):471–510, 2023. doi: 10.3982/QE1670.
  17. [17]Eric J. Tchetgen Tchetgen and Ilya Shpitser. Semiparametric theory for causal mediation analysis: Efficiency bounds, multiple robustness, and sensitivity analysis. The Annals of Statistics, 40(3):1816–1845, 2012. doi: 10.1214/12-AOS990.DOI
  18. [18]Tyler J VanderWeele and Eric J Tchetgen Tchetgen. Mediation analysis with time varying exposures and mediators. Journal of the Royal Statistical Society Series B: Statistical Methodology, 79(3):917–938, 2017.DOI
  19. [19]Kecheng Wei, Yahang Liu, Chen Huang, Ruilang Lin, Yongfu Yu, and Guoyou Qin. Debiased machine learning for ultra-high dimensional mediation analysis. Bioinformatics, 41(6):btaf282, 2025.DOI
  20. [20]Peikai Wu and Zhiguo Xiao. Double/debiased machine learning for treatment effects in dynamic panels. Journal of the American Statistical Association, pages 1–12, 2026. https://doi.org/10.1080/01621459.2026.2696607.
  21. [21]Houssam Zenati, Judith Abécassis, Julie Josse, and Bertrand Thirion. Double debiased machine learning for mediation analysis with continuous treatments. In Proceedings of the 28th International Conference on Artificial Intelligence and Statistics, volume 258 of Proceedings of Machine Learning Research, pages 4150–4158. PMLR, 2025.arxiv.org/abs/2503.06156
  22. [22]Wenjing Zheng and Mark J. van der Laan. Longitudinal mediation analysis with time-varying mediators and exposures, with application to survival outcomes. Journal of Causal Inference, 5(2), 2017. doi: 10.1515/jci-2016-0006.DOI

Paper details

vlnc:W_2up5mdxm
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Mathematics

Not recorded for this paper

View statement
Looking for related papers…
Contents