Analyzing Categorical Variables Separately

When analyzing your data, you sometimes just want to gain some insight into variables separately. The first step in doing so is creating appropriate tables and charts. This tutorial shows how to do so for dichotomous or categorical variables. We recommend you follow along by downloading and opening smartphone_users.sav.

SPSS Smartphone Users Data - Data View

SPSS Frequency Tables

We'd like to know which smartphone brands were most popular in 2011. Our data contains a variable brand_2011 holding the relevant data. Since this is a categorical variable, a suitable table here is a simple frequency table as obtained with FREQUENCIES. The syntax below shows how to run it.

*1. Show value labels and variable labels in output.

set tnumbers labels tvars labels.

*2. Create frequency table.

frequencies brand_2011.


SPSS Frequency Table Categorical Variable

Note that there's some system missing values. Presuming these occurred due to respondents not using a smartphone in the first place, we'll report the figures under “Percent”. Conclusion: in 2011, 33% of our respondents used a Samsung smartphone, making it the most popular brand during that year.

SPSS Bar Charts for Categorical Variable

Our frequency table provides us with the necessary information but we need to look at it carefully for drawing conclusions. Doing so is greatly facilitated by creating a simple bar chart with bars representing frequencies. The fastest way to do so is including it in our FREQUENCIES command but this doesn't allow us to add a title. We'll therefore do it differently as shown by the screenshots below.

SPSS Create Bar Chart with Title 1 SPSS Create Bar Chart with Title 2

SPSS Bar Chart Syntax Example

*Bar chart with title for brand_2011.

/BAR(SIMPLE)=COUNT BY brand_2011
/title 'All Respondents (n = 566)'.


SPSS Bar Chart with Title

We now have our basic bar chart. For a serious report, however, you probably want a better looking chart. A great way for prettifying charts is discussed in SPSS Chart Templates - Quick Introduction.

System Missing Values

Thus far, we simply ignored the system missing values we saw in our frequency table. For nominal variables, an alternative approach is including them as just another answer category. The syntax below does just that for all brand variables. We'll first inspect which values are present. Next, we'll RECODE system missing values into a value that wasn't present yet. In our case that will be 6.

SPSS RECODE Syntax Example

*1. Show values and value labels in output tables.

set tnumbers both.

*2. Inspect which values are present in brand variables.

frequencies brand_2011 to brand_2015.

*3. Change system missing values to 6.

recode brand_2011 to brand_2015 (sysmis = 6).

*4. Apply value label to new value.

add value labels brand_2011 to brand_2015 6 '(No answer)'.

*5. Show only value labels in output tables.

set tnumbers labels.

*6. Rerun frequency tables.

frequencies brand_2011 to brand_2015.


SPSS Frequency Table 2

Note that our frequency table no longer includes any missing values. They've been converted to 6, which is labeled “(No answer)” and occurs 30 times for this variable.
We see that recoding system missing values make our frequency tables look better but there's another advantage: because the brand variables don't contain missing values anymore, their bar charts will all be based on the same number of respondents. This circumvents the need for specifying different numbers of respondents in their titles; we can create them very easily by copy-pasting-editing the syntax we used previously. The syntax below illustrates the idea.

SPSS Bar Charts Syntax Example

*Create bar charts for several brand variables.

GRAPH /BAR(SIMPLE)=COUNT BY brand_2011 /TITLE='All Respondents (n = 596)'.

GRAPH /BAR(SIMPLE)=COUNT BY brand_2012 /TITLE='All Respondents (n = 596)'.

GRAPH /BAR(SIMPLE)=COUNT BY brand_2013 /TITLE='All Respondents (n = 596)'.


SPSS Bar Chart with Title

Tell us what you think!

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