IBM Support

How to display empty, or unselected, categories in SPSS standard charts.

Question & Answer


Question

I have a categorical variable which I would like to display in a bar chart. However, one of my categories was not selected by any of my respondents. I can generate a frequency distribution and bar chart for this variable, but the unselected category is not included. How can I both generate a frequency distribution to show a zero count for this category, as well as generate a bar chart which also reflects a zero frequency?

Answer

Chart Builder was introduced in SPSS 14.0.x which uses the GGRAPH command in syntax. GGRAPH displays empty categories by default as long as you have a value label defined for the empty category.

The following sample job illustrates an example:

* Create a sample data set.
INPUT PROGRAM.
LOOP #I = 1 TO 100.
COMPUTE x = (TRUNC(UNIFORM(3)) + 1).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.

VALUE LABELS x 1 'A' 2 'B' 3 'C' 4 'D'.

Go to Graphs->Chart Builder.
Drag bar from the gallery to the canvas.
Drag 'x' to the x-axis.
Click ok.

or via syntax:

* Chart Builder.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=x[LEVEL=ORDINAL] COUNT()
[rename="COUNT"] MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: x=col(source(s), name("x"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
GUIDE: axis(dim(1), label("x"))
GUIDE: axis(dim(2), label("Count"))
SCALE: cat(dim(1), include("1.00", "2.00", "3.00", "4.00"))
SCALE: linear(dim(2), include(0))
ELEMENT: interval(position(x*COUNT), shape.interior(shape.square))
END GPL.

As you can see from the example, Category 4 (D) is displayed in the chart.
(If you'd like to exclude this category from display, you may use SCALE: cat(dim(1), exclude ("4.00")) instead)

NOTE: You may also use the Interactive Graph feature to create a bar chart that displays an empty category. To do so, follow these instructions:

Create the chart in SPSS Interactive Graphs through Graphs-->Interactive -->Bar. Select the variables you would like to display on the graph. Click on the 'Options' tab and uncheck the box that says "Exclude empty categories" and press the OK button. The empty category will then appear in the bar chart

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"PF033","label":"Windows"}],"Version":"18.0","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

15434

Document Information

Modified date:
16 April 2020

UID

swg21476105