SPSS Statistics

 View Only
  • 1.  Error Message while Propensity Score Matching

    Posted Fri July 15, 2022 10:01 PM
    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


  • 2.  RE: Error Message while Propensity Score Matching

    IBM Champion
    Posted Fri July 15, 2022 11:01 PM
    Paste and post the syntax or send me a syntax file to look at (jkpeck@gmail.com)

    --





  • 3.  RE: Error Message while Propensity Score Matching

    Posted Fri July 15, 2022 11:31 PM
    * 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
    ------------------------------



  • 4.  RE: Error Message while Propensity Score Matching

    IBM Champion
    Posted Sat July 16, 2022 08:41 AM
    The last few lines of the code are missing from the post.  It should end with something like
    ADD FILES /FILE=* /FILE=%(tempdsname)s.
    EXECUTE.
    DATASET CLOSE %(tempdsname)s.""" % locals())
    spss.Submit(fuzzycmd)
    end program.ADD FILES /FILE=* /FILE=%(tempdsname)s.
    EXECUTE.
    DATASET CLOSE %(tempdsname)s.""" % locals())
    spss.Submit(fuzzycmd)
    end program.

    I don't see anything wrong with the code up to that point, but I have a suspicion
    that the random number generator produced an extreme value that then
    got formatted incorrectly.  If that is the case, then just running the command
    again would make the problem disappear.

    If that doesn't solve the problem, can you send me the data? (jkpeck@gmail.com)  I'll try
    to reproduce the problem on my end.

    The PSM dialog is not a regular extension command and is therefore
    sometimes vulnerable to some problems that can occasionally arise.
    I am planning to upgrade it to a regular extension command that would
    make it more robust.


    --