Command reference
tabulate — count categories and compare groups
Count the observations in each category, or cross-tabulate two categorical variables. Add percentages to compare differently sized groups or summarize a numeric variable within categories.
Syntax
tabulate rowvar [columnvar] [if condition] [in range] [, options]
With one variable, the table reports category frequencies, percentages, and cumulative percentages. With two variables, the first defines rows and the second defines columns. Numeric codes and string categories can both be tabulated. if and in restrict the sample. tab is an alias for tabulate.
Options
Example
The example counts the four race codes in 24 synthetic student records, then cross-tabulates race with the zero/one female variable.
clear
import delimited "data/student_scores.csv"
tabulate race
tabulate race female
Sample data included. Opens in a new tab; click Run.
What to look for
Every race code appears six times, so each is 25% of the sample. Within every race code, three records have female=0 and three have female=1. These balanced counts were built into the teaching data; they describe no real population.
| Race code | female = 0 | female = 1 | Total |
|---|---|---|---|
| 1 | 3 | 3 | 6 |
| 2 | 3 | 3 | 6 |
| 3 | 3 | 3 | 6 |
| 4 | 3 | 3 | 6 |
| Total | 12 | 12 | 24 |