Stata Help

Histograms in Stata

If you are new to histograms in Stata, you might find it more intuitive to go to the Graphics menu and select Histogram. This is a good way to see all the options available and if you want a highly specific histogram, it may in fact be faster to specify your options in this manner. When you execute a command using the user interface, Stata will display the syntax in the Results window, so this can be a good way to get a feel for how you would do things via the Command window.

Both tables and histograms are great ways to get a good look at your data over all trends and leanings, and can be useful precursors to analysis.

The command to create a histogram is histogram. The histogram command takes a variety of arguments, the most important being the variable you want, which comes next.

The default histogram graphs density along the y-axis, which is not typically what people want from a histogram. For a standard frequency histogram, you can add the frequency option. Other options (typed in place of frequency) are percent (which puts percent out of a hundred on the y-axis) or fraction (which displays the data as a decimalized proportion). 

Thus to create a basic frequency histogram of variable X, you would type histogram [indep variable], frequency.

In addition, you can do a number of things to customize your histogram, both obvious things such as titles and less obvious things such as specifying how wide each bar is or at what number the histogram should start. Basic elements like titles are added by appending the sub-command, and then specifying the details in parentheses. For example, to make a frequency histogram with a title, the full command would become histogram variableX, frequency title(Histogram of VariableX) The comma tells Stata that what follows are options and not more variables. If you run the same line of command without the comma, it will not work and the Review window will show "variable frequency not found."

Back to The Sample Session

Back to Tutorials