Lisa
Lisa

Reputation: 893

Recode or compute age categories based by gender

I'm a complete spss-novice and I can't figure it out. Google doesn't give any answers either (or I don't know how to google this question.. that's possible too).

I have to make a new variable based on two variables:

Gender (0=male, 1=female)
and
oudad (1=age 18-29; 2=age 30-54; 3=age 55-89; 4=deselect 99).

The new variable has to have six categories:
1. 18-29 male
2. 18-29 female
3. 30-54 male
4. 30-54 female
.. and so on.

I think I have to do something with either compute or recode into different variables, but can't figure out what to do.

Who can help me?

Upvotes: 2

Views: 1989

Answers (2)

Lisa
Lisa

Reputation: 893

I don't know if it's the 'correct' way to do it, but this is the way I got it done. Advise on how to improve it, is still appreciated :)

IF (gender = 0 & agegroup =1) GenAge=1.
IF (gender = 0 & agegroup =2) GenAge=2.
IF (gender = 0 & agegroup =3) GenAge=3.
IF (gender = 1 & agegroup =1) GenAge=4.
IF (gender = 1 & agegroup =2) GenAge=5.
IF (gender = 1 & agegroup =3) GenAge=6.
EXECUTE.

VALUE  LABELS GenAge 
 1 'Young man'
 2 'Middle-aged man'
 3 'Old man'
 4 'Young woman'
 5 'Middle-aged woman'
 6 'Old woman'.

Upvotes: 3

Jignesh Sutar
Jignesh Sutar

Reputation: 2929

Look up the DO IF and/or IF command.

DO IF (Gender = 0 /* Male*/ AND Age = 1 /* 18 -29 */).
    COMPUTE GenAge=1.
ELSE IF (Gender = 1 /* Female */ AND Age = 1 /* 18 -29 */).
    COMPUTE GenAge=2.
ELSE IF (Gender = 0 /* Male */ AND Age = 2 /* 30 - 54 */).
    COMPUTE GenAge=3.
ELSE IF (Gender = 1 /* Female */ AND Age = 2 /* 30 - 54 */).
    COMPUTE GenAge=4.
ELSE IF (Gender = 0 /* Male */ AND Age = 3 /* 55 - 89 */).
    COMPUTE GenAge=5.
ELSE IF (Gender = 1 /* Female */ AND Age = 3 /* 55 - 89 */).
    COMPUTE GenAge=6.
END IF.

The content between each pair of /* & */ are simply to help make the code more readable and apparent what the code represents and so entirely optional.

Instead of series of IF statements in this manner (which could be even more cumbersome with a large number of categories), I would typically opt for coding something like this in an alternative manner such as follows:

RECODE Gender (0=2) (ELSE=COPY).
VALUE LABELS Gender 1 "Female" 2 Male".
COMPUTE GenAge=SUM(Gender*10, Age).
VALUE LABELS GenAge.
  11 "Female 18 - 29"
  12 "Female 30 - 54"
  13 "Female 55 - 89"
  21 "Male 18 - 29"
  22 "Male 30 - 54"
  23 "Male 55 - 89".

For categorical variables of this nature it is typically irrelevant the code that is assigned to it so I would always prefer a solution which involves writing as little code as possible and that too not being dependent on the data itself too. If the order is of importance you could always choose to have Age represented by the tenth unit integer and Gender the single unit integer.

Upvotes: 2

Related Questions