splitsyntaxspsscategorical-databinary-data

SPSS Syntax: spliting one categorical variable into multiple yes/no variables


I have a categorical variable (v0) with options 1, 2 and 3. I want to split this into 3 yes or no variables (v1, v2, v3).

1,2 and 3 are not mutually exclusive, here is the logic:

if 1 is true then 2 & 3 are not. if 2 is true then 1 & 2 are, but 3 is not. if 3 is true then 1-3 are true.

This is the solution I've tried:

COMPUTE v1 v2 v3.
FORMATS v1 to v3 (f1).
EXECUTE.

IF (v0 = 1) v1 = 1
    /v2 to v3 = 0.
IF (v0 = 2) v1 to v2  = 1
    /v3 = 0.
IF (v0 = 3) v1 to v3  = 1.
EXECUTE.

VALUE LABELS v1 to v3 0 'No' 1 'Yes' 99 'Missing'.

Is there better way to be doing this? Or is this an acceptable solution.


Solution

  • There is any number of ways to do this, here's just one of them:

    compute V1=any(V0,1,2,3).
    compute V2=any(V0,2,3).
    compute V3=(V0=3).