Skip to contents

comp_did() is the user-facing entry point for the package. It accepts a two-sided formula such as y ~ x1 + x2, or separate column-name arguments, builds the validated internal data object, fits nuisance functions, and returns the non-stationary doubly robust ATT estimator for repeated cross-section data with compositional changes.

Usage

comp_did(
  yname,
  tname,
  dname,
  xformla = NULL,
  data,
  xformula = NULL,
  continuous = NULL,
  unordered = NULL,
  ordered = NULL,
  nuisance_method = c("dml", "loo", "parametric"),
  stationary = FALSE,
  stationarity_test = FALSE,
  stabilized = TRUE,
  i.weights = NULL,
  boot = FALSE,
  nboot = NULL,
  boot_type = c("mammen", "normal", "bayes", "wild"),
  ps_min_treat = 0.005,
  inffunc = TRUE,
  ...
)

Arguments

yname

Name of the outcome column, or a two-sided formula such as y ~ x1 + x2. When a formula is supplied, tname, dname, and data must be named explicitly.

tname

Name of the post-period indicator column. Values must be coded as 0 for the pre period and 1 for the post period.

dname

Name of the treatment-group indicator column. Values must be coded as 0 for controls and 1 for the treated group.

xformla, xformula

Optional one-sided formula for covariates. xformula is the preferred spelling; xformla is accepted for users familiar with DID-package style arguments. When supplied, the resulting model matrix columns are treated as continuous covariates. For nuisance_method = "loo", formula covariates must be numeric; use continuous, unordered, and ordered instead when the local-polynomial mixed-data kernels should distinguish covariate types.

data

Data frame containing all analysis variables.

continuous, unordered, ordered

Optional covariate column names or positions identifying continuous, unordered discrete, and ordered discrete covariates. These are passed to make_did_dp().

nuisance_method

Either "dml" for cross-fitted nuisance estimation, "loo" for local-polynomial nuisance estimation, or "parametric" for fixed-dimensional parametric first steps.

stationary

Logical. If TRUE, also compute the stationary repeated cross-section estimator.

stationarity_test

Logical. If TRUE, compute the test comparing stationary and non-stationary estimates. The nonparametric and DML paths report the existing Hausman-type comparison; the parametric path reports the corresponding Wald equality test. This requires stationary = TRUE and influence functions.

stabilized

Logical. If TRUE, use stabilized weights in the DR second-stage estimators.

i.weights

Optional non-negative sampling weights.

boot

Logical. If TRUE, use multiplier-bootstrap inference.

nboot

Number of bootstrap draws when boot = TRUE.

boot_type

Multiplier-bootstrap type.

ps_min_treat

Minimum treated-group propensity used in stationary weights when stationary = TRUE or stationarity_test = TRUE. The default (0.005) clips fitted treated propensities to [ps_min_treat, 1 - ps_min_treat]; set to 0 to disable clipping.

inffunc

Logical. If TRUE, return influence functions.

...

Additional arguments passed to att_estimate().

Value

A "compdid" object containing the ATT fit, nuisance metadata, the processed data object, and optionally stationary-fit and test results.

Examples

set.seed(123)
d <- simulate_comp_did(n = 200)
out <- comp_did(
  y ~ x1 + x2 + x3 + x4 + x5 + x6,
  tname = "post",
  dname = "d",
  data = d,
  K = 2
)
out
#> Compositional-change DiD
#> Nuisance method: dml 
#> Nuisance backend: custom 
#> ATT: 9.566 
#> SE : 7.618 
#> 95% CI: [-5.366, 24.5]