Similar to if, by can be used in combination with a lot of other commands.
One particularly great application is to use it together with different types of graphs (e.g. bar charts, histograms, and scatterplots).
More informationhelp by |
Practical example
| Dataset |
| StataData1.dta |
| Variable name | educ |
| Variable label | Educational level (Age 40, Year 2010) |
| Value labels | 1=Compulsory 2=Upper secondary 3=University |
| Variable name | sex |
| Variable label | Sex |
| Value labels | 0=Man 1=Woman |
graph bar, over(educ) by(sex) |

This gives us two bar charts of educational level – one for men and one for women.