I want to compute a variable X=x1+x2+x3. x1, x2 and x3 have either the values 1 or 0. I recoded system missings to -77. There are some conditions which should be met.
1) If there is a missing value in either x1,x2 or x3, then it should be ignored if one or two of the other variables have the value 1. So the sum should be calculated although there is a missing value but only if there is at least one 1 (Eg. X = x1 + x2 + x3 = 0 + missing + 1 = 1)
2) If there is a missing value in either x1, x2 or x3, then it should not be ignored if there is no 1 at all and the sum should not be calculated. (Eg. X = x1 + x2 + x3 = 0 + missing + missing = missing).
I tried to make a loop with IF but it won't work and I just can't figure out why.
`COMPUTE X =SUM(x1, x2, x3).
IF (x1=-77 AND x2~=1 AND x3~=1) X=999.
IF (x2=-77 AND x1~=1 AND x3~=1) X=999.
IF (x3=-77 AND x1~=1 AND x2 ~=1)X=999.
EXECUTE.`
*These are the returned results: when x1=1, x2 = 0, x3=-77 then X=1. (That is the result I want. The problem arises when x1=-77, x2=0, x3=0 because then X=0 and not 999 as I want it to be.
I think that with the loop above I am close to the result but something is missing. Below I post some other loops I made, but neither did work and I think the one above is the closest to the right answer.
Thank you so much for your help and happy easter! Cheers desperate Ichav :)
'COMPUTE X = x1 + x2 + x3.
RECODE X (SYSMIS=-77).
IF ((X = -77 AND x1 = 1) OR (X = -77 AND x2 = 1) OR (X = -77 AND x3 = 1)) X =1.
EXECUTE.'
*Here X is always returned as -77.
Aucun commentaire:
Enregistrer un commentaire