Combining variables

Discussion in 'SPSS' started by Mutuku, Oct 20, 2011.

  1. Mutuku

    Mutuku Guest

    Hi,

    I want to combine 3 variables into one. I have gender(male =1, female
    =2), age(group1=1, group2=2, group3 =3) and parents age (group1=1,
    group2=2, group3 =3, group4 =4).

    I want to combine then in that I will have

    newvar1 = gender(1), age(1),parents age(1)
    newvar2 = gender(1), age(1),parents age(2)
    newvar3 = gender(1), age(2),parents age(1)
    newvar4 = gender(2), age(1),parents age(1)
    etc

    How do I do this in SPSS?

    Thanks
     
    Mutuku, Oct 20, 2011
    #1
    1. Advertisements

  2. Mutuku

    David Guest

    Create a function to map the values of the 3 variables into 1.
    For 3 dichotomous variables:
    A,B,C
    C | 1 2
    B | 1 2 1 2
    -----|------------------------
    A 1 | 1 3 5 7
    A 2 | 2 4 6 8
    data list free /A B C.
    BEGIN DATA
    1 1 1
    2 1 1
    1 2 1
    2 2 1
    1 1 2
    2 1 2
    1 2 2
    2 2 2
    END DATA.
    COMPUTE ABC=(C-1)*4 + (B-1)*2 + A.
    LIST.
    A B C ABC

    1.00 1.00 1.00 1.00
    2.00 1.00 1.00 2.00
    1.00 2.00 1.00 3.00
    2.00 2.00 1.00 4.00
    1.00 1.00 2.00 5.00
    2.00 1.00 2.00 6.00
    1.00 2.00 2.00 7.00
    2.00 2.00 2.00 8.00
    Number of cases read: 8 Number of cases listed: 8.

    ----------------------------------------------------------------------------
    In general: ABC=(C-1) * (Na*Nb) + (B-1)*Na + A .
    ----------------------------------------------------------------------------
    I will leave it to you to apply this to your specific issue.
    You will have to rethink your specific pattern as what you have
    presented *WILL NOT* readily smash together in a simple function
    (usually for etc to be applicable there needs to be a discernible
    pattern) . Build a table and the math will come!
    HTH, David
     
    David, Oct 20, 2011
    #2
    1. Advertisements

  3. Mutuku

    Rich Ulrich Guest

    - Increment for p_age=2, then age=2?
    - I will assume that it is okay to create the newvars in an
    *easy* systematic order, incrementing for p_age1-4, then
    age1-3, then gender1-2; instead of working by an arbitrary
    order that is as awkward to do, as what you show.
    - Of course, if you do have an arbitrary order, you can
    first create a systematic ordering and then recode to
    your arbitrary one.
    You say that you want to combine 3 variables "into one",
    but then you give an example where you use 3 variables
    to create 4x3x2= 24 dummy variables for exclusive categories.

    Okay. You can create one variable with an index value,
    and then use that index to set the right dummy. Something
    like this (untested) -

    COMPUTE index= p_age+ 4*(age-1) + 12*(gender-1).

    VECTOR newvar(24).
    RECODE newvar1 to newvar24(else=0).
    COMPUTE newvar(index)= 1.
     
    Rich Ulrich, Oct 20, 2011
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.