Introduction
The distributions of continuous variables can be depicted in numerous ways, including through the use of histograms and box plots. The advantage of a violin plot is of combining a histogram and a box plot in the same graphic. In this blog, we’ll show you how to create a violin plot in Stata.
Install Violin Plot
Violin plot is a user-written command, so you need to install it first:
ssc install vioplot
Create Data
First, we’ll create mock data, then we’ll show you how to apply the list command. Let’s assume we’re measuring IQ for 1,000 subjects.
set obs 1000
gen iq_a = runiform(90,140)
gen iq = round(iq_a)
drop iq_a
label variable iq "IQ"
Generate the Violin Plot
vioplot iq
Here’s what you get:
If you look at the violin plot sideways, it depicts a histogram. Vertically, there is a box plot within the histogram, including the mean, interquartile range, and 95% confidence interval.
BridgeText can help you with all of your statistical analysis needs.