# NOT RUN {
library(optmatch)
data(nuclearplants)
#require exact match on variables ne and pt, use rank-based Mahalanobis distance
my.dist.struct <- build.dist.struct(z = nuclearplants$pr,
X = subset(nuclearplants[c('date','t1','t2','cap','bw','cum.n')]),
exact = paste(nuclearplants$ne, nuclearplants$pt, sep = '.'))
#match with refined covariate balance, first on ct then on (ct x bw)
rcbalance(my.dist.struct, fb.list = list('ct',c('ct','bw')),
treated.info = nuclearplants[which(nuclearplants$pr ==1),],
control.info = nuclearplants[which(nuclearplants$pr == 0),])
#repeat the same match using match_on tool from optmatch and regular Mahalanobis distance
exact.mask <- exactMatch(pr ~ ne + pt, data = nuclearplants)
my.dist.matrix <- match_on(pr ~ date + t1 + t2 + cap + bw + cum.n,
within = exact.mask, data = nuclearplants)
match.matrix <-
rcbalance(my.dist.matrix*100, fb.list = list('ct',c('ct','bw')),
treated.info = nuclearplants[which(nuclearplants$pr ==1),],
control.info = nuclearplants[which(nuclearplants$pr == 0),])
# }
Run the code above in your browser using DataLab