I would like to order a bar graph in ascending order. The graph consists of a categorical variable which I divided into two groups based on a dummy variable. I would like that this two graphs are overlapping, so you can see the differences between the dummy variable. Like this one, but just in ascending order...

I used this code:
tw (hist occupation if inlist(dummy,1), fcolor(gs8%30) lcolor(gs8%30) discrete percent barwidth(.8)) ///
(hist occupation if inlist(dummy,0), fcolor(cranberry%30) lcolor(cranberry%30) discrete percent barwidth(.8)),
ytitle("Percentage", size(*1.2)) ///
xlabel(1(1)13, valuelabel angle(45) labsize(*1.2)) ///
ylabel(, labsize(*1) angle(horizontal) grid glc(gs15) noticks) ///
ysc(titlegap(3) noline) ///
ylabel(#6) ///
xtitle("", size(*0.8)) ///
legend(order(1 2) pos(6) rows(1) size(*1) label(2 "0") label(1 "1"))
How can I make the bars in a ascending order?
If I have just one variable, it's possible to do it with "graph bar" like in this example:

Code: graph bar (count), over(occupations, sort(1) gap(*0.7) label(angle(45) labsize(*1.2) ticks)) bar(1, color(cranberry%60))
I did not found any source how to sort a histogram with categorical variables and graph bar (count) does not allow twoway plot.
Can someone help me?
Greetings,
Mathis
I used this code:
tw (hist occupation if inlist(dummy,1), fcolor(gs8%30) lcolor(gs8%30) discrete percent barwidth(.8)) ///
(hist occupation if inlist(dummy,0), fcolor(cranberry%30) lcolor(cranberry%30) discrete percent barwidth(.8)),
ytitle("Percentage", size(*1.2)) ///
xlabel(1(1)13, valuelabel angle(45) labsize(*1.2)) ///
ylabel(, labsize(*1) angle(horizontal) grid glc(gs15) noticks) ///
ysc(titlegap(3) noline) ///
ylabel(#6) ///
xtitle("", size(*0.8)) ///
legend(order(1 2) pos(6) rows(1) size(*1) label(2 "0") label(1 "1"))
How can I make the bars in a ascending order?
If I have just one variable, it's possible to do it with "graph bar" like in this example:
Code: graph bar (count), over(occupations, sort(1) gap(*0.7) label(angle(45) labsize(*1.2) ticks)) bar(1, color(cranberry%60))
I did not found any source how to sort a histogram with categorical variables and graph bar (count) does not allow twoway plot.
Can someone help me?
Greetings,
Mathis
Comment