Announcement

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

  • Adding error bars to bar graph

    Hi all, can someone please assist me with how to add error bars to the bar graph attached. Thanks.
    Attached Files

  • #2
    There is no code here or example data but it is possible to guess that your command was something like


    Code:
    graph bar response_time, over(younger) over(blur) asyvars
    This graph is fine for showing means, but a dead end for also showing error bars. You need to switch to graph twoway.

    I will illustrate my recommendation using a different dataset.

    Code:
    webuse nlswork, clear
    
    keep if ind_code == 8 
    
    statsby, by(collgrad south) clear : ci means ln_wage 
    
    gen x1 = south - 0.1
    gen x2 = south + 0.1
    
    twoway rcap ub lb x1 if collgrad == 0, lcolor(orange) || ///
           rcap ub lb x2 if collgrad == 1, lcolor(blue)   || ///
         scatter mean x1 if collgrad == 0, ms(O) mc(orange)     || ///
         scatter mean x2 if collgrad == 1, ms(T) mc(blue)          ///
         ytitle(ln_wage) xla(0 "North" 1 "South")            ///
         legend(order(3 "not graduate" 4 "graduate")) aspect(1) xsc(r(-0.2 1.2))
    Click image for larger version

Name:	notdynamite.jpg
Views:	1
Size:	14.0 KB
ID:	1685886




    See e.g. https://biostat.app.vumc.org/wiki/pu...de/Poster3.pdf and https://simplystatistics.org/posts/2...lots-must-die/ as two of many sample arguments against the bar +/- error bar dynamite, detonator or plunger plots.

    See also https://www.stata-journal.com/articl...article=gr0045 (bearing in mind that the syntax of ci has changed slightly since that paper was published).

    Comment


    • #3
      Thanks so much Nick. I'm very grateful for your help

      Comment

      Working...
      X