IF-ELSE statement

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

IF-ELSE statement

Jordan Kennedy
Hi all:

I would like to create a binary variable that indicates a value of 1
or yes if individuals within a data file have a valid value for 10
variables that I am interested in. That is, I want individuals to have
non-missing values for all 10 variables to be coded in the "yes"
group; if they are missing even 1 (or a subset) of these variables I
want individuals coded 0 or no. I have attempted to use the DO IF-ELSE
procedure linking the 10 variables together with AND statements, but
this has not worked. Any advice would be appreciated. Thanks!

Jordan

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: IF-ELSE statement

Maguin, Eugene
Jordan,
Read up on the documentation for the Count command and then how the result of a count operation could be transformed to make the new variable you want.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jordan Kennedy
Sent: Monday, July 09, 2012 9:52 AM
To: [hidden email]
Subject: IF-ELSE statement

Hi all:

I would like to create a binary variable that indicates a value of 1 or yes if individuals within a data file have a valid value for 10 variables that I am interested in. That is, I want individuals to have non-missing values for all 10 variables to be coded in the "yes"
group; if they are missing even 1 (or a subset) of these variables I want individuals coded 0 or no. I have attempted to use the DO IF-ELSE procedure linking the 10 variables together with AND statements, but this has not worked. Any advice would be appreciated. Thanks!

Jordan

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: IF-ELSE statement

Rick Oliver-3
In reply to this post by Jordan Kennedy
data list list (",") /x y z.
begin data
1,2,3
4,,6
7,8,9
end data.
missing values x, y, z (9).
compute newvar=not(missing(x+y+z)).
list.

or

compute newvar=not(missing(sum.n(varlist)))

where n is the number of variables.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Jordan Kennedy <[hidden email]>
To:        [hidden email]
Date:        07/09/2012 09:18 AM
Subject:        IF-ELSE statement
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi all:

I would like to create a binary variable that indicates a value of 1
or yes if individuals within a data file have a valid value for 10
variables that I am interested in. That is, I want individuals to have
non-missing values for all 10 variables to be coded in the "yes"
group; if they are missing even 1 (or a subset) of these variables I
want individuals coded 0 or no. I have attempted to use the DO IF-ELSE
procedure linking the 10 variables together with AND statements, but
this has not worked. Any advice would be appreciated. Thanks!

Jordan

=====================
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


Reply | Threaded
Open this post in threaded view
|

Automatic reply: IF-ELSE statement

Rose, Cecilie

I will be out of the office on Monday July 9th.

 

I will return your message when I return on the 10th.

 

Thank you,

 


Cecilie

 

Reply | Threaded
Open this post in threaded view
|

Re: IF-ELSE statement

David Marso
Administrator
In reply to this post by Jordan Kennedy
Sometimes nice to post the code you are having trouble with.
OTOH IF-ELSE is not really a viable approach here.
Have you looked at the NMISS and NVALID functions in the FM?

COMPUTE yesno=(NMISS(your variable list) EQ 0).
ie...
COMPUTE yesnoNMiss=(NMISS(v1 TO v10) EQ 0).
COMPUTE yesnoNValid= (NVALID(v1 TO v10) EQ 10).

or you could abuse the SUM.n function the way Rick did ;-)
-----
Jordan Kennedy wrote
Hi all:

I would like to create a binary variable that indicates a value of 1
or yes if individuals within a data file have a valid value for 10
variables that I am interested in. That is, I want individuals to have
non-missing values for all 10 variables to be coded in the "yes"
group; if they are missing even 1 (or a subset) of these variables I
want individuals coded 0 or no. I have attempted to use the DO IF-ELSE
procedure linking the 10 variables together with AND statements, but
this has not worked. Any advice would be appreciated. Thanks!

Jordan

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"