I’m trying to do a propensity score matching (PSM) in SPSS (yeah, I know it’s easier in Stata and R, but SPSS is what I got to work with my current customer), and I’m using the PSM Macro written by Raynald Levesque (and adapted for use with propensity matching by John Painter):
GET FILE= !pathd + "population.sav". COMPUTE x = RV.UNIFORM(1,1000000) . SORT CASES BY treatm(D) propen x. COMPUTE idx=$CASENUM. SAVE OUTFILE=!pathd + "mydata.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 + "mydata.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 + "mydata.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 + "mydata.sav" / DROP = used mydata key delta. EXECUTE. !DOEND !ENDDEFINE. *////////////////////////////////. SET MPRINT=yes. **************************. *Step 3: insert the number of cases after nbtreat= . **************************. !match nbtreat=27 . SET MPRINT=no. * 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 + "mydata.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 + "mydata and results.sav" EXECUTE. The macro in itself seems to works out pretty well; but I have a couple of questions: 1) It seems, at least when using the illustration data, that the macro removes cases (subjects) from the file. Obviously removing cases is normal in many matching procedures, my question is on what criteria cases are removed in this macro? Are for example cases removed if they have no overlap in propensity scores? Or are they removed if they don’t match within an interval of propensity scores? 2) Not really about the macro, but here goes: Is there another way to do PSM in SPSS v17/18 (that doesn’t involve macros) without using the python plugin? Thanks for helping a stressed out soul (withouht stata). Evo |
Evo,
A comparison case is removed after it is matched to a treatment case. In other words, a comparison case is only used once or not at all. This is known as a "greedy" algorithmn and is explained somewhat in this paper:
The macro can be modified to not drop casses, which can result in the same control being matched to multiple treatments. Which is not unusual either.
Does this answer your quesiton 1? As for question 2, I don't know. But my guess is probably not.
John From: evo <[hidden email]> To: [hidden email] Sent: Tue, February 23, 2010 6:13:03 AM Subject: Propensity Score Matching in SPSS: Question regarding 'the macro' I’m trying to do a propensity score matching (PSM) in SPSS (yeah, I know it’s easier in Stata and R, but SPSS is what I got to work with my current customer), and I’m using the PSM Macro written by Raynald Levesque (and adapted for use with propensity matching by John Painter): GET FILE= !pathd + "population.sav". COMPUTE x = RV.UNIFORM(1,1000000) . SORT CASES BY treatm(D) propen x. COMPUTE idx=$CASENUM. SAVE OUTFILE=!pathd + "mydata.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 + "mydata.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 + "mydata.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 + "mydata.sav" / DROP = used mydata key delta. EXECUTE. !DOEND !ENDDEFINE. *////////////////////////////////. SET MPRINT=yes. **************************. *Step 3: insert the number of cases after nbtreat= . **************************. !match nbtreat=27 . SET MPRINT=no. * 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 + "mydata.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 + "mydata and results.sav" EXECUTE. The macro in itself seems to works out pretty well; but I have a couple of questions: 1) It seems, at least when using the illustration data, that the macro removes cases (subjects) from the file. Obviously removing cases is normal in many matching procedures, my question is on what criteria cases are removed in this macro? Are for example cases removed if they have no overlap in propensity scores? Or are they removed if they don’t match within an interval of propensity scores? 2) Not really about the macro, but here goes: Is there another way to do PSM in SPSS v17/18 (that doesn’t involve macros) without using the python plugin? Thanks for helping a stressed out soul (withouht stata). Evo -- View this message in context: http://old.nabble.com/Propensity-Score-Matching-in-SPSS%3A-Question-regarding-%27the-macro%27-tp27700865p27700865.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
John,
Yes that answered my question. Thank you so much! Evo
|
Hi again,
Do you have any suggestions on how the macro can be modified so that one control can be matched to multiple treatments? Thanks again, Evo
|
In reply to this post by evo
Please guys, i have a problem in using PSM. I need to undertake a propensity score matching in assessing the impact of microfinance to household welfare. i have to compare the impact when customer enters the program and after he has spent 6 months with the program to see if there will be any improvement in his/her income, assets and other welfare indicators. Now i was told to run PSM using spss, and i can not use the syntax thing.
|
try this website. It has a ppt that explains how to use PSM and a zip file with an SPSS example and code. I hope this helps.
From: Peter <[hidden email]> To: [hidden email] Sent: Sat, April 16, 2011 5:51:37 AM Subject: Can Someone Help Me on this! Please guys, i have a problem in using PSM. I need to undertake a propensity score matching in assessing the impact of microfinance to household welfare. i have to compare the impact when customer enters the program and after he has spent 6 months with the program to see if there will be any improvement in his/her income, assets and other welfare indicators. Now i was told to run PSM using spss, and i can not use the syntax thing. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Propensity-Score-Matching-in-SPSS-Question-regarding-the-macro-tp1092170p4307296.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by evo
Hi I am new to this group. I have SPSS 20. Could someone tell me if the above syntax needs to be modified to use with SPSS 20?
Thanks for your help! |
Free forum by Nabble | Edit this page |