Computing new variable from variable with multiple observations fromthe same respondent

Discussion in 'SPSS' started by Jeppe Christensen, Oct 12, 2011.

  1. Confusing subject, but it's hard to describe.

    I have two variables:

    var1. Variable with a unique respondent number
    var2. Variable with a study number (1-3)

    The respondents can have participated in one, two or three studies,
    and they will figure a corresponding number of times on my two
    variables. So a unique respondent can figure multiple times in the
    data, with different values on var2.

    Problem: I want to compute a new variable that tells me which studies
    the respondents have participated in.

    Hope I made myself clear:)

    Jeppe Christensen, Oct 12, 2011
    1. Advertisements

  2. Jeppe Christensen

    Bruce Weaver Guest

    Do you mean you want a single new variable added to the data file with
    multiple rows (potentially) per ID? Something like this will do it, I

    * Read in some data to illustrate.
    new file.
    dataset close all.
    data list list / ID StudyNum (2f5.0).
    begin data
    1 1
    1 2
    2 3
    3 2
    3 3
    4 1
    4 2
    4 3
    5 1
    6 2
    end data.

    /f1=FIN(StudyNum 1 1)
    /f2=FIN(StudyNum 2 2)
    /f3=FIN(StudyNum 3 3)

    compute Studies = (f1 GT 0) + (f2 GT 0)*10 + (f3 GT 0)*100.
    variable labels Studies "Studies for this ID".
    value labels Studies
    1 "S1"
    10 "S2"
    11 "S1, S2"
    100 "S3"
    101 "S1, S3"
    110 "S2, S3"
    111 "S1, S2, S3"
    frequencies Studies.
    delete variables f1 to f3.

    If this is not what you're after, please clarify.
    Bruce Weaver, Oct 12, 2011
    1. Advertisements

  3. Thanks a lot Bruce, your syntax proved to be the solution

    Jeppe Christensen, Oct 14, 2011
    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.