I wanted to combine several variables. I work with 4 waves of the Share Data. The variables that measures the contact with the child is ch014_ but, there's a variable for every possible child (W1_ch014_1 W1_ch014_2 W1_ch014_3 and W1_ch014_4).
I found a syntax that works for wave 1 en 2, here it is: COMPUTE W1_ch014_SOM = 99. EXECUTE. MISSING VALUES W1_ch014_SOM (99) DO If (W1_ch014_1=1 or W1_ch014_2=1 or W1_ch014_3=1 or W1_ch014_4=1). compute W1_ch014_SOM =1. Else If (W1_ch014_1=2 or W1_ch014_2=2 or W1_ch014_3=2 or W1_ch014_4=2 ). compute W1_ch014_SOM =2. Else If (W1_ch014_1=3 or W1_ch014_2=3 or W1_ch014_3=3 or W1_ch014_4=3 ). compute W1_ch014_SOM =3. Else If (W1_ch014_1=4 or W1_ch014_2=4 or W1_ch014_3=4 or W1_ch014_4=4 ). compute W1_ch014_SOM =4. Else If (W1_ch014_1=5 or W1_ch014_2=5 or W1_ch014_3=5 or W1_ch014_4=5 ). compute W1_ch014_SOM =5. Else If (W1_ch014_1=6 or W1_ch014_2=6 or W1_ch014_3=6 or W1_ch014_4=6 ). compute W1_ch014_SOM =6. Else If (W1_ch014_1=7 or W1_ch014_2=7 or W1_ch014_3=7 or W1_ch014_4=7 ). compute W1_ch014_SOM =7. END IF. Here I use 4 variables: W1_ch014_1 W1_ch014_2 W1_ch014_3 and W1_ch014_4. The result is exactly what I needed, I now get the seven answercategories in 1 table, combining all the 4 variables. But in Wave 4 the variable ch014 consists of 20 variables (W4_ch014_1 until W4_ch014_20). I used the same syntax: COMPUTE W4_ch014_SOM = 99. EXECUTE. MISSING VALUES W4_ch014_SOM (99) DO If (W4_ch014_1=1 or W4_ch014_2=1 or W4_ch014_3=1 or W4_ch014_4=1 or W4_ch014_5=1 or W4_ch014_6=1 or W4_ch014_7=1 or W4_ch014_8=1 or W4_ch014_9=1 or W4_ch014_10=1 or W4_ch014_11=1 or W4_ch014_12=1 or W4_ch014_13=1 or W4_ch014_14=1 or W4_ch014_15=1 or W4_ch014_16=1 or W4_ch014_17=1 or W4_ch014_18=1 or W4_ch014_19=1 or W4_ch014_20=1 ). compute W4_ch014_SOM =1. Else If (W4_ch014_1=2 or W4_ch014_2=2 or W4_ch014_3=2 or W4_ch014_4=2 or W4_ch014_5=2 or W4_ch014_6=2 or W4_ch014_7=2 or W4_ch014_8=2 or W4_ch014_9=2 or W4_ch014_10=2 or W4_ch014_11=2 or W4_ch014_12=2 or W4_ch014_13=2 or W4_ch014_14=2 or W4_ch014_15=2 or W4_ch014_16=2 or W4_ch014_17=2 or W4_ch014_18=2 or W4_ch014_19=2 or W4_ch014_20=2 ). compute W4_ch014_SOM =2. Else If (W4_ch014_1=3 or W4_ch014_2=3 or W4_ch014_3=3 or W4_ch014_4=3 or W4_ch014_5=3 or W4_ch014_6=3 or W4_ch014_7=3 or W4_ch014_8=3 or W4_ch014_9=3 or W4_ch014_10=3 or W4_ch014_11=3 or W4_ch014_12=3 or W4_ch014_13=3 or W4_ch014_14=3 or W4_ch014_15=3 or W4_ch014_16=3 or W4_ch014_17=3 or W4_ch014_18=3 or W4_ch014_19=3 or W4_ch014_20=3 ). compute W4_ch014_SOM =3. Else If (W4_ch014_1=4 or W4_ch014_2=4 or W4_ch014_3=4 or W4_ch014_4=4 or W4_ch014_5=4 or W4_ch014_6=4 or W4_ch014_7=4 or W4_ch014_8=4 or W4_ch014_9=4 or W4_ch014_10=4 or W4_ch014_11=4 or W4_ch014_12=4 or W4_ch014_13=4 or W4_ch014_14=4 or W4_ch014_15=4 or W4_ch014_16=4 or W4_ch014_17=4 or W4_ch014_18=4 or W4_ch014_19=4 or W4_ch014_20=4 ). compute W4_ch014_SOM =4. Else If (W4_ch014_1=5 or W4_ch014_2=5 or W4_ch014_3=5 or W4_ch014_4=5 or W4_ch014_5=5 or W4_ch014_6=5 or W4_ch014_7=5 or W4_ch014_8=5 or W4_ch014_9=5 or W4_ch014_10=5 or W4_ch014_11=5 or W4_ch014_12=5 or W4_ch014_13=5 or W4_ch014_14=5 or W4_ch014_15=5 or W4_ch014_16=5 or W4_ch014_17=5 or W4_ch014_18=5 or W4_ch014_19=5 or W4_ch014_20=5 ). compute W4_ch014_SOM =5. Else If (W4_ch014_1=6 or W4_ch014_2=6 or W4_ch014_3=6 or W4_ch014_4=6 or W4_ch014_5=6 or W4_ch014_6=6 or W4_ch014_7=6 or W4_ch014_8=6 or W4_ch014_9=6 or W4_ch014_10=6 or W4_ch014_11=6 or W4_ch014_12=6 or W4_ch014_13=6 or W4_ch014_14=6 or W4_ch014_15=6 or W4_ch014_16=6 or W4_ch014_17=6 or W4_ch014_18=6 or W4_ch014_19=6 or W4_ch014_20=6 ). compute W4_ch014_SOM =6. Else If (W4_ch014_1=7 or W4_ch014_2=7 or W4_ch014_3=7 or W4_ch014_4=7 or W4_ch014_5=7 or W4_ch014_6=7 or W4_ch014_7=7 or W4_ch014_8=7 or W4_ch014_9=7 or W4_ch014_10=7 or W4_ch014_11=7 or W4_ch014_12=7 or W4_ch014_13=7 or W4_ch014_14=7 or W4_ch014_15=7 or W4_ch014_16=7 or W4_ch014_17=7 or W4_ch014_18=7 or W4_ch014_19=7 or W4_ch014_20=7 ). compute W4_ch014_SOM =7. END IF. But now when I look at the frequencies, I only get the value 1 and the missing 99 in the tabel. Is this syntax not possible with this many variables? Or am I doing something wrong? Thanks a lot! |
DO If (W1_ch014_1=1 or W1_ch014_2=1 or W1_ch014_3=1 or W1_ch014_4=1).
Can be re-wrriten as: DO If (ANY, 1 , W1_ch014_1,W1_ch014_2,W1_ch014_3,W1_ch014_4). Or even: DO If (ANY, 1 , W1_ch014_1 to W1_ch014_4). Assuming W1_ch014_1 to W1_ch014_4 are in contiguous order. Always wise to try keep your code as parsimonious/short hand/compact as possible so try that at first to see if it helps bring to light the flaw in the syntax which is not providing you the desirable outcome... |
Hmm I just tried it, didn't work. Now I only get the value 7 in the table...
|
In situation like these, I would break down the code bit-by-bit to try debug why what you think the expected result should be against what you are actually computing.
Are you able to share your data for those 20 variables for a subset of cases? |
Free forum by Nabble | Edit this page |