|
hello all
i'll get straight to the point lets say that i'm having 2 variables first variable is having values of 1-10 second variable is having values of 1-2 now i need to genrate a third variable to do the following : - to code "1" if the first variable's value is 1-5 - to code "2" if the second variable's value is 1 - to code "3" if both above conditions are fulfilled is it posibble to do this in spss ? i'm using PASW 18 thanks in advance for your help! Best Regards, Mohd |
|
Dear Mohamed,
If I understood you well, here is the code for this RECODE V1 (1 thru 5=1)INTO V3. IF (V2 = 1) V3 = 2. IF (V1 >=1 and V1 <=5 and V2 =1) V3 = 3. EXECUTE. Regards. Walid From: Mohammed Mustafa <[hidden email]> To: [hidden email] Sent: Thu, September 16, 2010 12:53:03 PM Subject: Compute / generate a new variable hello all i'll get straight to the point lets say that i'm having 2 variables first variable is having values of 1-10 second variable is having values of 1-2 now i need to genrate a third variable to do the following : - to code "1" if the first variable's value is 1-5 - to code "2" if the second variable's value is 1 - to code "3" if both above conditions are fulfilled is it posibble to do this in spss ? i'm using PASW 18 thanks in advance for your help! Best Regards, Mohd |
|
In reply to this post by Mohammed Mustafa
If your two vars are v1 and v2, something like (in syntax,
unchecked):
recode v1 (1 thru 5 = 1)(6 thru 10 =0)(else = sysmis) into
x1
/v2 (1 =1)(2 =0)(else = sysmis) into
x2.
count x3 = x1 x2 (1) .
recode x3 (1=0)(2=1) .
freq x1 to x3 .
|
|
In reply to this post by Waleed Massoud
Many thanks waleed & John actually i have 4 different variables and i used your method as a key to deal with the rest of them below is the syntax that i used , i'd like to know your opinion about it RECODE Q1a (1 thru 5=1) (6 thru 99=0) (ELSE=SYSMIS) INTO X1. RECODE Q1b (1 thru 5=1) (6 thru 99=0) (ELSE=SYSMIS) INTO X2. RECODE Q2a (1 thru 5=1) (6 thru 99=0) (ELSE=SYSMIS) INTO X3. RECODE Q18 (1=1) (2 thru 99=0) (ELSE=SYSMIS) INTO X4. IF (((X1=1) OR (X2=1) OR (X3=1)) AND (X4=0)) X5=1.IF ((X1=0) AND (X2=0) AND (X3=0) AND (X4=1)) X5=2. IF (((X1=1) OR (X2=1) OR (X3=1)) AND (X4=1)) X5=3. IF ((X1=0) AND (X2=0) AND (X3=0) AND (X4=0)) X5=0. EXECUTE. the results came exactlly as i needed but is there an easier way to do this or i just did it right ? Thanks & best regards, Mohammed Date: Thu, 16 Sep 2010 03:51:23 -0700 From: [hidden email] Subject: Re: Compute / generate a new variable To: [hidden email] Dear Mohamed,
If I understood you well, here is the code for this RECODE V1 (1 thru 5=1)INTO V3. IF (V2 = 1) V3 = 2. IF (V1 >=1 and V1 <=5 and V2 =1) V3 = 3. EXECUTE. Regards. Walid From: Mohammed Mustafa <[hidden email]> To: [hidden email] Sent: Thu, September 16, 2010 12:53:03 PM Subject: Compute / generate a new variable hello all i'll get straight to the point lets say that i'm having 2 variables first variable is having values of 1-10 second variable is having values of 1-2 now i need to genrate a third variable to do the following : - to code "1" if the first variable's value is 1-5 - to code "2" if the second variable's value is 1 - to code "3" if both above conditions are fulfilled is it posibble to do this in spss ? i'm using PASW 18 thanks in advance for your help! Best Regards, Mohd |
|
Administrator
|
Does this do what you want? RECODE Q1a Q1b Q2a (1 thru 5=1) (6 thru 99=0) (ELSE=SYSMIS) INTO X1 X2 X3. RECODE Q18 (1=1) (2 thru 99=0) (ELSE=SYSMIS) INTO X4. IF ANY(1,X1,X2,X3) AND (X4=0)) X5=1. IF ((X1=0) AND (X2=0) AND (X3=0) AND (X4=1)) X5=2. IF ANY(1,X1,X2,X3) AND (X4=1)) X5=3. IF ((X1=0) AND (X2=0) AND (X3=0) AND (X4=0)) X5=0. EXECUTE.
--
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/). |
|
In reply to this post by Mohammed Mustafa
IF (((X1=1) OR (X2=1) OR (X3=1)) AND (X4=0)) X5=1.IF (((X1 eq 1) OR (X2 eq 1) OR (X3 eq 1)) AND (X4=0)) X5=1. 2) be aware that the if statement are evaluated in order. If more than one condition is true X5 will have that value. while developing your syntax you may wish to have each condition create a different variable and look at them to be sure you are doing what you want to do. IF (((X1 eq 1) OR (X2 eq 1) OR (X3 eq 1)) AND (X4=0)) test1=1. 3)Also it is helpful to initialize a variable such as x5. numeric X5(f2). compute x5 = 4. 4) value labels help a lot in debugging logic. value labels x5 0 'whatever label' 1 'some label' 2 'another label' 3 'meaningful label' 4 'not assigned a new values by tests'. 5) since you know why a value is missing you should assign a specific user missing value. Reserving sysmis for its intended purpose of letting you know when the program cannot follow your instructions is good programming. 6) since the same recoding scheme is used for 3 X variables you could recode Q1a Q1b Q2a (1 thru 5) ... Art Kendall Social Research Consultants On 9/21/2010 9:59 AM, Mohammed Mustafa wrote: ===================== 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 |
| Free forum by Nabble | Edit this page |
