creation of additional variable

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

creation of additional variable

Jims More
I have three dichotomous variables: X, Y and Z (all coded 0/1).  I want to create another variable called W such that:
 
                        W=7 if X=Y=Z=1
                        W=6 if X=Y=1 and Z=0
                        W=5 if X=Z=1 and Y=0                                            
                        W=4  if X=1 and Y=Z=0
                        W=3 if Y=Z=1 and X=0
                        W=2  if Z=1 and X=Y=0
                        W=1  if Y=1 and X=Z=0
                        W=0 if X=Y=Z=0
 
For example:
 
X             Y             Z               W
1             1             1                7
1             1             0                6
1             0             1                5
1             0             0                4
0             1             1                3
0             0             1                2
0             1             0                1
0             0             0                0
 
Can someone help for a syntax?
 
Thank you.
Jims
 
 


Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how.
Reply | Threaded
Open this post in threaded view
|

Re: creation of additional variable

Hector Maletta

The simplest syntax is practically the same as the way you presented your question. Just put the IF at the beginning of each condition. Examples:

 

IF (X=1 AND Y=1 AND Z=1) W=7.

IF (X=1 AND Y=1 AND Z=0) W=6.

……………….

… and so on with the other IF commands. Use parentheses and put a period at the end of each line.

 

Any combination not covered by the IFs will be assigned a system-missing value. For instance, if any of the three variables (X,Y,Z) is blank, or has any value other than 0 or 1, the resulting W would be blank.

 

Hector


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jims More
Sent: 24 June 2009 23:28
To: [hidden email]
Subject: creation of additional variable

 

I have three dichotomous variables: X, Y and Z (all coded 0/1).  I want to create another variable called W such that:

 

                        W=7 if X=Y=Z=1

                        W=6 if X=Y=1 and Z=0

                        W=5 if X=Z=1 and Y=0                                            

                        W=4  if X=1 and Y=Z=0

                        W=3 if Y=Z=1 and X=0

                        W=2  if Z=1 and X=Y=0

                        W=1  if Y=1 and X=Z=0

                        W=0 if X=Y=Z=0

 

For example:

 

X             Y             Z               W

1             1             1                7

1             1             0                6

1             0             1                5

1             0             0                4

0             1             1                3

0             0             1                2

0             1             0                1

0             0             0                0

 

Can someone help for a syntax?

 

Thank you.

Jims

 

 

 


Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how.

Reply | Threaded
Open this post in threaded view
|

Re: creation of additional variable

Art Kendall
I would wrap the set of if statements with some additional syntax. If you use a fixed font you can use vertical alignment to check your syntax.
compute w = -1.
if (...
if (...
value labels w
 -1 'oops fell through. pattern not provided for'
  0 'words'
  1 'more words'
...
do if w eq -1.
print /id x y z w.
end if.


Art Kendall
Social Research Consultants

Hector Maletta wrote:

The simplest syntax is practically the same as the way you presented your question. Just put the IF at the beginning of each condition. Examples:

 

IF (X=1 AND Y=1 AND Z=1) W=7.

IF (X=1 AND Y=1 AND Z=0) W=6.

……………….

… and so on with the other IF commands. Use parentheses and put a period at the end of each line.

 

Any combination not covered by the IFs will be assigned a system-missing value. For instance, if any of the three variables (X,Y,Z) is blank, or has any value other than 0 or 1, the resulting W would be blank.

 

Hector


From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Jims More
Sent: 24 June 2009 23:28
To: [hidden email]
Subject: creation of additional variable

 

I have three dichotomous variables: X, Y and Z (all coded 0/1).  I want to create another variable called W such that:

 

                        W=7 if X=Y=Z=1

                        W=6 if X=Y=1 and Z=0

                        W=5 if X=Z=1 and Y=0                                            

                        W=4  if X=1 and Y=Z=0

                        W=3 if Y=Z=1 and X=0

                        W=2  if Z=1 and X=Y=0

                        W=1  if Y=1 and X=Z=0

                        W=0 if X=Y=Z=0

 

For example:

 

X             Y             Z               W

1             1             1                7

1             1             0                6

1             0             1                5

1             0             0                4

0             1             1                3

0             0             1                2

0             1             0                1

0             0             0                0

 

Can someone help for a syntax?

 

Thank you.

Jims

 

 

 


Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how.

===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: creation of additional variable

Bruce Weaver
Administrator
In reply to this post by Jims More
Jims More wrote
I have three dichotomous variables: X, Y and Z (all coded 0/1).  I want to create another variable called W such that:
 
                        W=7 if X=Y=Z=1
                        W=6 if X=Y=1 and Z=0
                        W=5 if X=Z=1 and Y=0                                            
                        W=4  if X=1 and Y=Z=0
                        W=3 if Y=Z=1 and X=0
                        W=2  if Z=1 and X=Y=0
                        W=1  if Y=1 and X=Z=0
                        W=0 if X=Y=Z=0
 
For example:
 
X             Y             Z               W
1             1             1                7
1             1             0                6
1             0             1                5
1             0             0                4
0             1             1                3
0             0             1                2
0             1             0                1
0             0             0                0
 
Can someone help for a syntax?
 
Thank you.
Jims

do if (x EQ 0) and (y EQ 0) and (z EQ 0).
- compute w = 0.
else if (x EQ 0) and (y EQ 1) and (z EQ 0).
- compute w = 1.
else if (x EQ 0) and (y EQ 0) and (z EQ 1).
- compute w = 2.
etc...
end if.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).