Announcement

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

  • Bar graph with mean and CI

    Please if you can provide me with the code/ steps to create as attached image


    Thank you




    Attached Files

  • #2
    Please back up and read the FAQ Advice, especially https://www.statalist.org/forums/help#stata

    Specifically:

    1. Please do not post MS Office attachments, as explained.

    2. Please tell us about your data with an example and variable names.

    We can tell you about technique. It seems that you have one outcome variable and three categorical variables, with differing numbers of categories.

    Here is an example with similar flavour.

    For such problems I write a script and only rarely get things right first time. So, I tend to use replace suboptions knowing that I will usually revise a graph.

    In my code cisets is from SSC and must be downloaded before you can use it. See https://www.statalist.org/forums/for...-interval-sets for more detail.

    0(0.5)2.5 is customised to what works moderately well, as the defaults don't here, in my view.

    What you have asked for is often called a dynamite plot, detonator plot or plunger plot. Use dynamite plot as a search term here on Statalist and more generally to discover severe critiques of this design. There are two especially common criticisms of such graphs. A comparison with zero is often not the main issue and at best a distraction. They don't show enough about the underlying data. These criticisms don't apply, I think, quite so much to the example in your attachment as they often do. But then again we have no idea about how different your data may be.

    I add a different kind of plot which I would be more likely to use myself.

    Code:
    webuse nlswork , clear
    
    foreach x in race collgrad south {
        cisets mean ln_wage, over(`x') saving(`x', replace)
    }
    
    foreach x in race collgrad south {
        use `x', clear
        levelsof origgvar, local(levels)
        twoway bar point origgvar, base(0) barw(0.6) fcolor(none) xla(`levels', valuelabel) legend(off) ///
        || rcap ub lb origgvar, yla(0(0.5)2.5) ytitle(`=varlabel') name(`x', replace)
        
        twoway scatter point origgvar, ms(D) msize(medium) xla(`levels', valuelabel) legend(off) ///
        || rbar ub lb origgvar, fcolor(none) ytitle(`=varlabel') name(`x'2, replace)
    }
    
    graph combine race collgrad south, row(1) name(G1, replace)
    
    graph combine race2 collgrad2 south2, row(1) ycommon name(G2, replace)
    There are always other ways to do it and further refinements you can make.
    Click image for larger version

Name:	ci1.png
Views:	1
Size:	46.5 KB
ID:	1770565

    Click image for larger version

Name:	ci2.png
Views:	1
Size:	40.1 KB
ID:	1770566

    Comment

    Working...
    X