Skip to contents

Splits the sample by quantiles (or categories) of a moderator and estimates separate 2x2 DiDs.

Usage

morie_did_heterogeneous(
  data,
  outcome,
  treatment,
  post,
  moderator,
  covariates = NULL,
  cluster = NULL,
  n_quantiles = 4L,
  alpha = 0.05
)

Arguments

data

A data frame containing the outcome, treatment, post and any covariate columns.

outcome

Name of the outcome column.

treatment

Name of the binary (0/1) treatment-group column.

post

Name of the binary (0/1) post-period column.

moderator

Column to split on.

covariates

Optional character vector of covariate column names.

cluster

Optional cluster ID column for CR1 standard errors.

n_quantiles

Number of quantile bins if the moderator is continuous.

alpha

Significance level for confidence intervals (default 0.05).

Value

A data frame with one row per stratum.

Examples

set.seed(1)
n <- 600
d <- rbinom(n, 1, 0.5); p <- rbinom(n, 1, 0.5)
y <- 1 + 0.3 * d + 0.4 * p + 0.5 * d * p + rnorm(n, sd = 0.5)
df <- data.frame(y = y, d = d, post = p, mod = rnorm(n))
out <- morie_did_heterogeneous(df, "y", "d", "post",
                               moderator = "mod", n_quantiles = 3L)
out
#>              group  estimate std_error  ci_lower  ci_upper      p_value   n
#> interaction      1 0.4788164 0.1450669 0.1944905 0.7631422 0.0009645786 200
#> interaction1     2 0.4123132 0.1545397 0.1094208 0.7152055 0.0076302585 200
#> interaction2     3 0.5280850 0.1549711 0.2243471 0.8318228 0.0006552859 200