
Repeated cross-section DiD (optionally weighted)
Source:R/did.R
morie_did_repeated_cross_section.RdSame specification as morie_did_2x2 but accepts a survey
weight column. When weights is supplied, weighted least
squares is used.
Usage
morie_did_repeated_cross_section(
data,
outcome,
treatment,
post,
covariates = NULL,
weights = NULL,
cluster = NULL,
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.
- covariates
Optional character vector of covariate column names.
- weights
Optional column of (sampling / survey) weights.
- cluster
Optional cluster ID column for CR1 standard errors.
- alpha
Significance level for confidence intervals (default 0.05).
Value
A list of class results; see morie_did_2x2.
Examples
if (requireNamespace("fixest", quietly = TRUE)) {
set.seed(1)
n <- 400
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,
w = runif(n, 0.5, 2)
)
res <- morie_did_repeated_cross_section(df, "y", "d", "post",
weights = "w"
)
res$estimate
}
#> [1] 0.5353118