# NOT RUN {
data(LL)
todrop <- c("treated","re78")
imbalance(LL$treated, LL, drop=todrop)
# cem match: automatic bin choice
mat <- cem(treatment="treated", data=LL, drop="re78")
mat
# cem match: user choiced coarsening
re74cut <- hist(LL$re74, br=seq(0,max(LL$re74)+1000, by=1000),plot=FALSE)$breaks
re75cut <- hist(LL$re75, br=seq(0,max(LL$re75)+1000, by=1000),plot=FALSE)$breaks
agecut <- hist(LL$age, br=seq(15,55, length=14),plot=FALSE)$breaks
mycp <- list(re75=re75cut, re74=re74cut, age=agecut)
mat <- cem(treatment="treated",data=LL, drop="re78",cutpoints=mycp)
mat
# cem match: user choiced coarsening, k-to-k matching
mat <- cem(treatment="treated",data=LL, drop="re78",cutpoints=mycp,k2k=TRUE)
mat
# mahalnobis matching: we use MatchIt
if(require(MatchIt)){
mah <- matchit(treated~age+education+re74+re75+black+hispanic+nodegree+married+u74+u75,
distance="mahalanobis", data=LL)
mah
#imbalance
imbalance(LL$treated, LL, drop=todrop, weights=mah$weights)
}
# Multiply Imputed data
# making use of Amelia for multiple imputation
if(require(Amelia)){
data(LL)
n <- dim(LL)[1]
k <- dim(LL)[2]
set.seed(123)
LL1 <- LL
idx <- sample(1:n, .3*n)
invisible(sapply(idx, function(x) LL1[x,sample(2:k,1)] <<- NA))
imputed <- amelia(LL1,noms=c("black","hispanic","treated","married",
"nodegree","u74","u75"))
imputed <- imputed$imputations[1:5]
# without information on which observation has missing values
mat1 <- cem("treated", datalist=imputed, drop="re78")
mat1
# ATT estimation
out <- att(mat1, re78 ~ treated, data=imputed)
# with information about missingness
mat2 <- cem("treated", datalist=imputed, drop="re78", data=LL1)
mat2
# ATT estimation
out <- att(mat2, re78 ~ treated, data=imputed)
}
# }
Run the code above in your browser using DataLab