|
Dear List,
I have a problem with „recoding“ a variable. I have one variable with about 150 values. The values are codes which are composed of two different codes The first part is a country identifier and the second part are categories of education. I have to replace the country identifier with a new identifier (i.e. different coding scheme). The real problem now is that the values of the original variable exist in two different lengths (with 4 digits and with 5 digits; e.g. 3999 or 39988). The syntax I tried first looks like that: rename variables (v336_cs=v336_csorg) . compute v336_cs =0. DO IF ((v336_csorg>=3101) & (v336_csorg<=3999)). recode v336_cs = (v336_csorg-3000+2760000). ELSE IF ((v336_csorg>3999) & (v336_csorg<=39988)). recode v336_cs = (v336_csorg-30000+27600000). END IF. I do understand that the recode command does not tolerate variables in the function part. And I know there is a solution in an appending cases procedure, however this would make my already quite complex syntax even more complex and potentially instable. Moreover, simply writing out the single recode commands is no option as I would have to do this a myriad of times… Has anyone an idea how I could solve this problem in a simple manner? Thanks a lot in advance, Jara ===================== 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 |
|
Jara,
Ok, you are getting a syntax error because you don't quite understand the recode command syntax. I thing you'd get rid of your syntax error if you did this. rename variables (v336_cs=v336_csorg) . compute v336_cs =0. DO IF ((v336_csorg>=3101) & (v336_csorg<=3999)). compute v336_cs = (v336_csorg-3000+2760000). ELSE IF ((v336_csorg>3999) & (v336_csorg<=39988)). compute v336_cs = (v336_csorg-30000+27600000). END IF. Would that fix your real problem? I don't know but it will get you past where you are stuck now. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jara Kampmann Sent: Thursday, June 10, 2010 9:11 AM To: [hidden email] Subject: problem recoding values Dear List, I have a problem with "recoding" a variable. I have one variable with about 150 values. The values are codes which are composed of two different codes The first part is a country identifier and the second part are categories of education. I have to replace the country identifier with a new identifier (i.e. different coding scheme). The real problem now is that the values of the original variable exist in two different lengths (with 4 digits and with 5 digits; e.g. 3999 or 39988). The syntax I tried first looks like that: rename variables (v336_cs=v336_csorg) . compute v336_cs =0. DO IF ((v336_csorg>=3101) & (v336_csorg<=3999)). recode v336_cs = (v336_csorg-3000+2760000). ELSE IF ((v336_csorg>3999) & (v336_csorg<=39988)). recode v336_cs = (v336_csorg-30000+27600000). END IF. I do understand that the recode command does not tolerate variables in the function part. And I know there is a solution in an appending cases procedure, however this would make my already quite complex syntax even more complex and potentially instable. Moreover, simply writing out the single recode commands is no option as I would have to do this a myriad of times. Has anyone an idea how I could solve this problem in a simple manner? Thanks a lot in advance, Jara ===================== 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 |
|
In reply to this post by Jara Kampmann
Jara
Looks to me as if you have original numeric
variables, so instead of all those IFs, try using COMPUTE with TRUNC or MOD and
dividing by multiples of 10, 100, 1000, 10,000 etc. I'm off to
England first thing tomorrow and will be out of contact until Fri 18 June, so
send me the actual variable format and I'll write you some syntax. In case
you don't catch me,
If v366_cs is a four digit code, you'll need
something like:
compute country = trunc
(v366_cs/100) .
* If v366_cs is 3999 and 39 = country, 99 =
edcode this will make country 39
compute edcode = mod (v366_cs/100)
.
* This will make edcode 99
Look up COMPUTE in the syntax reference
guide.
John Hall
|
| Free forum by Nabble | Edit this page |
