data("lalonde", package = "MatchIt")
# Fit the model
fit <- lm(re78 ~ treat * (age + educ + race +
married + re74 + re75),
data = lalonde)
# Simulate coefficients
set.seed(123)
s <- sim(fit, n = 100)
# Average adjusted predictions for `treat` within
# subsets of `race`
est_b <- sim_ame(s, var = "treat", verbose = FALSE,
subset = race == "black")
est_b
est_h <- sim_ame(s, var = "treat", verbose = FALSE,
subset = race == "hispan")
est_h
# Compute differences between adjusted predictions
est_b <- transform(est_b,
diff = `E[Y(1)]` - `E[Y(0)]`)
est_b
est_h <- transform(est_h,
diff = `E[Y(1)]` - `E[Y(0)]`)
est_h
# Bind estimates together after renaming
names(est_b) <- paste0(names(est_b), "_b")
names(est_h) <- paste0(names(est_h), "_h")
est <- cbind(est_b, est_h)
est
# Compute difference in race-specific differences
est <- transform(est,
`diff-diff` = .b6 - .b3)
summary(est,
parm = c("diff_b", "diff_h", "diff-diff"))
# Remove last quantity by using `NULL`
transform(est, `diff-diff` = NULL)
Run the code above in your browser using DataLab