Analyze groups of observations
The by option

Many commands have a by option producing statistics for each group defined by a categorical variable.

tabstat infmor , by(continent)Summary statistics by continent
histogram urb, by(continent) A histogram for each continent
graph box urb , by(continent) Boxplot for each continent
The BY prefix

Another way of producing groupwise results is to use the BY prefix supported by most commands (one of the exceptions is the graph command.

The general syntax is:

by varlist1 [(varlist2)] [, sort] :  stata_cmd
bysort varlist1 [(varlist2)]:  stata_cmd

BYSORT is a shortcut, as sorting on the group variable is a requirement for the command to work.

bysort continent: stem urbStem and leaf plot for each continent.
Related commands