#code for Chapter 3 "Propensity Score Weighting" of book: #Leite, W. L. (2017). Practical propensity score methods using R. #Thousand Oaks, CA: Sage. # #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 #============================================ #Estimate the ATT with multiple imputed datasets #Estimate the effect of high school student participation in #career academies on future income #using data from the Education Longitudinal Study (ELS) #load required survey library require(survey) options(survey.lonely.psu = "adjust") #load mitools library require(mitools) #load object with multiple imputed datasets load(file="Chapter3_ELS_all_imputed_datasets_with_weights.Rdata") #first, add the final weight to imputed datasets allImputations <- update(allImputations, finalWeightATT = bystuwt*weightATT) #normalize the final weight allImputations <- update(allImputations, finalWeightATT = finalWeightATT/mean(finalWeightATT)) #create survey design object for multiple imputed dastests surveyDesign2006MI <- svydesign(ids=~psu, strata=~STRAT_ID, weights=~finalWeightATT, data = allImputations, nest=T) #estimate the ATT with regression in each imputed dataset outcomeModel2006MI <- with(surveyDesign2006MI, svyglm(F2ERN5P2~treat)) #combine estimates from multiplle imputed datasets resultsModel2006MI <- MIcombine(outcomeModel2006MI) summary(resultsModel2006MI) #save all objects save(list=ls(), file="Chapter_3_treatment_effect_from_all_imputed_datasets.Rdata",compress=T) #=====