* Propensity Score Matching.
begin program python3.
import spss, random, spssaux, codecs
try:
import FUZZY
except:
print("This procedure requires the FUZZY extension command which is not installed.")
parts = [int(i) for i in FUZZY.__version__.split(".")]
if parts < [1,3,0]:
raise EnvironmentError("This procedure requires version 1.3.0 or later of FUZZY")
ds = spss.ActiveDataset()
if ds =="*":
ds = "D" + str(random.random())
spss.Submit("DATASET NAME " + ds)
matchgroup = "M" + str(random.random()) #temporary variable
tempdsname = "D" + str(random.random())
lrcmd = spssaux.u(r"""LOGISTIC REGRESSION VARIABLES COHORT
/METHOD=ENTER Age BMI WHO
/SAVE=PRED(PropScore).""")
try:
spss.Submit(lrcmd)
except:
raise ValueError("Logistic Regression step failed")
fuzzycmd = spssaux.u(r"""FUZZY BY=PropScore SUPPLIERID=CaseID NEWDEMANDERIDVARS=MatchID
GROUP=COHORT EXACTPRIORITY=FALSE
MATCHGROUPVAR=%(matchgroup)s FUZZ=.005 DS3=%(tempdsname)s
/OPTIONS SAMPLEWITHREPLACEMENT=FALSE MINIMIZEMEMORY=TRUE SHUFFLE=FALSE .
DELETE VARIABLES %(matchgroup)s.
DATASET ACTIVATE %(ds)s.
DELETE VARIABLES %(matchgroup)s.
DATASET COPY MatchedCohort.
DATASET ACTIVATE MatchedCohort.
SELECT IF COHORT EQ 1.
DATASET ACTIVATE %(tempdsname)s.
When I run it I get this message.
------------------------------
Cindy Gombaut
------------------------------
Original Message:
Sent: Fri July 15, 2022 11:00 PM
From: Jon Peck
Subject: Error Message while Propensity Score Matching
Paste and post the syntax or send me a syntax file to look at (
jkpeck@gmail.com)
--
Original Message:
Sent: 7/15/2022 10:01:00 PM
From: Cindy Gombaut
Subject: Error Message while Propensity Score Matching
Hello! I am running a propensity score matching, but it is not running when I click Ok. If I click paste instead, I get the following warning message:
Text: " % locals()) Command: DATASET CLOSE
A text string is not correctly enclosed in quotation marks
on the command line. Literals may not be continued
across command lines without the use of the continuation
symbol '+'.
-------------------------------------------------------------------
Expecting dataset name or WINDOW. Found %.
-------------------------------------------------------------------
Execution of this command stops.
Not sure what I'm doing wrong here. None of my variables or labels have apostrophes or percentages.
I have a nominal variable in my group indicator. Predictors include both continuous and categorical variables.
I've tried including or excluding different predictors but the test won't run regardless.
Thanks in advance for your help!
------------------------------
Cindy Gombaut
------------------------------
#SPSSStatistics