Recoding many values

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

Recoding many values

E. Bernardo
Dear All,
 
A datafile has only one variable X with n=2000.  The X is a count variable which values range between 0 and 150. The goal is to create another variable Y based on the values of X.  Rather than using a formula to recode or compute Y, a new value is assigned for each value of X (old value)  which looks like as follows. 
 
Old values        New Values
0                     4
1                     7
2                     13
3                     17
4                     19
.
.
.
150                  100
 
The "new-old data" above are stored in the separate SPSS data file.  Clearly, using a recode procedure is quite tedeous.  Do you know of a quickest procedure that can be used do create Y?
 
Thank you.
Eins


Surf faster.
Internet Explorer 8 optmized for Yahoo! auto launches 2 of your favorite pages everytime you open your browser.Get IE8 here! (It's free)
Reply | Threaded
Open this post in threaded view
|

Re: Recoding many values

Hector Maletta

You may use match files more or less thus:

  1. Prepare a small file (“table”) with old and new values. Old values in a variable with the same name as in the main file. Sort the table by old values. Save this table.
  2. Open main file. Sort cases in the main file by old variable
  3. Match files /file=* /table = (filename of the table of old and new values) /by (old variable).
  4. Sort the resulting file (if desired) by whatever criteria you want it sorted (if necessary), e.g. by ID.
  5. Save resulting matched file (under a new name, for safety).

This should do the trick. The resulting new file will have the old and new values.

Hector


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eins Bernardo
Sent: 01 February 2010 10:14
To: [hidden email]
Subject: Recoding many values

 

Dear All,

 

A datafile has only one variable X with n=2000.  The X is a count variable which values range between 0 and 150. The goal is to create another variable Y based on the values of X.  Rather than using a formula to recode or compute Y, a new value is assigned for each value of X (old value)  which looks like as follows. 

 

Old values        New Values

0                     4

1                     7

2                     13

3                     17

4                     19

.

.

.

150                  100

 

The "new-old data" above are stored in the separate SPSS data file.  Clearly, using a recode procedure is quite tedeous.  Do you know of a quickest procedure that can be used do create Y?

 

Thank you.

Eins

 


Surf faster.
Internet Explorer 8 optmized for Yahoo! auto launches 2 of your favorite pages everytime you open your browser.Get IE8 here! (It's free)

Reply | Threaded
Open this post in threaded view
|

Re: Recoding many values

Jon K Peck
In reply to this post by E. Bernardo

Here is a way to do lookup-based recodes using the SPSSINC TRANS extension command available from SPSS Developer Central.  (It requires the Python programmability plugin and the extension command and extendedTransforms modules).

In this example, the recode keys and values are stored in an open sav file (dataset) named lookup.
The main dataset is named main.

* The lookup table.
data list free/ value(F8.0) akey(A1).
begin data
10 'a'
20 'b'
100 'z'
end data.
dataset name lookup.

* The main dataset.
data list free/x(f8.0) y(A2).
begin data
1 'a'
2 'b'
5 'a '
10 ''
1 'b'
end data.
dataset name main.
dataset activate main.


Now the result is obtained with this extension command by first initializing a lookup table with the INITIAL subcommand and then applying the transformation specified in the FORMULA subcommand generating a variable named resultcodealpha.

SPSSINC TRANS RESULT = resultcodealpha
/INITIAL "extendedTransforms.vlookup('akey', 'value', 'lookup')"
/FORMULA func(y).

Neither dataset needs to be sorted.

HTH,
Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Eins Bernardo <[hidden email]>
To: [hidden email]
Date: 02/01/2010 06:19 AM
Subject: [SPSSX-L] Recoding many values
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Dear All,
 
A datafile has only one variable X with n=2000.  The X is a count variable which values range between 0 and 150. The goal is to create another variable Y based on the values of X.  Rather than using a formula to recode or compute Y, a new value is assigned for each value of X (old value)  which looks like as follows.
 
Old values        New Values
0                     4
1                     7
2                     13
3                     17
4                     19
.
.
.
150                  100
 
The "new-old data" above are stored in the separate SPSS data file.  Clearly, using a recode procedure is quite tedeous.  Do you know of a quickest procedure that can be used do create Y?
 
Thank you.
Eins



Surf faster.
Internet Explorer 8 optmized for Yahoo! auto launches 2 of your favorite pages everytime you open your browser.
Get IE8 here! (It's free)

Reply | Threaded
Open this post in threaded view
|

Re: Recoding many values

John F Hall
In reply to this post by E. Bernardo
If n is the same for both files and the cases are in the same order, I think you can use you can use
 
match files /file = <file1.sav> /file = <file2.sav> .
save out <file3.sav> .
 
where you supply your own <filename>
 
----- Original Message -----
Sent: Monday, February 01, 2010 2:13 PM
Subject: Recoding many values

Dear All,
 
A datafile has only one variable X with n=2000.  The X is a count variable which values range between 0 and 150. The goal is to create another variable Y based on the values of X.  Rather than using a formula to recode or compute Y, a new value is assigned for each value of X (old value)  which looks like as follows. 
 
Old values        New Values
0                     4
1                     7
2                     13
3                     17
4                     19
.
.
.
150                  100
 
The "new-old data" above are stored in the separate SPSS data file.  Clearly, using a recode procedure is quite tedeous.  Do you know of a quickest procedure that can be used do create Y?
 
Thank you.
Eins


Surf faster.
Internet Explorer 8 optmized for Yahoo! auto launches 2 of your favorite pages everytime you open your browser.Get IE8 here! (It's free)
Reply | Threaded
Open this post in threaded view
|

Re: Recoding many values

John F Hall
In reply to this post by Hector Maletta
Hector
 
Should have read yours first before jumping in.
 
John
----- Original Message -----
Sent: Monday, February 01, 2010 2:39 PM
Subject: Re: Recoding many values

You may use match files more or less thus:

  1. Prepare a small file (“table”) with old and new values. Old values in a variable with the same name as in the main file. Sort the table by old values. Save this table.
  2. Open main file. Sort cases in the main file by old variable
  3. Match files /file=* /table = (filename of the table of old and new values) /by (old variable).
  4. Sort the resulting file (if desired) by whatever criteria you want it sorted (if necessary), e.g. by ID.
  5. Save resulting matched file (under a new name, for safety).

This should do the trick. The resulting new file will have the old and new values.

Hector


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eins Bernardo
Sent: 01 February 2010 10:14
To: [hidden email]
Subject: Recoding many values

 

Dear All,

 

A datafile has only one variable X with n=2000.  The X is a count variable which values range between 0 and 150. The goal is to create another variable Y based on the values of X.  Rather than using a formula to recode or compute Y, a new value is assigned for each value of X (old value)  which looks like as follows. 

 

Old values        New Values

0                     4

1                     7

2                     13

3                     17

4                     19

.

.

.

150                  100

 

The "new-old data" above are stored in the separate SPSS data file.  Clearly, using a recode procedure is quite tedeous.  Do you know of a quickest procedure that can be used do create Y?

 

Thank you.

Eins

 


Surf faster.
Internet Explorer 8 optmized for Yahoo! auto launches 2 of your favorite pages everytime you open your browser.Get IE8 here! (It's free)

Reply | Threaded
Open this post in threaded view
|

SPSSINC SUMMARY TTEST

Jon K Peck
In reply to this post by Jon K Peck

Following on the discussion last week on this list about doing t tests from just the summary data, I have produced a new Python-based extension command for this.  It includes a dialog box interface and traditional SPSS-style syntax definition.  The output is a set of pivot tables.  You can download the package from SPSS Developer Central, www.spss.com/devcentral.  I would like to thank Marta García-Granero for her inspiration and assistance with this.

This command requires at least version 17 and the Python programmability plugin.

Regards,

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435