Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Order Overlapping Percentage Bar Graphs for Categorical Variable

    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...
    Click image for larger version

Name:	1.PNG
Views:	1
Size:	86.6 KB
ID:	1697266
    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:
    Click image for larger version

Name:	2.PNG
Views:	1
Size:	88.1 KB
ID:	1697267
    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
    Last edited by Mathis Mueller; 14 Jan 2023, 06:45.

  • #2
    On (re-)ordering categorical variables see

    https://www.statalist.org/forums/for...e-or-graph-use

    and especially the Stata Journalpaper cited in that thread.

    Comment

    Working...
    X