Announcement

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

  • A method to change a bar graph's labels to percentages of total?

    Hi there,

    Nearly brand new to Stata, and I'm trying to create a bar graph whose bar labels are that bar's percentage of the total number of survey participants, rather than a raw number.

    Is there a way to do this with the "blabel" command? It seems to only allow for a "total" figure.

    Thanks!

  • #2
    You have not showed us the syntax you tried.

    This is possible with graph bar (if that is what you are using) in updated Stata 13.1. See http://www.stata.com/help.cgi?graph_bar

    Alternatively consider catplot (SSC).

    Comment


    • #3
      See also e.g. http://stackoverflow.com/questions/2...abels-in-stata for yet another way to do it.

      Comment


      • #4
        Hi, thanks for your reply, Nick. Here's the syntax in which I'm trying to get percentage labels:

        Code:
        graph hbar (sum) Q2_1 (sum) Q2_2 (sum) Q2_3 (sum) Q2_4 (sum) Q2_5 (sum) Q2_6 (sum) Q2_7 (sum) Q2_8 (sum) Q2_9 (sum) Q2_10 (sum) Q2_11 (sum) Q2_12 (sum) Q2_13 (sum) Q2_14 (sum) Q2_15 (sum) Q2_16 (sum) Q2_17, blabel(total)
        This command yields the attached graph, which you'll see shows total figures for each bar, whereas I'd like those labels to be a percentage of the total number of participants, which is 1110.

        I am using Stata 13.1 and the command you mentioned, but I haven't found an option for
        Code:
        blabel
        that allows for percentages rather than totals.

        Comment


        • #5
          Note that attachments using the Attachment icon usually work better than Photos: this is explained in the FAQ Advice.

          Puzzling. I am looking at help graph bar which starts as below. Check that you have upgraded your Stata recently, as these extras came in last year.

          -------- update 09oct2014 -----------------------------------------------------

          2. graph bar and graph dot now handle categorical data better. Graphs of frequencies and percentages of observations within over() groups can be obtained using statistics (count) and (percent). For example,
          graph bar (percent), over(grpvar)
          creates bars measuring the percentage of observations in each level of grpvar.
          graph bar, over(grpvar)
          is an abbreviated syntax that does the same.

          -------- update 07nov2014 -----------------------------------------------------

          3. graph bar and graph dot with option percent now report percentages rather than proportions.

          Title

          [G-2] graph bar -- Bar charts


          Syntax

          graph bar yvars [if] [in] [weight] [, options]

          graph hbar yvars [if] [in] [weight] [, options]


          where yvars is
          (asis) varlist

          or is
          (percent) [varlist] | (count) [varlist]
          I have suggested three solutions. Here's another. I see 16 totals and a multicolour legend that takes up about 50% of the graph space. Although it's a one off, I typed in the totals directly as a small dataset.

          Code:
          clear
          mat total = (715,870,832,630,546,580,426,504,485,491,870,687,290,787,825,38)
          set obs 16
          gen total = total[1, _n]
          gen question = _n
          graph hbar (asis) total, blabel(total) ///
          over(question) ysc(r(0, 900)) l1title(Question) ytitle(Totals)
          Click image for larger version

Name:	hbar.png
Views:	1
Size:	13.9 KB
ID:	1101284





          There will be simple ways of getting these totals, and whatever percents you want, directly from your data, but dividing by 1110 is easy.
          Last edited by Nick Cox; 19 Mar 2015, 13:41.

          Comment


          • #6
            Thanks again, Nick, for the various solutions. Much appreciated. I'm incredibly new to statistics and to Stata, so I apologize about the mundane nature of this question. I'll have to spend a couple hours trying to figure this out.

            Comment

            Working...
            X