LEVESQUE/PAINTER/CLARK MACRO FOR N-N MATCHING

By William Holmes

 

This program estimates propensity scores and allows transforming them with a logit transform. You may skip the transform if you wish. The propensity, PRE_1, should be renamed PROPEN if you do not use the transform. The covariates, COV1 – COV10 should be replaced with the confounder names.

The Macro follows.

*/////////////////////////////////////////////.

* This computes the propensity scores.

LOGISTIC REGRESSION VARIABLES treatm

  /METHOD=ENTER Cov1 Cov2 Cov3 Cov4 Cov5 Cov6 Cov7 Cov8 Cov9 Cov10

  /SAVE=PRED

  /CRITERIA=PIN(.05) POUT(.10) ITERATE(20) CUT(.5).

* This computes the logit transform on the propensity scores.

COMPUTE propen=ln(PRE_1/(1-PRE_1)).

EXECUTE.

***************************************

**Use independent t-tests and SB estimates to determine if the covariates are balanced.

T-TEST GROUPS=treatm(1 0)

  /MISSING=ANALYSIS

  /VARIABLES=Cov1 Cov2 Cov3 Cov4 Cov5 Cov6 Cov7 Cov8 Cov9 Cov10

  /CRITERIA=CI(.95).

 

/* Core code written by Raynald Levesque and */

/* Adapted for use with propensity matching by John Painter (Feb 2004)*/

/* Adpated for caliper matching by M.H. Clark (October 2010) */

/* Adapted to estimate covariate balance after matching by M.H. Clark (September 2012)*/

/* Program developed and tested with SPSS 20 */

/* 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 random */

/* For any analysis the number of Treatment cases and covariates must be specified manually */

/* and the 'Regression Modelsle' add-on module must be available  */

/* Change file path here and only here */

 

DEFINE !pathd() 'E:\AEA\AEA 2012\' !ENDDEFINE.

 

*********************.

* Note number of Treatment cases and place number after MACRO CALL near end ofthis program .

********************* .

 

********************* .

** End Preparation .

********************* .

GET FILE= !pathd + "CCMatchData.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.

 

**************************.

* MACRO CALL (first insert the number of treatment cases after nbtreat below) .

**************************.

!match nbtreat=120.

 

* 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 .

* Add names of the covariates below so that each covarite is recoded into Cov#. Example: (Age = cov1).

******************.

GET FILE=!pathd + "mydata.sav".

MATCH FILES /FILE=*

 /FILE=!pathd + "results.sav"

 /RENAME (idx = d0) (StudyID=id2) (propen=propen2)

  (treatm=treatm2) (outcome=outcome2) (key=idx)

  (Cov1=ACT) (Cov2=GPA) (Cov3=IntMot) (Cov4=ExtMot) (Cov5=Extraversion)

  (Cov6=Agreeableness) (Cov7=Neuroticism) (Cov8=Loneliness) (Cov9=AfricanAm) (Cov10=Caucasian)

 

 /BY idx

 /DROP= d0.

FORMATS delta propen propen2  (F10.8).

SAVE OUTFILE=!pathd + "mydata and results.sav".

EXECUTE.

 

* That's it!.

 

* Clark's addition (October 2010).

* This identifies and removes poor matches; those with delta > .25SD.

*// Change c to .25(1.8045), where1.8045 is the standard deviation of the transformed propensity scores.

COMPUTE c = .4511.

FILTER OFF.

USE ALL.

SELECT IF (delta < c).

EXECUTE.

*///////////////////////////////////////*

* Paired t-test to assess difference in outcomes.

T-TEST PAIRS=outcome WITH outcome2 (PAIRED)

  /CRITERIA=CI(.9500)

  /MISSING=ANALYSIS.

 

* Paired t-tests to assess difference in covariates .

*data must be reorganized to be consistent with a paired t-test.

*if you do not wish to do a paired t-test, you may use the initial t-test commands.

T-TEST PAIRS=Cov1 Cov2 Cov3 Cov4 Cov5 Cov6 Cov7 Cov8 Cov9 Cov10 WITH ACT GPA IntMot ExtMot

    Extraversion Agreeableness Neuroticism Loneliness AfricanAm Caucasian (PAIRED)

  /CRITERIA=CI(.9500)

  /MISSING=ANALYSIS.