Announcement

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

  • Graphing stacked categorical data by region

    I have a categorical response variable - Tenure- with 7 different categories. The categories are the ranges of time that people have been in their job. I have an indicator variable for which region of the country each observation is from - Region - .
    I want to create a stacked bar graph that shows the percentages in each category by each region. Ultimately, I would like the graph to look like the one attached (which I brute forced through Excel)
    So the two steps I need to do are:
    1. generate category percentages by regions, and
    2. produce the graph.
    Perhaps the graphing command may be able to do the percentages by region in one step?

    Any help would be much appreciated.
    Thanks,

    David
    Attached Files

  • #2
    Hello David,

    Welcoe to the Stata Forum,

    Unfortunately, you didn't present data for us to work with.

    Please read the FAQ, mainly the topics on how to share data and graphs.

    That said, you probably need to use - graph bar - with the options "stack", "asyvars" and "over".

    Below, a couple of examples related to your query.

    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Marcos gives excellent advice.

      This kind of stacked (divided, subdivided) bar chart is a very popular design, but it

      1. often struggles to show very small proportions (and zeros have to be inferred)

      2. usually requites a legend and thus mental "back and forth" from readers (unless they just glance at a graph and then give up on detailed scrutiny, which I guess wildly is much more common than graph producers want to believe)

      Legends are at best a necessary evil. If you can, lose the legend! Kill the key!

      Alternatives include

      1. two-way or three-way dot charts as supported by graph dot
      See the manual entry or e.g. http://www.stata-journal.com/sjpdf.h...iclenum=gr0034

      2. two-way or three-way bar charts in table layout as supported by tabplot (Stata Journal)
      http://www.statalist.org/forums/foru...updated-on-ssc is a sample thread (and other examples can be found here)

      (I've also encountered the term layered bar charts; I don't understand why layered, but it may be familiar.)

      P.S. A specific comment on the graph in #1 is that all those leading 0. could be removed by showing percents, e.g. 0.12 would just be shown as 12.
      Last edited by Nick Cox; 18 Feb 2017, 03:05.

      Comment

      Working...
      X