3

I want to create a new variable from two other variables.

The first is SEX (0=male, 1=female; there were no other genders selected by respondents though we had planned for that possibility) whereas the second is RACE9 (0=white, 1=racialized). The new variable is named SEXRACE9.

While the following code produces counts for white males, racialized males, white females and racialized females, the code fails to produce a count for total male or total female.

* Create combined sex and race categorical variable. 

IF (sex=0 AND (race9=0 OR race9=1)) sexrace9=1. /*Total males - glitchy.
IF sex=0 AND race9=1 sexrace9=2. /*White males.
IF sex=0 AND race9=0 sexrace9=3. /*Racialized males.
IF (sex=1 AND (race9=0 OR race9=1)) sexrace9=4. /*Total females - glitchy.
IF sex=1 AND race9=1 sexrace9=5. /*White females.
IF sex=1 AND race9=0 sexrace9=6. /*Racialized females.
EXECUTE.

Am I missing something? Alternately, does anyone have a solution for how to insert a count for total males and total females using COMPUTE? Any help is greatly appreciated.

rabidotter
  • 31
  • 5
  • See my answer below explaining why the `Total` lines seem glitchy. They are not :). But in any case, please explain in more details what you are trying to achieve with those two lines – horace_vr Dec 17 '17 at 20:01
  • I am trying to create one variable to use on an x-axis for a bar chart. However, I'm beginning to think what I really need to do is figure out how to get GPL to allow me to add two different variables to the same x-axis. – rabidotter Dec 22 '17 at 08:50

1 Answers1

2

You are missing two key aspects:

  1. Your sexracevariable is intended to define mutually exclusive groups (i.e. - each case will belong to one group, and no case could qualify for more than one group)

  2. SPSS syntax is being run sequentially, line by line, so a syntax line can overwrite previous lines.

More to the point:

IF (sex=0 AND (race9=0 OR race9=1)) sexrace9=1.

is being partially overwritten by

IF sex=0 AND race9=1 sexrace9=2. /*White males.

because white males would qualify for both sexrace=1 and sexrace=2. , and then by the line

IF sex=0 AND race9=0 sexrace9=3. /*Racialized males.

, because Racialized males qualify for both sexrace=1 and sexrace =3.

So I am guessing that no cases ghave sexrace=1 after running your syntax :) Exactly the same logic goes for Females.

I am not sure what you want to achieve by your Total Males and Total Femalessyntax lines. You already have the sexvariable to differentiate between males and females.

horace_vr
  • 3,026
  • 6
  • 26
  • 48
  • Thanks for clarifying some of my problems, Horace. I had an inkling things were getting written over, but your explanation makes clear why this is happening. I want this variable so I can then make a publication-quality bargraph of sexrace on the X-axis and MEAN(income) on the Y-axis. Additionally, I will use the sexrace variable to construct another variable that also incorporates age-cohort for another bargraph's x-axis. – rabidotter Dec 18 '17 at 21:39
  • Also, the only cases that are showing up in the Total male and Total female are the SYSMIS cases. – rabidotter Dec 18 '17 at 21:45