Shenya
Shenya

Reputation: 344

How do I recode variables dependent on another variable in spss

when recoding variables, the dependency on another variable is apparently ignored.

My syntax:

if(leaFi15 = '1,2')
 RECODE  f13_1 f13_3 f13_5 f13_2 f13_6 f13_4 f13_7 f13_8 f13_9 f13_10 f13_11 f13_12 f13_13 f13_14 f13_15 (0 = SYSMIS).
EXECUTE.

Also by using a numeric variable the same behavior without any error message.

if(SYSMIS(f18n))
 RECODE  f13_1 f13_3 f13_5 f13_2 f13_6 f13_4 f13_7 f13_8 f13_9 f13_10 f13_11 f13_12 f13_13 f13_14 f13_15
 (0 = SYSMIS).
EXECUTE.

The data before:

After processing with the syntax:

enter image description here

Everything is completely deleted in the variables(f13_...) with the value 0. However, only the lines should be changed for which the variable leaFi15 has sysmis. What is wrong with the script here?

I tested the syntax in PSPPIRE, but I guess it should be the same in IBM's SPSS program in this case.

Upvotes: 2

Views: 547

Answers (1)

horace_vr
horace_vr

Reputation: 3166

what you are after is DO IF, and also how you write the logical condition depends on whether leaFi15 is string or numerical:

Assuming it is numerical:

DO IF any(leaFi15, 1,2).
 RECODE  f13_1 f13_3 f13_5 f13_2 f13_6 f13_4 f13_7 f13_8 f13_9 f13_10 f13_11 f13_12 f13_13 f13_14 f13_15 (0 = SYSMIS).
END IF.
EXECUTE.

(this will replace all your 0 values with blanks).

Assuming leaFi15 is string, you need to place each value between quotation signs:

    DO IF any(leaFi15, "1","2").
...

Using DO IF allows you to place several transformation commands between DO IF and END IF. A simple IF statement only allows for one such transformation.

Upvotes: 1

Related Questions