data(schools)
# Kreft and De Leeuw, Introducing Multilevel Modeling, Sage (1988).
# The data set is the subsample of NELS-88 data consisting of 10 handpicked schools
# from the 1003 schools in the full data set.
# Let us consider the following variables:
X<-schools$ses # (socio economic status)
Y<-schools$math #(mathematics score)
Tr<-ifelse(schools$homework > 1, 1 ,0)
Group<-schools$schid #(school ID)
# Multivariate Matching on covariates X
### Matching within schools
mw <- CMatch(type="within",Y=Y, Tr=Tr, X=X, Group=Group, caliper=0.1)
# Balance statistics for X variables(s) before and after matching within schools.
CMatchBalance(Tr~X,data=schools,match.out = mw)
### Match preferentially within school
# i.e. first match within schools
# then tries to match remaining units between schools
mpw <- CMatch(type="pwithin",Y=schools$math, Tr=Tr, X=schools$ses,
Group=schools$schid, caliper=0.1)
# examine covariate balance of variable(s) X before and after preferential matching within schools
CMatchBalance(Tr~X, data=schools, match.out = mpw)
Run the code above in your browser using DataLab