#===================================================== #code for Chapter 5 "Propensity Score Matching" of book: #Leite, W. L. (2017). Practical propensity score methods using R. #Thousand Oaks, CA: Sage. #PART 2 - ONE TO ONE GREEDY MATCHING WITH 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 One-to-One greedy matching with replacement and #with caliper to estimate the ATT #load data load(file="Chapter5_data_with_propensity_scores_and_formula.rData") library(MatchIt) #library for propensity score matching greedyMatching <- matchit(psFormula,distance=data$logitPScores, data = data, method = "nearest",ratio=1,replace=T,caliper=0.25) #diagnose covariate balance (balance.greedyMatching <- summary(greedyMatching, standardize=T)) #obtain the summary of balance aftdr matching summary(abs(balance.greedyMatching$sum.matched$"Std. Mean Diff.")) table(abs(balance.greedyMatching$sum.matched$"Std. Mean Diff.") > 0.1) #estimate ATT with one-to-one greedy matching with replacement #within 0.25 caliper #obtain matched data data.greedyMatching <- match.data(greedyMatching) library(survey) design.greedyMatching <- svydesign(ids=~1, weights=~weights, data=data.greedyMatching) #estimate the ATT model.greedyMatching <- svyglm(C0338600~childCare, design.greedyMatching, family=gaussian()) summary(model.greedyMatching)