SPSS tutorials website header logo SPSS TUTORIALS BASICS ANOVA REGRESSION FACTOR CORRELATION

Include Empty Categories in Output

Question

“I have some empty categories in my data. For example, none of my respondents filled out "politician" as their job. Therefore, "politician" is completely absent from crosstabs. How can I include it with a zero frequency?”

SPSS Include Empty CategoryHow to include an empty category in a crosstab?

Solution

The basic solution here is to add one or more fake cases to the data that do have the absent values. Giving them case weights close to zero includes them in crosstabs with zero frequencies. Although this solution requires a couple of steps, all of them are pretty basic.
Run the syntax below in order to set up the data and run the initial crosstabs. Note that none of our respondents works as a politician (job = 2). Therefore, "politician" doesn't show up in the crosstab. The same goes for "law" as education (education = 3).

SPSS Syntax Example 1

*1. Create data.

data list free/job education gender.
begin data
1 1 0 1 1 0 1 2 0 1 2 0 3 1 1 3 1 1 3 2 1 3 2 1
end data.

dataset name data.

*2. Apply value labels.

value labels job 1 'Statistician' 2 'Politician' 3 'Teacher'.
value labels education 1 'Economics' 2 'Social Sciences' 3 'Law'.
value labels gender 0 'Female' 1 'Male'.

*3. Show value labels in output and make crosstabs.

set tnumbers labels.

crosstabs gender by job education.

Creating Fake Cases

SPSS Syntax Example 2

*1. Create fake cases.

data list free/job education gender.
begin data
2 3 0
end data.

dataset name fakecases.

*2. Assign very small case weights.

compute caseweight = 1E-5.

*3. Merge fake cases into data.

add files file = data/file = fakecases.
exe.

*4. Close original datasets.

dataset close all.

dataset name alldata.

Creating the Desired Tables

SPSS Syntax Example 3

*1. Case weight = 1 for real cases.

if missing(caseweight) caseweight = 1.

*2. Switch on case weights.

weight by caseweight.

*3. Generate desired crosstabs.

crosstabs gender by education job.

*4. When done, delete fake cases.

select if caseweight = 1.
exe.

*5. Deleting caseweight restores original data.

delete variables caseweight.

Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.

THIS TUTORIAL HAS 1 COMMENT: