coding two variables into one

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

coding two variables into one

J McClure
Hi,
I have two variables; RaceEth1 and RaceEth2 from a survey where
participants were asked to circle their race/ethnicity. However, some
participants circled more than one category (e.g. HIspanic and Pacific
Islander) so entered the data as two different variables.  RaceEth2=0 if
they only circled one category. It turns out only 4% of participants
chose two categories and so I want to create a new variable (or I could
recode RaceEth1) such that participants who marked two categories are
coded as 6 in the new variable. I wrote the below code and forgot about
the missing so got '0' in the new variable Race_Eth when there was a
'99'  (missing) for RaceEth1. I added the line for missing but the new
variable Race_Eth still shows a '0' instead of '99'.
Thanks for any help,
Jan

Compute Race_Eth=0.
If (RaceEth1=99)  Race_Eth=99.
If (RaceEth2=0)  Race_Eth=RaceEth1.
If (RaceEth2>0)   Race_Eth=6.
Variable labels Race_Eth 'Survey race/ethnicity'.
  Freq Race_Eth.
Execute.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: coding two variables into one

John F Hall
Jan
 
Looks as if you've over-ridden the 99 by your 3rd if command which should read:
 
If (RaceEth2>0) and (raceth2 ne 99)  Race_Eth=6.
If is an expensive command to run (especially on vary large data sets) as it passes through the data for each if.
 
You can create a new variable by:
 
compute race_eth = race_eth1 * 10 + race_eth2 .
freq race_eth .
 
then use recode to get the categories you want, combining values from both lists ( including ?? = 99) and use
 
missing values race_eth (99) .
 
----- Original Message -----
Sent: Thursday, August 12, 2010 2:14 AM
Subject: coding two variables into one


Hi,
I have two variables; RaceEth1 and RaceEth2 from a survey where
participants were asked to circle their race/ethnicity. However, some
participants circled more than one category (e.g. HIspanic and Pacific
Islander) so entered the data as two different variables.  RaceEth2=0 if
they only circled one category. It turns out only 4% of participants
chose two categories and so I want to create a new variable (or I could
recode RaceEth1) such that participants who marked two categories are
coded as 6 in the new variable. I wrote the below code and forgot about
the missing so got '0' in the new variable Race_Eth when there was a
'99'  (missing) for RaceEth1. I added the line for missing but the new
variable Race_Eth still shows a '0' instead of '99'.
Thanks for any help,
Jan

Compute Race_Eth=0.
If (RaceEth1=99)  Race_Eth=99.
If (RaceEth2=0)  Race_Eth=RaceEth1.
If (RaceEth2>0)   Race_Eth=6.
Variable labels Race_Eth 'Survey race/ethnicity'.
  Freq Race_Eth.
Execute.

=====================
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

Reply | Threaded
Open this post in threaded view
|

Re: coding two variables into one

John F Hall
It's neater if you recode ALL the values to yeild codes  from 1 to n + 99, then write value labels as necessary.  Are these your varnames or someone else's?  The shorter the better for me, and without the undescore character: too much typing.
----- Original Message -----
Sent: Thursday, August 12, 2010 5:35 PM
Subject: Re: coding two variables into one

Thanks John. I see that I did override with the last line.
I'm not sure I understand the method you suggested using compute.
It looks like I multiply the value for the first variable (you wrote race_eth1 but I think you meant RaceEth1) by 10 which would give me values of 10, 20,30,40,50, 60 and 990, and then add the second variable which would have values of 1 to 6 and 99.
Then I would probably keep the values of 10, 20, 30, 40 etc and recode values of 11,12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23 etc into the 'other' category.
Is this right?
Jan

On 8/12/2010 1:32 AM, John F Hall wrote:
Jan
 
Looks as if you've over-ridden the 99 by your 3rd if command which should read:
 
If (RaceEth2>0) and (raceth2 ne 99)  Race_Eth=6.
If is an expensive command to run (especially on vary large data sets) as it passes through the data for each if.
 
You can create a new variable by:
 
compute race_eth = race_eth1 * 10 + race_eth2 .
freq race_eth .
 
then use recode to get the categories you want, combining values from both lists ( including ?? = 99) and use
 
missing values race_eth (99) .
 
----- Original Message -----
Sent: Thursday, August 12, 2010 2:14 AM
Subject: coding two variables into one


Hi,
I have two variables; RaceEth1 and RaceEth2 from a survey where
participants were asked to circle their race/ethnicity. However, some
participants circled more than one category (e.g. HIspanic and Pacific
Islander) so entered the data as two different variables.  RaceEth2=0 if
they only circled one category. It turns out only 4% of participants
chose two categories and so I want to create a new variable (or I could
recode RaceEth1) such that participants who marked two categories are
coded as 6 in the new variable. I wrote the below code and forgot about
the missing so got '0' in the new variable Race_Eth when there was a
'99'  (missing) for RaceEth1. I added the line for missing but the new
variable Race_Eth still shows a '0' instead of '99'.
Thanks for any help,
Jan

Compute Race_Eth=0.
If (RaceEth1=99)  Race_Eth=99.
If (RaceEth2=0)  Race_Eth=RaceEth1.
If (RaceEth2>0)   Race_Eth=6.
Variable labels Race_Eth 'Survey race/ethnicity'.
  Freq Race_Eth.
Execute.

=====================
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