SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  conditional syntax; what is the best approach....

    Posted Tue November 02, 2021 02:19 PM
    Dear Forum Members, 

    I hope someone can help me out or point me in the right direction. I have a data file with 300 subjects and quite a few variables, most of them discretely coded 1-6. Here is what I would like to do:

    1) if any variable of let's DP1, DP2, DP3, .... DP7 is 1, 3, or 5 make target_var1 = 1
    2) if all of the above (DP1-DP7) are $sysmis then make target_var1 = $sysmis
    3) if none of these are true make target_var = 0

    Ideally, I would like to be able to adapt item 2) to something that says: "if more than i.e. 4 of DP1-7 contain $sysmis then make i.e. target_var 2 = $sysmis" or some other way to designate too few data points.

    so finally, at the most complex I might also need to have something like:
    IF in DP1-7 at least two have the value 4 and no more than i.e. 3 are $sysmis, then give target_var3 = 1


    If anyone could help out, I would be very very grateful.

    All the best,

    J.

    ------------------------------
    johannes achenbach
    ------------------------------

    #SPSSStatistics


  • 2.  RE: conditional syntax; what is the best approach....

    Posted Tue November 02, 2021 03:15 PM
    The COUNT command (Transform > Count Values within Cases) is your friend. That with a small DO IF block should get you there.

    --





  • 3.  RE: conditional syntax; what is the best approach....

    Posted Tue November 02, 2021 03:16 PM
    See if this does what you want.

    DO REPEAT existVar=dp1 to dp7 /newVar=new1 TO new7.
    COMPUTE newVar=0.
    COMPUTE newVar=any(existVar,1,3,5).
    END REPEAT.
    COUNT miss=dp1 to dp7 (MISSING,SYSMIS).
    EXECUTE.
    
    DO IF miss=7.
    RECODE new1 to new7 (LO THRU HI,MISSING=SYSMIS).
    END IF.
    EXECUTE.

    The DO IF command could be modified from 7 to whatever number you want, or some range, etc.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 4.  RE: conditional syntax; what is the best approach....

    Posted Sun November 07, 2021 04:27 PM
    Thanks guys. @Rick Marcantonio
    I couldn't quite get that to work because I didn't need 7 new variables but wanted to have one new one that contains the new information.

    For people who might run into similar problems I did the following (probably not elegant and too long winded):
    compute new_var= 0.
    if any  (dp1, 1,3,5) new_var=1.
    if any  (dp2, 1,3,5) new_var=1.
    and so on til dp7.    [is there any way to combine the seven different if clauses???]
    
    compute mis_var = nmiss(dp1 to dp7).
    if (mis_var GE 5 AND new_var NE 1) new_var = $sysmis.
    execute.​


    looking forward to your feedback.....

    all the best,

    J.


    ------------------------------
    johannes achenbach
    ------------------------------



  • 5.  RE: conditional syntax; what is the best approach....

    Posted Mon November 08, 2021 08:42 AM
    Sorry I misunderstood. This will combine the 7 separate statements:

    COMPUTE newVar=0.
    DO REPEAT existVar=dp1 to dp7.
    IF newVar=0 newVar=any(existVar,1,3,5).
    END REPEAT.
    EXECUTE.​


    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------