here you are:
Code:compute group2 = 0. if (group eq 1) and (age le 5) group2 = group. if (group eq 2) and (age eq 6) group2 = group. if (group eq 3) and (age eq 7) group2 = group. exe.
Hi all,
I am new to SPSS-Syntax. I will appreciate if any of you can help me with the following programming.
I have a variable 'group' with 3 values 1 2 3. I would like to compute another variable 'group2'
from 'group' with another condition on another variable 'age'. The condition is:
I want to keep the first value of 'group' as it is if age <=5 else the value should be changed to 0.
The second value (2) of the 'group' should be as it is if age=6 else 2 should be set to zero. The 3rd value (3) of the 'group' should be as it is if age=7 else 3 should be set to zero. How do I write the SPSS-syntax for this task?
Thank you.
soma
here you are:
Code:compute group2 = 0. if (group eq 1) and (age le 5) group2 = group. if (group eq 2) and (age eq 6) group2 = group. if (group eq 3) and (age eq 7) group2 = group. exe.
I'm not sure I quite understand what you want to do. Do you want a new variable that is three times the value of sum_var or do you want three new variables that are equal to sum_var? Or something else entirely?
Also, your command "compute sum_var=sum(var1+var2+var3)." will result in missing values in any case containing missing data amongst your summed variables. If this is not what you want, use "compute sum_var = sum(var1, var2, var3)."
OK, I'm puzzled as to why you would want to do this but here you go:
Code:string #x (a10). string sum_var2 (a20). compute #x=ltrim(string(sum_var,f8)). compute sum_var2=concat(rtrim(#x), ', ', rtrim(#x), ', ', rtrim(#x)). exe.
Try:
If this is not what you need, then you will need to post an example of how your datafile looks now and how you want it to look.Code:compute sortid =$casenum. add files / file=* / file=* / file=*. sort cases by sortid. delete variables sortid. exe.
Here you are:
Code:if missing(Kontaktfähigkeit_Summe) Kontaktfähigkeit_Summe = lag(Kontaktfähigkeit_Summe). exe.
Thank you very much! It works!
Hi Helicon,
I wrote the following code to do the following: I want to compute the variable J_Gruppe_Final from J_Gruppe_Cal (please see the attached picture)
after imposing these conditions:
I want to keep the first value of ' J_Gruppe_Cal' as it is if age_year <= 4 else the value should be changed to 0.
The second value of the ' J_Gruppe_Cal' should be as it is if age_year =5 else should be set to zero. The 3rd value of the 'group' should be as it is if age=7 else 3 should be set to zero. I tried the following...but it does not work -- I understand why.
compute J_Gruppe_Final = 0.
do if (age_year le 4).
-compute J_Gruppe_Final = J_Gruppe_Cal.
else if (age_year eq 5).
-compute J_Gruppe_Final = J_Gruppe_Cal.
else if (age_year eq 6).
-compute J_Gruppe_Final = J_Gruppe_Cal.
end if.
EXECUTE.
How do I write the SPSS-syntax for this task?
Thank you.
soma
Your syntax is conditional upon just age, not the combination of age and group.
Not tested but it should look something like this:
Code:compute j_gruppe_final = 0. if ((j_gruppe_cal eq 1) and (age_year le 4)) or ((j_gruppe_cal eq 2) and (age_year eq 5)) or ((j_gruppe_cal eq 3) and (age_year eq 6)) j_gruppe_final = j_gruppe_cal. exe.
Hi,
I tried your code...but it does not work!Please help. Thanks
|
|