I would like to make a graph bar but with percentages instead of the count. However, I am interested that those percentages to be 100% for each bar in total. In fact, I would like to mimic the percentage in the table below. Adding the option "percent" to the graph I´ll show below gives the percentages over the whole quantity, which is what I do not want to.
Is there any simple way to do it?
Thanks in advance.
Code:
tab x1 year, col
Code:
| year x1 | 2014 2017 2020 | Total -----------+---------------------------------+---------- 1 | 1,775 2,170 2,756 | 6,701 | 27.58 28.21 32.03 | 29.48 -----------+---------------------------------+---------- 2 | 4,660 5,522 5,848 | 16,030 | 72.42 71.79 67.97 | 70.52 -----------+---------------------------------+---------- Total | 6,435 7,692 8,604 | 22,731 | 100.00 100.00 100.00 | 100.00
Code:
graph bar (count) x1, over(x2) over(year) asyvar stack blabel(bar, box bfcolor(white) pos(center) format(%4.2f) size(medium)) legend(off) ytitle("") title("from 2014")
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(year x1 x2) 2014 1 1 2014 1 1 2014 2 2 2014 1 1 2014 2 2 2014 2 2 2014 1 1 2014 2 2 2014 2 2 2014 2 2 2014 . . 2014 . . 2014 . . 2014 2 2 2014 2 2 2014 2 2 2014 2 2 2014 2 2 2014 2 2 2014 2 2 2017 . . 2017 1 1 2017 2 2 2017 . . 2017 2 2 2017 2 2 2017 . . 2017 2 2 2017 1 1 2017 1 1 2017 2 2 2017 2 2 2017 2 2 2017 1 1 2017 2 2 2017 2 2 2017 2 2 2017 1 1 2017 1 1 2017 1 1 2017 2 2 2020 2 2 2020 1 1 2020 2 2 2020 1 1 2020 . . 2020 . . 2020 1 1 2020 1 1 2020 1 1 2020 2 2 2020 2 2 2020 2 2 2020 2 2 2020 2 2 2020 2 2 2020 2 2 2020 1 1 2020 2 2 2020 2 2 2020 2 2 2020 2 2 end
0 Response to creating a percentage graph bar
Post a Comment