Announcement

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

  • Show percent within a category on a bar graph

    I am trying to show the percent of a category on a bar graph, when I use the option 'percentage' it shows the percent of the group, where I want the "row" percent of that subgroup (when I leave percentage out, it gives the proportion - which is what I want on the graph but in %)

    This code:
    Code:
    graph bar HIV2, over(Income, relabel(1 "Low & low-middle" 2 "Upper-middle" 3 "High") ///
     label(angle(forty_five))) over(group, relabel(1 "2000-2003" 2 "2004-2006" 3 "2007-2009" 4 "2010-2012" 5 "2013-2015")) ///
      scheme(s2color) ytitle(Proportion) ///
     blabel(bar, format(%4.1f) size(vsmall)) ///
    graphregion(fcolor(white)) ///
     asyvars bar(1, fcolor(ebg)) bar(2, fcolor(ebblue)) bar(3, fcolor(edkblue))
    gives:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	28.2 KB
ID:	1511906


    How can I get those proportions as percents without using something like catplot?

  • #2
    without using something like catplot
    (that's from SSC, as you're asked to explain).

    Using the extra options

    Code:
    yla(0 0.1 "10" 0.2 "20" 0.3 "30") ytitle(Percent (%)) 
    may be as much as you need. Otherwise bear in mind that graph bar is here just showing means, so to see numbers 100 times bigger you just need to multiply by 100, as

    100 x mean(foo) = mean(100 x foo)

    Code:
    gen toshow = HIV2 * 100 
    
    graph bar toshow ....
    if that doesn't answer the question I'd give a data example (FAQ Advice #12). All you need to do is


    Code:
    collapse HIV2, by(group income) 
    dataex

    Comment


    • #3
      Thanks Nick, I think the second section of code will work with what I need.

      Comment

      Working...
      X