Table of Contents
A Stem-and-Leaf Plot is a useful tool for organizing and visually representing numerical data. In Stata, creating a Stem-and-Leaf Plot is a simple process that involves using the “stemplot” command. This command allows users to specify which variables to include in the plot, as well as customize the appearance of the plot. The resulting plot consists of a “stem” column, which displays the first digit of the data, and a “leaf” column, which displays the remaining digits. This allows for a quick and easy way to identify the distribution and range of the data. By following a few steps, users can efficiently create a Stem-and-Leaf Plot in Stata to effectively analyze and communicate their numerical data.
Create a Stem-and-Leaf Plot in Stata
A is a chart we can use to display data by splitting up each value in a dataset into a stem and a leaf.
Here is an example of a stem-and-leaf plot for a given dataset, created by the :
The stem for each value is simply the first digit of the value while the leaf is the second digit of the value.
Now let’s find out how to create a stem-and-leaf plot in Stata.
Example: Stem-and-Leaf Plot in Stata
Use the following steps to create a stem-and-leaf plot in Stata.
Step 1: Load the data.
We’ll use a built-in Stata dataset called auto for this example. Load this dataset by typing the following into the command box:
use http://www.stata-press.com/data/r13/auto
Step 2: Create a stem-and-leaf plot for the variable mpg.
Type the following into the Command box and click Enter:
stem mpg
This produces the following stem-and-leaf plot for all of the values for mpg:
By default, Stata splits the stems into multiple lines. You can specify that each stem only uses one line by using the lines() command:
stem mpg, lines(1)
Notice how each stem now has all of its values on one line.
We can also create a stem-and-leaf plot for another variable in the dataset called price, which represents the price of each car in the dataset and takes on values in the thousands.
stem price
We can also use the round() command to round numbers. For example, we can use round(100) to specify that each value of price should be rounded to the hundreds place:
stem price, round(100)
Or we can specify each price to be rounded to the tens place:
stem price, round(10)
Lastly, we can use the command prune to avoid printing any stems that have no leaves:
stem price, round(10) prune