I am having a problem with creating a bar graph/ histogram with 4 different variables. The variables are discrete values from 1 to 4. I want to present each variable on its own with the respective percentages for each value. I am using STATA version 16 for Windows.


I want to present the variables p1, p2, p3 and p4 with the respective percentage of the occurrence of 1, 2, 3, or 4 in a bar graph or histogram. You can find example data and the illustration below.


1. My first approach so far was to use twoway:

. twoway (hist p1, discrete percent color(blue)) (hist p2, discrete percent color(yellow)) (hist p3, discrete percent color(green)) (hist p4, discrete percent color(red))
  • here the problem is that the variables are not illustrate besides each other (as in the excel graph below).


2. The second idea was to use graph bar

. graph bar p1 p2 p3 p4
  • here I am unsure how to adjust the code for receiving the percentage of the occurrences.

Does somebody has an idea for how to solve the problem?

obs p1 p2 p3 p4
1 1 3 4 2
2 3 4 2 1
3 1 3 4 2
4 1 3 2 4
5 1 3 4 2
6 1 2 3 4
7 1 2 4 3
8 3 1 4 2
9 1 4 2 3
10 2 1 4 3
11 1 2 4 3
12 2 3 4 1
13 1 4 2 3
14 2 1 4 3
15 1 3 4 2
16 4 3 1 2

Array