I am a low-level, basic user and I’m trying to generate a new variable using two existing variables. I've looked for instructions online, without success.
Here’s the logic. Var1 = Location of Prisoner before transfer (locations are numeric codes) Var2 = Location of Prisoner after transfer. (locations are numeric codes) The new variable (var3) I need to generate represents the “TransferType.” If a prisoner goes from prison1 to prison2, the transfer type would =3. If a prisoner goes from prison1 to parole, the transfer type would = 1; etc… I have tried generating a new variable and then using the RECODE IF function, but can’t get it to accept my logic (it will only allow one use of an old value). I don't know much about syntax, but am learning a lot by using the paste function. Thanks for your help on this. Joan Schwartz |
Administrator
|
IF (oldvar1 EQ value AND oldvar2 EQ value) newvar= VALUE.
--
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?" |
Administrator
|
Here's a variation that may involve less RSI, depending on the number of values the two variables can have. Suppose each variable has values 1-3, for example.
COMPUTE newvar = oldvar1*10 + oldvar2. RECODE newvar (11 = value) (12 = value) (13 = value) (21 = value) etc (33 = value). Then use VALUE LABELS to assign labels to the different values of newvar. And before Art beats me to it, recoding a variable into itself is often not a good idea, because you can end up in a situation where you lose the original information, and cannot start over if necessary. But in a case like this, where newvar is generated from oldvar1 and oldvar2, you can restart with no loss of information (because oldvar1 and oldvar2 have not been modified), so I see no problem with it. HTH.
--
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/). |
Administrator
|
In reply to this post by Joan
Please expand on etc...and a fuller explanation of the possible outcome values.
Is the new value ALWAYS 1 or 3? The more info provided in initial posts saves much guess work! --
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?" |
Free forum by Nabble | Edit this page |