Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xtifedml

Double Machine Learning for Panel Models with Interactive Fixed Effects

License: GPL v2 R >= 3.5.0

The xtifedml package implements Double Machine Learning for partially linear regression models for panel data with interactive fixed effects (panel DML-IFE), as in Binzhi et al. (2026).

The package follows the object-oriented architecture of DoubleML (Bach et al., 2024) and is built on top of xtdml (Polselli, 2025), which handles additive one-way fixed effects. It uses the mlr3 ecosystem for nuisance-function estimation, keeping the same R6-style API.

The Partially Linear Panel Regression Model with Interactive Fixed Effects

xtifedml estimates the structural (causal) parameter from panel data models of the form

$$ Y_{it} = \theta_0 V_{it} + l_0(X_{it}) + \lambda_i' f_t + U_{it}, $$

$$ D_{it} = m_0(X_{it}) + \gamma_i' f_t + V_{it}, $$

$$ X_{it} = \Gamma_i' f_t + E_{it}, $$

where

  • $Y_{it}$ is the outcome, $D_{it}$ the treatment, $X_{it}$ the high-dimensional covariates;
  • $\theta_0$ is the structural (causal) parameter to estimate;
  • $l_0$ and $m_0$ are (possibly nonlinear) nuisance functions to learn from the data;
  • $\lambda_i' f_t$, $\gamma_i' f_t$, and $\Gamma_i' f_t$ are interactive (factor-structures) fixed effects, with unobserved individual loadings ${\lambda_i,\gamma_i, \Gamma_i}$ interacted with unobserved common time factors $f_t$;
  • $U_{it}$, $V_{it}$, and $E_{it}$ are disturbances.

