Reputation: 2854
I have six columns:
age01 ... age06
They contain a 1
or 0
depending on whether a respondent fits into that age category.
The age categories are mutually exclusive, respondent cannot answer 1 to more than 1, and at least 1 must equal 1.
How can I recode this such that I get a variable with:
respondent age_category
1 age01
2 age01
3 age04
4 age05
5 age06
Once I get this, the next step is to swap out each one of these for a mean value. ie. Age0 -> 24.5. But I am able to do that from the format above.
Upvotes: 2
Views: 955
Reputation: 34406
You can try:
string new_age_string (a10).
do repeat a = age01 to age06 / b = 24.5 34.5 44.5 54.5 64.5 74.5 / c = "age_01" "age_02" "age_03" "age_04" "age_05" "age_06".
if a = 1 new_age = b.
if a = 1 new_age_string = c.
end repeat.
exe.
However, I don't see the wisdom in recoding to the middle value of your age groups - if your intention is to use age as an IV then you'd get the same result just recoding the variable as 1 to 6.
Upvotes: 2
Reputation: 2929
I suspect you want something like this (rather than coding AgeCat as string variables which your post may suggest):
compute AgeCat= sum(age01*1,age02*2,age03*3,age04*4,age05*5).
value labels AgeCat
1 "Age Category 1"
2 "Age Category 2"
3 "Age Category 3"
4 "Age Category 4".
On the off chance (more often than not quite a high chance), the age dichotomies are not mutually exclusive, I would add a few extra lines of code for safe measure, like this:
do if sum(age01 to age05)=1.
compute AgeCat= sum(age01*1,age02*2,age03*3,age04*4,age05*5).
else if sum(age01 to age05)=0.
compute AgeCat= -98.
else if sum(age01 to age05)>1.
compute AgeCat= -99.
end if.
value labels AgeCat
1 "Age Category 1"
2 "Age Category 2"
3 "Age Category 3"
4 "Age Category 4"
-98 "No data"
-99 "Multiple entries".
Upvotes: 2