/* Core code written by Raynald Levesque */ /* Adapted for use with propensity matching by John Painter Feb 2004*/ /* Program developed and tested with SPSS 11.5 */ /* Procedure will find best match for each treatment case from the control cases, */ /* control case is then removed and not reconsidered for subsequent matches */ /* Order of cases is randomized */ /* Requirement: The number of Treatment cases must be known */ /* Change file path here only */ DEFINE !pathd() 'J:\Research\R&E Team Folders\Aaron Horenstein\PSM Macro\' !ENDDEFINE. ******************** . * Perform logistical regression to compute propensity score . ******************* . GET FILE=!pathd + "Population.sav". LOGISTIC REGRESSION VARIABLES TREATM /METHOD=ENTER AGE ABC DEF HIJ SEX /SAVE=PRED /CRITERIA=PIN(.05) POUT(.10) ITERATE(20) CUT(.5). RENAME VARIABLES (PRE_1 = propen). *********************. * Note number of Treatment cases and place number after MACRO CALL near end ofthis program . ********************* . FREQUENCIES VARIABLES=treatm /ORDER= ANALYSIS . SAVE OUTFILE=!pathd + "Population1.sav" . ********************* . ** End Preparation . ********************* . GET FILE= !pathd + "Population1.sav". COMPUTE x = RV.UNIFORM(1,1000000) . SORT CASES BY treatm(D) propen x. COMPUTE idx=$CASENUM. SAVE OUTFILE=!pathd + "PopulationPSM.sav". * Erase the previous temporary result file, if any. ERASE FILE=!pathd + "results.sav". COMPUTE key=1. SELECT IF (1=0). * Create an empty data file to receive results. SAVE OUTFILE=!pathd + "results.sav". exec. ********************************************. * Define a macro which will do the job. ********************************************. SET MPRINT=no. *////////////////////////////////. DEFINE !match (nbtreat=!TOKENS(1)) !DO !cnt=1 !TO !nbtreat GET FILE=!pathd + "PopulationPSM.sav". SELECT IF idx=!cnt OR treatm=0. * Select one treatment case and all control . DO IF $CASENUM=1. COMPUTE #target=propen. ELSE. COMPUTE delta=propen-#target. END IF. EXECUTE. SELECT IF ~MISSING(delta). IF (delta<0) delta=-delta. SORT CASES BY delta. SELECT IF $CASENUM=1. COMPUTE key=!cnt . SAVE OUTFILE=!pathd + "used.sav". ADD FILES FILE=* /FILE=!pathd + "results.sav". SAVE OUTFILE=!pathd + "results.sav". ************************************************ Match back to original and drop case from original . GET FILE= !pathd + "PopulationPSM.sav". SORT CASES BY idx . MATCH FILES /FILE=* /IN=mydata /FILE=!pathd + "used.sav" /IN=used /BY idx . SELECT IF (used = 0). SAVE OUTFILE=!pathd + "PopulationPSM.sav" / DROP = used mydata key delta. EXECUTE. !DOEND !ENDDEFINE. *////////////////////////////////. SET MPRINT=yes. **************************. * MACRO CALL (first insert the number of cases after nbtreat below) . **************************. !match nbtreat=27. * Sort results file to allow matching. GET FILE=!pathd + "results.sav". SORT CASES BY key. SAVE OUTFILE=!pathd + "results.sav". ******************. * Match each treatment cases with the most similar non treatment case. * To include additional variables from original file list them on the RENAME subcommand below . ******************. GET FILE=!pathd + "PopulationPSM.sav". MATCH FILES /FILE=* /FILE=!pathd + "results.sav" /RENAME (idx = d0) (id=id2) (propen=propen2) (treatm=treatm2) (key=idx) /BY idx /DROP= d0 x. FORMATS delta propen propen2 (F10.8). SAVE OUTFILE=!pathd + "PopulationPSM and results.sav". EXECUTE . * That's it!.