2

I am trying to change the color of the bars in a twoway bar graph with an overlayed rcap.

Stata will not allow me to use the color(), bcolor(), or bar(1, color()) options.

This is my code:

twoway (bar meanVAR1 Treatment) (rcap loVAR1 hiVAR1 Treatment), yscale(off) ///
ytitle(Percent) xtitle(Exp whether treated) xlabel(minmax) legend(off) ///
name(experience, replace) graphregion(fcolor(white) ifcolor(white)) ///
plotregion(fcolor(white) ifcolor(white))

How can I change the color of the bars in my graph?

anna123
  • 21
  • 1
  • 2
  • Please read the [Stata tag wiki](https://stackoverflow.com/tags/stata/info) for advice on how to ask Stata-related questions on Stack Overflow. We expect you to provide us with example data using the `dataex` command so we can be able to run your code. –  May 15 '19 at 19:41
  • Although it may well seem confusing `graph bar` and `twoway bar` are different commands. Some options are shared but in particular options like `bar(1, ...)` apply only to `graph bar`. – Nick Cox May 16 '19 at 07:55
  • It is a different issue, but plots of mean as bar and some interval of uncertainty as error bar are widely deprecated as uninformative and even misleading. Terms detonator plot, dynamite plot and plunger plot find discussions, including several on Statalist. – Nick Cox May 16 '19 at 07:56

1 Answers1

2

If you only want to specify the colour for all bars, you simply need to place the color() option inside the twoway bar graph:

sysuse sp500, clear
by date: egen mean_open = mean(open)

twoway (bar mean_open date in 1/37, color(sand)) (rcap high low date in 1/37, color(ebblue))

enter image description here

If instead you want to define the colour of each bar then you need to overlay multiple twoway bar graphs and use the bcolor() option in order to achieve the desired output depending on your data:

twoway (bar mean_open date in 1/37 if date < `= daily("27/01/2001", "DMY")', bcolor(red)) ///
       (bar mean_open date in 1/37 if date > `= daily("27/01/2001", "DMY")', bcolor(orange)) ///
       (rcap high low date in 1/37, color(black))

enter image description here

  • Anna, if you found my answer helpful, please consider accepting it by clicking the check-mark. this is how you reward volunteers on Stack Overflow for their time and ensure that they will help you again in the future. –  Jun 08 '19 at 23:39