One-way descriptive summaries depend on the type of variable:
sysuse nlsw88 tab occupation
graph pie, over(occupation)
gen n = 1 graph bar (sum) n, over(occupation)
centile age centile age, centile(25 50 75)
graph box age
Now we will work with several ways of analysing two variables together: bivariate analysis.
We will look at three types of combination:
We will consider numerical and graphical techniques.
Cross-tabulation is the easiest, and quite a powerful, method for looking at the relationship between categorical (nominal, ordinal) or grouped data.
Use the command
to load an extract from the 1991 U.S. General Social Survey.
tab race region
Get either row or column percentages by adding the option
col at the end of the command
(options come after a comma).
What patterns do you see in the table? Which percentages (row or column) are easier
With the same variables, use
graph hbar (count) x, over(race)
over(region) asyvars to create a clustered bar chart (you will
need to do
gen x = 1 first). If you add the option
stack you get a stacked rather than clustered bar chart.
Experiment with both types, and with which variable to use as the
cluster or stack variable. Do you see the same patterns as in the
table? See what happens if you drop the
Sometimes we have a continuous variable that "varies with" a
categorical one. Income may vary with gender, or with educational
bysort groupvar: su continvar
allows us to get the mean value of the continuous variable (continvar) for each
value of the categorical one (groupvar).
With the 1991 U.S. General Social
Survey, look at how occupational prestige (
prestg80) varies with
variables such as region, race and sex (as the group variable).
Graphically, we can represent this with a barchart where the height
of the bar represents the mean of the continuous variable for that
value of the categorical one:
graph hbar (mean) prestg80, over(region).
Box plots focus on medians and quartiles, and give a somewhat
more detailed picture of the distribution than just the mean. Try
graph box prestg80, over(region), etc.
We will find out about numerical methods for summarising the relationship between pairs or interval variables later, but for now the scatterplot is very useful. With the US General Social Survey, compare all three possible pairs of the following variables:
To do this, try
scatter age prestg80 and so on.
What relationships do you see?