Announcement

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

  • Showing 95%-CI intervals in bar graph

    Hello everyone

    In my data I have a dichotomous variable (=value) for three different conditions (which are coded as 0,1,2). Currently, I get a nice picture with:

    graph bar, over(value) by(condition, cols(3)) blabel(bar, format(%4.2g)) ytitle(Distribution in percentage) yscale(range(0 100)) ylabel(#5) scheme(s1mono) xsize(5)

    However, I also want to show the 95%-CI in the bars. Some research suggest, that I would need to work with a twoway graph and use || rcap but I don't get it to work. I think the syntax with by(condition) is not supported in two-way graphs?

    Can somebody help me?

    Thanks
    Jonas

  • #2
    You can use "cibar" to get confidence intervals without changing your syntax too much. However, it doesn't support "by", but you can create different graphs and then combine them together with "graph combine" or "grc1leg"

    Comment


    • #3
      This question often arises here.

      There is no scope whatsoever for combining graph bar with twoway rcap. The problem doesn't lie in support for by() but just in the fact that graph bar and graph twoway are completely separate code so far as the user is concerned.

      I have been somewhat negative about community-contributed commands for this -- including my own ciplot from SSC -- ever since realising (by virtue of a single throw-away remark from Vince Wiggins of StataCorp) that designing your own in a flexible way is easy with official commands. For example, a community-contributed command not supporting by() -- in my experience the most frequent need! -- is then irrelevant.

      Here is an example. Note that bars are plotted for repair record 1 and 2. It's just that they are of zero height and you need suspension of disbelief to know that they are there.

      For more on this approach
      https://www.stata-journal.com/sjpdf....iclenum=gr0045 is available.

      Code:
      sysuse auto, clear 
      
      statsby, by(rep78) : ci proportions foreign 
      
      twoway bar mean rep78, barw(0.6) bfcolor(green*0.2) || rcap lb ub rep78, scheme(s1color) legend(off) yla(0 "0" 1 "1" 0.2(0.2)0.8, format(%02.1f) ang(h)) subtitle(Mean and  95% confidence intervals for proportion of foreign cars)


      Click image for larger version

Name:	bar_and_bar.png
Views:	1
Size:	19.6 KB
ID:	1549759


      That said, although this is close to what people often (seem to) want, it is a terrible design. Polemic but to me highly persuasive rants about this can be found with key terms detonator plot, dynamite plot, or plunger plot, either here on Statalist or indeed more widely. I think the main issues fall into two.

      1. Bars starting at zero privileges zero as a reference level, which may be of no substantive or scientific interest. In the example above it is, but often it isn't. Conversely, bars starting anywhere else is often tricky.

      2. More generally, this graph shows remarkably little information: the sample size and the precise pattern of variability are suppressed.

      Explaining alternatives would take me too far from the topic, but the crux of the problem lies in displaying more about the distribution together with summary statistics.

      Comment

      Working...
      X