################################################### ### chunk number 1: ################################################### library("MatchIt") data("lalonde") ################################################### ### chunk number 2: ################################################### m.out <- matchit(treat ~ educ + black + hispan, data = lalonde, method = "exact") ################################################### ### chunk number 3: ################################################### m.out <- matchit(treat ~ re74 + re75 + educ + black + hispan + age, data = lalonde, method = "subclass") ################################################### ### chunk number 4: ################################################### m.out <- matchit(treat ~ re74 + re75 + educ + black + hispan + age, data = lalonde, method = "nearest") ################################################### ### chunk number 5: ################################################### m.out <- matchit(treat ~ re74 + re75 + age + educ, data = lalonde, method = "optimal", ratio = 2) ################################################### ### chunk number 6: ################################################### m.out <- matchit(treat ~ age + educ + black + hispan + married + nodegree + re74 + re75, data = lalonde, method = "full") ################################################### ### chunk number 7: ################################################### m.out <- matchit(treat ~ age + educ + black + hispan + married + nodegree + re74 + re75, data = lalonde, method = "genetic") ################################################### ### chunk number 8: ################################################### m.data <- match.data(m.out) ################################################### ### chunk number 9: ################################################### library("Zelig") ################################################### ### chunk number 10: ################################################### m.out0 <- matchit(treat ~ age + educ + black + hispan + nodegree + married + re74 + re75, method = "nearest", discard = "hull.control", data = lalonde) ################################################### ### chunk number 11: ################################################### z.out0 <- zelig(re78 ~ treat + age + educ + black + nodegree + re74 + re75, data = match.data(m.out0), model = "ls") ################################################### ### chunk number 12: ################################################### x.out0 <- setx(z.out0, treat=0) x1.out0 <- setx(z.out0, treat=1) ################################################### ### chunk number 13: ################################################### s.out0 <- sim(z.out0, x = x.out0, x1 = x1.out0) summary(s.out0) ################################################### ### chunk number 14: ################################################### m.out1 <- matchit(treat ~ age + educ + black + hispan + nodegree + married + re74 + re75, method = "nearest", data = lalonde) ################################################### ### chunk number 15: ################################################### z.out1 <- zelig(re78 ~ age + educ + black + hispan + nodegree + married + re74 + re75, data = match.data(m.out1, "control"), model = "ls") ################################################### ### chunk number 16: ################################################### x.out1 <- setx(z.out1, data = match.data(m.out1, "treat"), cond = TRUE) s.out1 <- sim(z.out1, x = x.out1) ################################################### ### chunk number 17: ################################################### summary(s.out1) ################################################### ### chunk number 18: ################################################### z.out2 <- zelig(re78 ~ age + educ + black + hispan + nodegree + married + re74 + re75, data = match.data(m.out1, "treat"), model = "ls") ################################################### ### chunk number 19: ################################################### x.out2 <- setx(z.out2, data = match.data(m.out1, "control"), cond = TRUE) s.out2 <- sim(z.out2, x = x.out2) ################################################### ### chunk number 20: ################################################### ate.all <- c(s.out1$qi$att.ev, -s.out2$qi$att.ev) ################################################### ### chunk number 21: ################################################### mean(ate.all) sd(ate.all) quantile(ate.all, c(0.025, 0.975)) ################################################### ### chunk number 22: ################################################### m.out2 <- matchit(treat ~ age + educ + black + hispan + nodegree + married + re74 + re75, data = lalonde, method = "subclass", subclass = 4) ################################################### ### chunk number 23: ################################################### z.out3 <- zelig(re78 ~ re74 + re75 + distance, data = match.data(m.out2, "control"), model = "ls", by = "subclass") ################################################### ### chunk number 24: ################################################### x.out3 <- setx(z.out3, data = match.data(m.out2, "treat"), fn = NULL, cond = TRUE) s.out3 <- sim(z.out3, x = x.out3) summary(s.out3) ################################################### ### chunk number 25: ################################################### summary(s.out3, subset = 2) ################################################### ### chunk number 26: ################################################### m.out <- matchit(treat ~ educ + black + hispan, data = lalonde, method = "exact") m.data <- match.data(m.out) ## weighted diff in means weighted.mean(m.data$re78[m.data$treat == 1], m.data$weights[m.data$treat==1]) - weighted.mean(m.data$re78[m.data$treat==0], m.data$weights[m.data$treat==0]) ## weighted least squares without covariates zelig(re78 ~ treat, data = m.data, model = "ls", weights = "weights") ## weighted least squares with covariates zelig(re78 ~ treat + black + hispan + educ, data = m.data, model = "ls", weights = "weights") ################################################### ### chunk number 27: ################################################### m.out1 <- matchit(treat ~ re74 + re75 + age + educ, data = lalonde, method = "nearest", distance = "logit") ################################################### ### chunk number 28: ################################################### m.data1 <- match.data(m.out1) ################################################### ### chunk number 29: ################################################### summary(m.data1) ################################################### ### chunk number 30: ################################################### m.data2 <- match.data(m.out1, group = "treat") summary(m.data2) m.data3 <- match.data(m.out1, group = "control") summary(m.data3) ################################################### ### chunk number 31: ################################################### unmatched.data <- lalonde[!row.names(lalonde)%in%row.names(match.data(m.out1)),] ################################################### ### chunk number 32: ################################################### m.out2 <- matchit(treat ~ re74 + re75 + age + educ, data = lalonde, method = "subclass") m.data4 <- match.data(m.out2, subclass = "block", weights = "w", distance = "pscore") names(m.data4)