Announcement

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

  • Bar graph comparing full sample mean with means by group

    Hi everyone,

    I'm not quite sure how to phrase this request, but I want to create a bar graph that shows the mean of a full sample and compare it to the mean of groups within the sample in *one* graph. In the attached image, you see the far right bar represents the general population and the remaining graphs represent the major religious groups in the gen pop. I'd like to recreate something along these lines. Many thanks for the help.
    Attached Files

  • #2
    A toy example to get you started:

    Code:
    sysuse auto, clear
    
    *create total line:
    collapse (mean) price
    g rep78 = 99
    sa total, replace
    sysuse auto, clear
    collapse (mean) price, by(rep78)
    append using total
    
    lab def rep78 1 "test" 2 "test" 99 "Overall", modify
    
    lab val rep78 rep78
    list
    gr bar price, over(rep78) 
    
    *set specific bar colors
    
    graph bar (mean) price, over(rep78) ///
     ascategory asyvars showyvars ///
    bar(1, fcolor(gs1)) ///
    bar(2, fcolor(gs1)) ///
    bar(3, fcolor(gs1)) ///
    bar(4, fcolor(gs1)) ///
    bar(5, fcolor(gs1)) ///
    bar(6, fcolor(red)) ///
    bargap(20) blabel(bar)


    Aside: Is the general public bar really the same as the 'total respondents' base bar described in the note?
    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      Thanks a bunch, Eric! This is definitely enough to get me going where I want to end up.

      As for your question, I think you astutely noticed that clearly there are folks in America that do not fit neatly into the graph's categories. The analysis for that visualization omitted the "other" and "dk/ref" cats. Was that what you were getting at?

      Comment

      Working...
      X