
Heterogeneity-robust DiD by sub-group / moderator quantile
Source:R/did.R
morie_did_heterogeneous.RdSplits 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).
Examples
if (morie_crypto_liboqs_available()) {
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
}