Note: The model is written using the 'partialled-out' approach of Robinson (1988) with $V_{it}$ rather than $D_{it}$ representing the orthogonalised treatment. The PLPR model can be specified using the alternative `IV approach', i.e.,

$$ Y_{it} = \theta_0 D_{it} + g_0(Xit) + \lambda_i^\prime f_t +U_{it}, $$

where $g_0(\cdot)\neq l_0(\cdot)$, which is less attractive because model fitting generally requires iterating between learning $g_0(\cdot)$ and estimating $\theta_0$ until convergence.

What the user controls

The user can run the estimator directly on a panel data.frame; no manual data preparation is required. The two main choices are:

  1. Panel-data approach: approach = "pcce" (Pooled Common Correlated Effects), implements a projection-based defactorisation following Pesaran (2006), as adapted by Rucker (2025), which approximates the factor space using cross-sectional averages before applying DML; or approach = "pooled", which does not transform the data.

  2. Covariate transformation: transformX = c("no", "minmax", "poly"), default "no".

    • "no" leaves $X$ untransformed — recommended for tree-based learners.
    • "minmax" applies min–max normalization $x' = (x - x_{\min})/(x_{\max} - x_{\min})$ — recommended for neural networks.
    • "poly" adds polynomials up to order three and pairwise/three-way interactions — recommended for Lasso.

Note Two orthogonal scores are available via the score argument of xtifedml_plr$new(): "orth-PO" (partialling-out, requires ml_l and ml_m) and "orth-IV" (IV-type orthogonal score, additionally requires ml_g).

Installation

Install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("POLSEAN/xtifedml")

Quick start

A minimal end-to-end example using a regression tree (rpart) as the nuisance learner:

library(xtifedml)
library(mlr3)
library(rpart)
library(mlr3misc)
library(mlr3tuning)

set.seed(1234)

# 1. Simulate panel data with interactive fixed effects
data <- make_plpr_data(n_obs = 100, t_per = 5, dim_x = 10, theta = 1,
                        r = 2, rho = 0.6, dgp = "discontinuous")

x_cols <- paste0("X", 1:10)

# 2. Build the xtifedml data backend
obj_xtifedml_data <- xtifedml_data_df(
  data,
  x_cols   = x_cols,
  y_col    = "y",
  d_cols   = "d",
  panel_id = "id",
  time_id  = "time",
  approach = "pcce"
)

# 3. Learners
ml_l <- lrn("regr.rpart")
ml_m <- lrn("regr.rpart")

# 4. Set DML estimation environment
xtifedml_obj <- xtifedml_plr$new(obj_xtifedml_data,
                                  ml_l = ml_l, ml_m = ml_m,
                                  n_folds = 5, score = "orth-PO")

# 5. Tune and fit
param_grid <- list(
  "ml_l" = ps(cp = p_dbl(0.001, 0.1), minsplit = p_int(5, 30)),
  "ml_m" = ps(cp = p_dbl(0.001, 0.1), minsplit = p_int(5, 30))
)

tune_settings <- list(
  n_folds_tune = 5,
  rsmp_tune    = mlr3::rsmp("cv", folds = 5),
  terminator   = mlr3tuning::trm("evals", n_evals = 10),
  tuner        = mlr3tuning::tnr("grid_search", resolution = 10)
)

xtifedml_obj$tune(param_set = param_grid, tune_settings = tune_settings)
xtifedml_obj$fit()

# 6. Print estimated objects
xtifedml_obj$print()
xtifedml_obj$summary()

Inspecting the results

After fitting, the main quantities are available as fields and methods on the xtifedml_plr object:

Field / method Meaning
coef_theta Point estimate of the structural parameter $\theta_0$
se_theta Standard error of $\hat\theta$
pval_theta Two-sided $p$-value
confint() Confidence interval (default 95%)
model_rmse Overall model RMSE
rmses RMSE of each nuisance learner (ml_l, ml_m, ml_g)
params Tuned hyperparameters
get_panel_info() Stored panel data information (n_obs, n_subjects, n_groups)

Main functions

Function Purpose
xtifedml_plr R6 class implementing DML for partially linear panel models with interactive fixed effects.
xtifedml_data Constructor for the data backend used by the estimator.
xtifedml_data_df() Wrapper that builds an xtifedml_data object directly from a data.frame.
make_plpr_data() Simulates panel data from a partially linear regression model with interactive fixed effects.

Full documentation is available via ?xtifedml_plr, ?xtifedml_data_df, etc.

Dependencies

xtifedml requires R (>= 3.5.0) and imports R6 (>= 2.4.1), data.table (>= 1.12.8), mlr3 (>= 1.3.0), mlr3tuning (>= 1.5.0), mlr3learners (>= 0.13.0), mlr3misc (>= 0.19.0), mvtnorm, clusterGeneration, magrittr, dplyr, MLmetrics, checkmate. Suggested: rpart, mlr3pipelines, bbotk (>= 1.8.0).

References

  • Bach, P., Chernozhukov, V., Kurz, M. S., Spindler, M., and Klaassen, S. (2024). DoubleML — An Object-Oriented Implementation of Double Machine Learning in R. Journal of Statistical Software, 108(3), 1–56. doi:10.18637/jss.v108.i03
  • Chernozhukov, V., Chetverikov, D., Demirer, M., Duflo, E., Hansen, C., Newey, W., and Robins, J. (2018). Double/debiased machine learning for treatment and structural parameters. The Econometrics Journal, 21(1), C1–C68.
  • Clarke S. P., and Polselli A., (2026). Double machine learning for static panel models with fixed effects, The Econometrics Journal, Volume 29, Issue 1, January 2026, Pages 69–86. https://doi.org/10.1093/ectj/utaf011
  • Polselli, A. (2025). xtdml: Double Machine Learning Estimation to Static Panel Data Models with Fixed Effects in R. arXiv preprint arXiv:2512.15965.
  • Rücker, M., Vogt, M., Linton, O., and Walsh, C. (2025). Estimation and inference in high- dimensional panel data models with interactive fixed effects. Quantitative Economics, 16(4):1457–1509.

About

Double Machine Learning for Static Panel Models with Interactive Fixed Effects

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages