Population Pyramid Examples (XGRAPH command)

A population pyramid uses bars to show the shape of a distribution split by a categorical variable. The variable used for the distribution can be a scale or categorical. When the variable is scale, the data element type must be HISTOBAR. When the variable is categorical, the data element type is BAR.

Example Using Continuous Data

XGRAPH CHART=([HISTOBAR]) BY age[s] BY gender[c]
  /COORDINATE SPLIT=YES.
  • The bars in the chart represent the number of cases in each age bin.
  • The population pyramid is split by gender.

Example Using Categorical Data

XGRAPH CHART=([COUNT] [BAR]) BY agecat[c] BY gender[c]
  /COORDINATE SPLIT=YES.
  • The agecat variable has categories for different age groups.
  • The bars in the chart represent the number of cases in each agecat category. This is not necessarily the same as the previous example because the size of the bins and the size of the categories might not match.

Example Using Pre-Aggregated Data

XGRAPH CHART=(population [SUM] [BAR]) BY agecat[c] BY gender[c]
  /COORDINATE SPLIT=YES.
  • The bars in the chart represent the number of cases in each agecat category.
  • The data include a population variable that specifies the count for each agecat category for each gender. In other words, the data are pre-aggregated.

Example Using Pre-Aggregated Data Without a Categorical Splitter Variable

In the previous example, there was a categorical variable to use as the splitter variable. In some census data, the data are not organized in this manner. Instead of a splitter variable, there is one variable for each split value. An example follows:

Table 1. Pre-aggregated data without a categorical splitter variable
agecat malepop femalepop
1 247 228
2 306 300
3 311 303

Data in this format needs to be restructured by using the VARSTOCASES command:

VARSTOCASES /ID = id
  /MAKE population FROM malepop femalepop
  /INDEX = gender(2)
  /KEEP = agecat
  /NULL = KEEP.

Running this command results in the following. The splitter variable is gender.

Table 2. Pre-aggregated data with a categorical splitter variable
id agecat gender population
1 1 1 247
1 1 2 228
2 2 1 306
2 2 2 300
3 3 1 311
3 3 2 303

Now a population pyramid can be created using the categorical splitter variable:

XGRAPH (population [SUM] [BAR]) BY agecat[c] BY gender[c]
  /COORDINATE SPLIT=YES.