#=============================================
#code for Chapter 5 "Propensity Score Matching" of book:
#Leite, W. L. (2017). Practical propensity score methods using R.
#Thousand Oaks, CA: Sage.
#PART 5 - GENETIC MATCHING WITH PROPENSITY SCORES AND SENSITIVITY ANALYSIS
#
#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 genetic matching for estimating the ATT
#with variable ratio matching with replacement
#based on the propensity score only and without a caliper
#load data
load(file="Chapter5_data_with_propensity_scores_and_formula.rData")
#library for propensity score matching
library(MatchIt)
#convert the treatment from 0/1 to TRUE/FALSE as required by GenMatch
data$childCare <- ifelse(data$childCare==1, TRUE, FALSE)
#perform matching
geneticMatching2 <- matchit(psFormula,distance=data$logitPScores,
data = data, method = "genetic",pop.size=1000,
fit.func="pvals",
estimand="ATT", replace=T, ties=T)
#diagnose covariate balance
(balance.geneticMatching2 <- summary(geneticMatching2, standardize=T))
#obtain the summary of balance aftdr matching
summary(abs(balance.geneticMatching2$sum.matched$"Std. Mean Diff."))
table(abs(balance.geneticMatching2$sum.matched$"Std. Mean Diff.") > 0.1)
#================================================
#estimate ATT
#using regression
#obtain matched data
data.geneticMatching2 <- match.data(geneticMatching2)
#set up the survey design
library(survey)
design.geneticMatching2 <- svydesign(ids=~1, weights=~weights,
data=data.geneticMatching2)
#fit regression model to estimate the ATT
model.geneticMatching2 <- svyglm(C0338600~childCare, design.geneticMatching2, family=gaussian())
summary(model.geneticMatching2)