|
I want to create a variable (SIWkRating) that categorizes the suicidal
status of survey respondents. There are 5 questions on the survey regarding suicidal ideation and there is a progression to the questions. The five questions are recoded as dichotomous with 0=no and 1=yes with missing=sysmis PHQ_deathD S_Wk_death S_Wk_Active S_Wk_plan S_Wk_act If there is a positive response to either of the first two questions (PHQ_deathD or S_Wk_death) and the responses to the other questions are negative, the new variable is categorized as a '1'. If the next question in the series is positive (S_Wk_Active), regardless to the response to the first two questions, and the response to subsequent questions is negative then the new var=2 And so forth. compute SIWkRating=0. If sum(S_Wk_death, PHQ_deathD) GE 1 and sum( S_Wk_Active, S_Wk_plan, S_Wk_act) =0 SIWkRating=1. If (S_Wk_Active=1) and sum(S_Wk_plan, S_Wk_act) =0 SIWkRating=2. If (S_Wk_plan=1) and sum(S_Wk_act) =0 SIWkRating=3. If (S_Wk_act=1) SIWkRating=4. Freq SIWkRating. Execute. ***when there is missing data for a variable that must be positive to make the statement true then I want the new var to be set at missing. Does this code accomplish that? (I don't think so because I start with SIWkRating=0) Also, is there a better way to write this code? Is there a simple way to check the outcome of the code such as a cross tabs? Many thanks, Jan ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
Don't initialize the variable to 0. Use
Do If/Else If/Else with the last condition being:
else. SIWkRating=0. If any condition prior to the final Else returns missing, the value of SIWkRating will be 0 for that case. A simple example: data list free (",") /x. begin data 1,,2,3 end data. missing values x (3). do if x=1. compute y=1. else. compute y=0. end if. list.
I want to create a variable (SIWkRating) that categorizes the suicidal status of survey respondents. There are 5 questions on the survey regarding suicidal ideation and there is a progression to the questions. The five questions are recoded as dichotomous with 0=no and 1=yes with missing=sysmis PHQ_deathD S_Wk_death S_Wk_Active S_Wk_plan S_Wk_act If there is a positive response to either of the first two questions (PHQ_deathD or S_Wk_death) and the responses to the other questions are negative, the new variable is categorized as a '1'. If the next question in the series is positive (S_Wk_Active), regardless to the response to the first two questions, and the response to subsequent questions is negative then the new var=2 And so forth. compute SIWkRating=0. If sum(S_Wk_death, PHQ_deathD) GE 1 and sum( S_Wk_Active, S_Wk_plan, S_Wk_act) =0 SIWkRating=1. If (S_Wk_Active=1) and sum(S_Wk_plan, S_Wk_act) =0 SIWkRating=2. If (S_Wk_plan=1) and sum(S_Wk_act) =0 SIWkRating=3. If (S_Wk_act=1) SIWkRating=4. Freq SIWkRating. Execute. ***when there is missing data for a variable that must be positive to make the statement true then I want the new var to be set at missing. Does this code accomplish that? (I don't think so because I start with SIWkRating=0) Also, is there a better way to write this code? Is there a simple way to check the outcome of the code such as a cross tabs? Many thanks, Jan ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by J McClure
Jan
Rick is right about the Do if etc. Busy with
other stuff, but at first sight it looks as if you might have the makings of a
Guttman scale.
|
|
In reply to this post by Rick Oliver-3
Thanks for you input Rick!
How does this look? Jan DO IF sum(S_Wk_death, PHQ_deathD) GE 1 and sum( S_Wk_Active, S_Wk_plan, S_Wk_act) =0. compute SIWkRating=1. ELSE IF (S_Wk_Active=1) and sum(S_Wk_plan, S_Wk_act) =0. compute SIWkRating=2. ELSE IF (S_Wk_plan=1) and sum(S_Wk_act) =0. compute SIWkRating=3. ELSE IF (S_Wk_act=1). compute SIWkRating=4. else. compute SIWkRating=0. End If. Execute. On 8/17/2010 11:47 AM, Rick Oliver wrote: Don't initialize the variable to 0. Use Do If/Else If/Else with the last condition being:===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
If it does what you want, then it looks
fine. ;-)
An important difference between DO IF and IF is that DO IF stops evaluating conditions after the first condition it encounters that evaluates to true. Even if your conditions are not mutually exclusive, DO IF is done after the first condition it encounters in the structure that evaluates to true. So with DO IF, the first condition that is true wins, whereas with IF, the last condition that is true wins. For example: do if X=1. compute Y=1. else if X > 0. compute Y=2. end if. In the above DO IF, if X=1 then Y will be set to 1, even though X is also greater than 0. The second condition is not evaluated because the first condition is true. The result is NOT the same for the following sequence of IF commands: if X=1 Y=1. if X > 0 Y=2. Since the two conditions are both true, Y is initially set to 1, and then subsequently set to 2.
Thanks for you input Rick! How does this look? Jan DO IF sum(S_Wk_death, PHQ_deathD) GE 1 and sum( S_Wk_Active, S_Wk_plan, S_Wk_act) =0. compute SIWkRating=1. ELSE IF (S_Wk_Active=1) and sum(S_Wk_plan, S_Wk_act) =0. compute SIWkRating=2. ELSE IF (S_Wk_plan=1) and sum(S_Wk_act) =0. compute SIWkRating=3. ELSE IF (S_Wk_act=1). compute SIWkRating=4. else. compute SIWkRating=0. End If. Execute. On 8/17/2010 11:47 AM, Rick Oliver wrote: Don't initialize the variable to 0. Use Do If/Else If/Else with the last condition being: else. SIWkRating=0. If any condition prior to the final Else returns missing, the value of SIWkRating will be 0 for that case. A simple example: data list free (",") /x. begin data 1,,2,3 end data. missing values x (3). do if x=1. compute y=1. else. compute y=0. end if. list.
I want to create a variable (SIWkRating) that categorizes the suicidal status of survey respondents. There are 5 questions on the survey regarding suicidal ideation and there is a progression to the questions. The five questions are recoded as dichotomous with 0=no and 1=yes with missing=sysmis PHQ_deathD S_Wk_death S_Wk_Active S_Wk_plan S_Wk_act If there is a positive response to either of the first two questions (PHQ_deathD or S_Wk_death) and the responses to the other questions are negative, the new variable is categorized as a '1'. If the next question in the series is positive (S_Wk_Active), regardless to the response to the first two questions, and the response to subsequent questions is negative then the new var=2 And so forth. compute SIWkRating=0. If sum(S_Wk_death, PHQ_deathD) GE 1 and sum( S_Wk_Active, S_Wk_plan, S_Wk_act) =0 SIWkRating=1. If (S_Wk_Active=1) and sum(S_Wk_plan, S_Wk_act) =0 SIWkRating=2. If (S_Wk_plan=1) and sum(S_Wk_act) =0 SIWkRating=3. If (S_Wk_act=1) SIWkRating=4. Freq SIWkRating. Execute. ***when there is missing data for a variable that must be positive to make the statement true then I want the new var to be set at missing. Does this code accomplish that? (I don't think so because I start with SIWkRating=0) Also, is there a better way to write this code? Is there a simple way to check the outcome of the code such as a cross tabs? Many thanks, Jan ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@... (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
| Free forum by Nabble | Edit this page |
