#------------------------------------
#code for Chapter 5 "Propensity Score Matching" of book:
#Leite, W. L. (2017). Practical propensity score methods using R.
#Thousand Oaks, CA: Sage.
#PART 3 - VARIABLE RATIO 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 variable ratio greedy matching
#with replacement and with caliper to estimate the ATT
#load data
load(file="Chapter5_data_with_propensity_scores_and_formula.rData")
library(Matching) #load necessary package
#Maching requires the treatment indicator to be logical (TRUE/FALSE)
data$childCare <- ifelse(data$childCare==1, TRUE,FALSE)
greedyMatching2 <- with(data,
Match(Y=C0338600, Tr=childCare, X=logitPScores,
estimand = "ATT", M = 1,
caliper = 0.25, replace=TRUE, ties=TRUE))
#evaluate covariate balance
balance.greedyMatching2 <- MatchBalance(psFormula, data = data, match.out = greedyMatching2,
ks = F, paired=F)
balance.greedyMatching2After <- unlist(balance.greedyMatching2$AfterMatching)
#summarize only the standized mean differences (they have been multiplied by 100, so I divided by 100)
#see details in ?balanceUV
summary(abs(balance.greedyMatching2After[names(balance.greedyMatching2After)=="sdiff"]/100))
table(abs(balance.greedyMatching2After[names(balance.greedyMatching2After)=="sdiff"]/100)>0.1)
#-------------------------
#estimate ATT with variable ratio greedy matching
#with replacement and within 0.25 caliper
#standard error is obtained with Abadie and Imbens (2006) estimator
summary(greedyMatching2)
#=======================================
#Rosenbaum Sensitivity Test for Wilcoxon Signed Rank P-Value
#with genetic matching
library(rbounds)
psens(greedyMatching2, Gamma=3, GammaInc=.1)