Greetings SPSSers,
I am dealing with an incredibly messy data file with lots of string variables that need to be transformed into a useful format. I have hit a bit of a problem in some data transformations. I have a variable in a dataset that was entered as a string, where information about previous psychiatric hospitalization was written in. I am trying to reduce it to a 0=no, 1=yes, and 2=unknown variable. I autorecoded the text variable and ended up with 416 distinct values which are mostly unique misspellings and abbreviations of a few main types of appropriate responses. I went through and generated a listing of the autorecoded values that belong in each category. Where I am having trouble is now moving from the auto recoded values to the 3 level variable The piece of code I can't get to work is: Do If any(hosprec,1-3,7,9,10-103,105-219,221-275,284,285,289-306,309-315, 319-341,383-394,396,400-405,407-416)=1. compute prevhosp=1. This is inserting the 1 in prevhosp only for those cases with hosprec values of 7,9,284,285 and maybe a couple others. IT seems to be ignoring the intended ranges of values. I tried using both "to" and "thru" in place of the "-" for the ranges and doing that resulted in spss putting a 1 in prevhosp for evey case in the data file. Any insights into what I am doing wrong will be greatly appreciated. Best, Jeff Jeffrey D. Leitzel, Ph.D. Assistant Professor, Department of Psychology Office: McCormick 2123 Bloomsburg University 400 East Second Street Bloomsburg, PA 17815 Office Phone:570-389-4232,fax:570-389-2019 Alt. Office (T & Th): 570 348-6100 ext:3216 |
Seems to me that you now just want to 'regular' recode your auto-recoded
values. Recode hosprec (1-3,7,9,10-103,105-219,221-275,284,285,289-306,309-315, 319-341,383-394,396,400-405,407-416=1)(4-6,...=0)(else=2) into prevhosp. Or am I missing something? Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Dr. Jeffrey D. Leitzel Sent: Wednesday, December 20, 2006 3:11 PM To: [hidden email] Subject: [SPSSX-L] Selecting ranges of autorecoded values for basis of a new variable Greetings SPSSers, I am dealing with an incredibly messy data file with lots of string variables that need to be transformed into a useful format. I have hit a bit of a problem in some data transformations. I have a variable in a dataset that was entered as a string, where information about previous psychiatric hospitalization was written in. I am trying to reduce it to a 0=no, 1=yes, and 2=unknown variable. I autorecoded the text variable and ended up with 416 distinct values which are mostly unique misspellings and abbreviations of a few main types of appropriate responses. I went through and generated a listing of the autorecoded values that belong in each category. Where I am having trouble is now moving from the auto recoded values to the 3 level variable The piece of code I can't get to work is: Do If any(hosprec,1-3,7,9,10-103,105-219,221-275,284,285,289-306,309-315, 319-341,383-394,396,400-405,407-416)=1. compute prevhosp=1. This is inserting the 1 in prevhosp only for those cases with hosprec values of 7,9,284,285 and maybe a couple others. IT seems to be ignoring the intended ranges of values. I tried using both "to" and "thru" in place of the "-" for the ranges and doing that resulted in spss putting a 1 in prevhosp for evey case in the data file. Any insights into what I am doing wrong will be greatly appreciated. Best, Jeff Jeffrey D. Leitzel, Ph.D. Assistant Professor, Department of Psychology Office: McCormick 2123 Bloomsburg University 400 East Second Street Bloomsburg, PA 17815 Office Phone:570-389-4232,fax:570-389-2019 Alt. Office (T & Th): 570 348-6100 ext:3216 PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by Dr. Jeffrey D. Leitzel
No ranges are allowed for any. You could use the range function but you don't have ranges but mixes of discrete values and ranges so you would end with lists like 3,3,7,7, etc. Use recode instead
* initialize prevhosp. COMPUTE prevhosp =0. RECODE hosprec (1 thru 3, 7, 9, 10 thru 103 etc. = 1) into prevhosp. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Dr. Jeffrey D. Leitzel Sent: Wednesday, December 20, 2006 3:11 PM To: [hidden email] Subject: Selecting ranges of autorecoded values for basis of a new variable Greetings SPSSers, I am dealing with an incredibly messy data file with lots of string variables that need to be transformed into a useful format. I have hit a bit of a problem in some data transformations. I have a variable in a dataset that was entered as a string, where information about previous psychiatric hospitalization was written in. I am trying to reduce it to a 0=no, 1=yes, and 2=unknown variable. I autorecoded the text variable and ended up with 416 distinct values which are mostly unique misspellings and abbreviations of a few main types of appropriate responses. I went through and generated a listing of the autorecoded values that belong in each category. Where I am having trouble is now moving from the auto recoded values to the 3 level variable The piece of code I can't get to work is: Do If any(hosprec,1-3,7,9,10-103,105-219,221-275,284,285,289-306,309-315, 319-341,383-394,396,400-405,407-416)=1. compute prevhosp=1. This is inserting the 1 in prevhosp only for those cases with hosprec values of 7,9,284,285 and maybe a couple others. IT seems to be ignoring the intended ranges of values. I tried using both "to" and "thru" in place of the "-" for the ranges and doing that resulted in spss putting a 1 in prevhosp for evey case in the data file. Any insights into what I am doing wrong will be greatly appreciated. Best, Jeff Jeffrey D. Leitzel, Ph.D. Assistant Professor, Department of Psychology Office: McCormick 2123 Bloomsburg University 400 East Second Street Bloomsburg, PA 17815 Office Phone:570-389-4232,fax:570-389-2019 Alt. Office (T & Th): 570 348-6100 ext:3216 |
Free forum by Nabble | Edit this page |