SPSS Statistics

 View Only
  • 1.  Different variables into one variable

    Posted 22 days ago

    All:

    I have a survey dataset that I am analyzing ins SPSS.  I have separate variables for race categories:

    Variable      Label

    Q4_1          White or Caucasian

    Q4_2          Black or African American

    Q4_3          Hispanic

    Etc.  (8 all together)

    I want to recode these 8 variables into one Combined Variable.  So it will look like:

    Variable                   Label                          Values

    Race_Combined     Race Combined          1 White, 2 Black  3 Hispanic, etc.

    I want to be able to run crosstabs on my other data    

    The field for each variable is 1 (this variable selected) or . (not selected).  Should I replace the (.) with a 0 before combining them?

    I am running version 28 and none of the videos I've watched show exactly my screen.  I tried running this command last night, but I got an error message every time.:

    Copy code

    * Create a new variable with initial missing values.

    COMPUTE Race_Combine = $SYSMIS.

    * Combine the races into the new variable.

    IF (Q4_1 = 1) Race_Combine = 1.

    IF (Q4_2 = 1) Race_Combine = 2.

    IF (Q4_3 = 1) Race_Combine = 3.

    IF (Q4_4 = 1) Race_Combine = 4.

    IF (Q4_5 = 1) Race_Combine = 5.

    IF (Q4_6 = 1) Race_Combine = 6.

    IF (Q4_7 = 1) Race_Combine = 7.

    IF (Q4_8 = 1) Race_Combine =8.

    EXECUTE.

    Error message:

    An expression contains a string of characters followed by a left parenthesis, indicating that the string of characters is a function or vector name, but the characters do not match any existing function or vector.  Check the spelling.



    ------------------------------
    Judith Sylvester
    ------------------------------


  • 2.  RE: Different variables into one variable

    IBM Champion
    Posted 22 days ago
    What you ran must be a little bit different from what is shown as that looks okay, but here is an easier way to do this.  It uses a vector and a loop.

    vector race = q4_1 to q4_8.
    loop #i = 1 to 8.
    do if race(#i) eq 1.
      compute combined = #i.
      break.
    end if.
    end loop.
    exec.

    Note that this and the code you posted assume that only one variable would have the value 1.

    --





  • 3.  RE: Different variables into one variable

    Posted 22 days ago

    Instead of this (COMPUTE Race_Combine = $SYSMIS) try one of these.

    numeric race_combine(f2.0).

    or if text needed

    string race_combine(a5).



    ------------------------------
    Art Jack
    ------------------------------