recode help

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

recode help

Tufayel Chowdhury
Hi All,

I have a distance dataset where the distance ranges from 0.01 km to 100 km. I need to create e frequency table where each class width will be 0.5 km. For this, I have to recode the DISTANCE variables like this-

recode DISTANCE (lowest thru 0.49=1) (0.5 thru 0.99=2) (1 thru 1.49=3)..... (100 thru Highest = 201) into re_DISTANCE.

I was wondering if there is a shortcut for this. Otherwise I'd have to write a tedious syntax to create 200 distance classes (0 to 100 km, class width = 0.5). Any help?

Thanks in advance!
Tufayel 

Reply | Threaded
Open this post in threaded view
|

Re: recode help

John F Hall
Try something like (untested, but assuming your distances are to 2 or more decimal places):
 
compute kmgroup = trunc (distance/0.5) + 1.
 
It's an old trick and you can use it to group into much ;larger groups if you use a larger divisor.  I've added the 1 to produce the same as your recodes.
 
----- Original Message -----
Sent: Saturday, January 29, 2011 2:45 AM
Subject: recode help

Hi All,

I have a distance dataset where the distance ranges from 0.01 km to 100 km. I need to create e frequency table where each class width will be 0.5 km. For this, I have to recode the DISTANCE variables like this-

recode DISTANCE (lowest thru 0.49=1) (0.5 thru 0.99=2) (1 thru 1.49=3)..... (100 thru Highest = 201) into re_DISTANCE.

I was wondering if there is a shortcut for this. Otherwise I'd have to write a tedious syntax to create 200 distance classes (0 to 100 km, class width = 0.5). Any help?

Thanks in advance!
Tufayel 

Reply | Threaded
Open this post in threaded view
|

Re: recode help

Jon K Peck
In reply to this post by Tufayel Chowdhury
Use the Visual Binner from the Transform menu.  It provides binning by fixed intervals, by percentages, or based on moments of the distribution.  It can automatically generate value labels for the output, too.

HTH,

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        Tufayel Chowdhury <[hidden email]>
To:        [hidden email]
Date:        01/28/2011 06:52 PM
Subject:        [SPSSX-L] recode help
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi All,

I have a distance dataset where the distance ranges from 0.01 km to 100 km. I need to create e frequency table where each class width will be 0.5 km. For this, I have to recode the DISTANCE variables like this-

recode DISTANCE (lowest thru 0.49=1) (0.5 thru 0.99=2) (1 thru 1.49=3)..... (100 thru Highest = 201) into re_DISTANCE.

I was wondering if there is a shortcut for this. Otherwise I'd have to write a tedious syntax to create 200 distance classes (0 to 100 km, class width = 0.5). Any help?

Thanks in advance!
Tufayel

Reply | Threaded
Open this post in threaded view
|

Re: recode help

Jon K Peck
In reply to this post by John F Hall
That works fine, but using the Visual Binner has the advantage that it generates value labels for the result.  And it can paste the syntax, too.

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        John F Hall <[hidden email]>
To:        [hidden email]
Date:        01/29/2011 05:58 AM
Subject:        Re: [SPSSX-L] recode help
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Try something like (untested, but assuming your distances are to 2 or more decimal places):
 
compute kmgroup = trunc (distance/0.5) + 1.
 
It's an old trick and you can use it to group into much ;larger groups if you use a larger divisor.  I've added the 1 to produce the same as your recodes.
 
John Hall
johnfhall@...
http://surveyresearch.weebly.com
----- Original Message -----
From: Tufayel Chowdhury
To: [hidden email]
Sent: Saturday, January 29, 2011 2:45 AM
Subject: recode help

Hi All,

I have a distance dataset where the distance ranges from 0.01 km to 100 km. I need to create e frequency table where each class width will be 0.5 km. For this, I have to recode the DISTANCE variables like this-

recode DISTANCE (lowest thru 0.49=1) (0.5 thru 0.99=2) (1 thru 1.49=3)..... (100 thru Highest = 201) into re_DISTANCE.

I was wondering if there is a shortcut for this. Otherwise I'd have to write a tedious syntax to create 200 distance classes (0 to 100 km, class width = 0.5). Any help?

Thanks in advance!
Tufayel