#=========================================================== #code for Chapter 5 "Propensity Score Matching" of book: #Leite, W. L. (2017). Practical propensity score methods using R. #Thousand Oaks, CA: Sage. #PART 6 - OPTIMAL ONE TO ONE MATCHING WITHOUT REPLACEMENT # #this is the code that was used to generate the example results in the book #As the R software and the R packages used in this example are updated frequently #some incompatibilities between the current code and new R versions or package versions #may appear #Any updates to the code will be posted at: # http://www.practicalpropensityscore.com #This example estimates the effect of mothers having a job #that provides or subsidizes child care #on the length that they breastfeed their children #National Longitudinal Survey of Youth 1979 (NLSY79) #and the NLSY79 Children and Youth #Perform optimal one-to-one matching without replacement library(MatchIt) #library for propensity score matching library(optmatch) #load data load(file="Chapter5_data_with_propensity_scores_and_formula.rData") #run the matching altorighm optimalMatching <- matchit(psFormula,distance=data$logitPScores, data = data, method = "optimal", ratio=1) #diagnose covariate balance (balance.optimalMatching <- summary(optimalMatching, standardize=T)) #obtain the summary of balance after matching summary(abs(balance.optimalMatching$sum.matched$"Std. Mean Diff.")) table(abs(balance.optimalMatching$sum.matched$"Std. Mean Diff.") > 0.1) #------------------------------------------ #estimate ATT with one-to-one optimal matched data #using regression #obtain matched data data.optimalMatching <- match.data(optimalMatching) library(survey) design.optimalMatching <- svydesign(ids=~subclass, weights=~weights, data=data.optimalMatching) #fit regression model model.optimalMatching <- svyglm(C0338600~childCare, design.optimalMatching, family=gaussian()) summary(model.optimalMatching)