SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  Do If and Compute

    Posted Wed April 19, 2023 05:35 PM

    I have a coding question regarding the Do If with Compute. I am trying to put together code to score a measure with string data. There is a fair amount of missing string data, so I started by defining the missing fields using the "missing values" command. That worked. Then, I moved onto scoring a test item to make sure my code was correct. The variable I6a_0 is string and the variable Q6a_0 is numeric. If the code is working correctly, I should get 261 total, 132 missing, 19 with a value of 1, and 110 with a value of 0.
    Here is what I have:
    do if (I6a_0="  ").
    compute Q6a_0=$SYSMIS.    
    Else if I6a_0= ('Never do this') or ('Unlikely to do this').
    compute Q6a_0=1.
    Else.
    compute Q6a_0=0.
    end if.
    freq var = Q6a_0.
    Here is the output:
    do if (I6a_0="  "). 
    compute Q6a_0=$SYSMIS. 
    Else if I6a_0= ('Never do this') or ('Unlikely to do this'). 
    >Error # 4321 in column 1024.  Text: (End of Command) 
    >One of the operands of a logical operator (AND, OR, and NOT) is neither a 
    >logical expression nor a logical function nor a logical variable. 
    >Execution of this command stops. 
    compute Q6a_0=1. 
    Else. 
    compute Q6a_0=0. 
    end if. 
    freq var = Q6a_0.
    I do not understand the error message I am getting and, as you can see, the missing values count has a value of 1 and what should be the valid cases count has a value of 0. I tried it this way, too, just to try to be more specific, and got the same error message twice (one for each "Else if":

    do if (I6a_0="  ").
    compute Q6a_0=$SYSMIS.
    Else if I6a_0= ('Never do this') or ('Unlikely to do this').
    compute Q6a_0=1.
    Else if (I6a_0= ('Not sure') or ('Probably do this') or ('Definitely do this')).
    compute Q6a_0=0.
    end if.
    freq var = Q6a_0.

    I got 261 valid cases --- all were coded "0". 

    Can someone please help me figure out where this is going awry? It has to be the logic in the Do-if that I am not getting correct. 





    ------------------------------
    Janet
    ------------------------------


  • 2.  RE: Do If and Compute

    Posted Wed April 19, 2023 05:44 PM
    You have to repeat the variable name in
    Else if I6a_0= ('Never do this') or I6a_0 = ('Unlikely to do this').
    or use the Any function:
    image.png


    --