Stata has excellent graphics facility. In this blogpost I will demonstrate how to create five types of graphs in Stata: Histogram, Box plot, bar chart, and a pie chart. I will use the Framingham dataset – framingam.dta – that can be downloaded HERE. To see the codesheet read my blogpost on Descriptive Statistics.
The choice of the type of graph to use depends on the type of data available. Quantitative data can be displayed using histogram, box plot, or a scatter plot. Qualitative/Categorical data on the other hand are most frequently displayed using a bar chart and less frequently using a pie chart.
All graphs can be accessed from Stata’s Graphics menu on top of the screen.
Let’s graph the variable total cholesterol. Since this is a continuous variable we can graph histogram or a box plot. Let’s look at the histogram first. Graphics > Histogram. You can also use Stata’s command
histogram total_chol, normal
in the Command Window and press Enter to run the command. The option normal specifies that the histogram be overlaid with an appropriately scaled normal density curve.
The histogram and the overlaid normal curve shows that the total cholesterol data is slightly right skewed. You can confirm this by running descriptive statistics.
The median is lower than the mean indicating right skewness and the skewness is > 0, a positive number confirming data is slightly skewed toward the right.
Let’s display the data using a box plot. Graphics > Box plot
graph box total_chol
Box plots provide a five number summary of the data
- Median– 50th Percentile
- First quartile– 25th Percentile
- Third quartile– 75th Percentile
Box plots are especially useful for comparing two or more plots. For example, to compare total cholesterol levels between men (coded as 1) and women (coded as 0) click on the By option and select male to display the data by gender. The Stata command is:
graph box total_chol, by(male)
Graphics > Bar Chart
Bar charts are frequently used to display nominal or ordinal data. For example, to graph gender we can use the following Stata command:
graph bar, over(male)
graph bar (count), over(male)
Graphics > Pie Chart
Pie charts are also used to display qualitative data. For example, we can plot the four-category blood pressure variable – BP4 – using the following Stata command:
graph pie, over(bp4)