syntaxspss

Creating one variable from three, SPSS


Cam someone be kind and help with SPSS syntax. I get error and do not understand why. I have 3 variables: Var1 (values 1 and 2) Var2 (values 1 and 2) Var3 (values 1, 2, and 3)

I want to create one variable based on these three, where values 1 on each variable ((var1=1 AND VAR2 = 1 AND Var3 = 1) is coded as 1, and all other combinations are coded as 2.

I have written this code but get error, can not understand why.

DO IF (Var1 = 1 AND Var2 = 1 AND Var3 = 1) COMPUTE ADL_independence_before_stroke = 1.
    IF ELSE COMPUTE ADL_independence_before_stroke = 2.
    END IF.
EXECUTE.

Thanks.


Solution

  • You're nearly there but need to correct your syntax:

    DO IF (Var1 = 1 AND Var2 = 1 AND Var3 = 1).
        COMPUTE ADL_independence_before_stroke = 1.
    ELSE.
        COMPUTE ADL_independence_before_stroke = 2.
    END IF.
    EXECUTE.
    

    And here's a shortened version:

    compute ADL_independence_before_stroke = 2- (Var1 = 1 AND Var2 = 1 AND Var3 = 1).