Announcement

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

  • Probably silly question on bar charts

    Dear Statalists

    I assume, I have a quite stupid question, but really I couldn't figure out how to do the following

    My data looks like this:
    group var1 var2 var3 var5
    0 4 4 3 5
    0 4 2 2 5
    0 2 3 5 2
    1 1 3 2 2
    1 1 3 3 3
    1 2 3 3 3
    2 2 3 2 4
    2 2 4 1 2
    2 5 7 2 1
    Now what I want is one bar chart that looks like this (done as a pivot chart in excel..)
    Click image for larger version

Name:	example.JPG
Views:	1
Size:	39.2 KB
ID:	1422518


    i.e. I want one chart that displays the means of var1, var2, ... and group them for each var, to be able to compare the averages between the groups.
    Additionally, should have error bars.

    If I use the gui of stata, I can only do over(grp) and then I get bars of the variable means per group... e.g. "graph bar (mean) var1 var2, over(grp)"

    Hope, somebody can help

  • #2
    This isn't silly or stupid at all. In essence you need to restructure the data to get what you want, or so I believe.

    But at least one command will do that for you, temporarily.

    So I'd suggest statplot from SSC by Eric Booth and friend. You need to install first.

    Your data example is very helpful -- and using dataex as requested in the FAQ would be even more helpful.

    You can search the forum for further mentions of statplot, or just rely on its help for more detail.


    Code:
    clear
    input group    var1    var2    var3    var5
    0    4    4    3    5
    0    4    2    2    5
    0    2    3    5    2
    1    1    3    2    2
    1    1    3    3    3
    1    2    3    3    3
    2    2    3    2    4
    2    2    4    1    2
    2    5    7    2    1
    end
    
    * "ssc inst statplot"  is needed before you can do this
    set scheme s1color
    statplot var*, over(group) recast(bar)
    Click image for larger version

Name:	statplot2.png
Views:	1
Size:	18.4 KB
ID:	1422528

    Last edited by Nick Cox; 15 Dec 2017, 06:02.

    Comment


    • #3
      Dear Nick

      You're the best.

      Comment


      • #4
        Andre Becker - In addition to Nick's great response, I see that your data example has some longer labels that might need wrapping. I wrote some examples for wrapping longer labels and how to fine-tune some other options in -statplot- on my (now mostly abandoned) blog at the links below (particularly the second one) these might be useful.

        http://researchnotes.eric-a-booth.co...-examples.html
        http://researchnotes.eric-a-booth.co...es-part-2.html
        Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

        Comment

        Working...
        X