worldbank / ietoolkit

Stata commands designed for Impact Evaluations in particular, but also data work in general
https://worldbank.github.io/ietoolkit/
MIT License
216 stars 77 forks source link

iegraph : color() has no effect in baroption() option #346

Closed kbjarkefur closed 9 months ago

kbjarkefur commented 1 year ago

Issue submitted by email from @oscarmdiazb :

For a while, I've been trying to change the colours of the bars when using the iegraph command, but without success. Would you mind providing an example? I've tried the variations of the following code:

sysuse auto, clear 
reg price foreign 
iegraph foreign,  varlabels legend(pos(6) rows(1)) baroptions(color(green))     barlabel barlabelformat( %9.2f)
kbjarkefur commented 1 year ago

The error reproduces as submitted by user.

The fix was quite straightforward and is implemented in f4ac0a1e27ed6b5aba02904f0273e93974b8b9ec.

kbjarkefur commented 1 year ago

OP followed up and suggested that baroptions() should be possible to set colors for individual bars. This is not possible using baroptions() as the bar options specified in that option is added to all bars.

Instead, in 0bfb72cb9ba7b7f0acc05a4383bd6d6ea6211440 a new option barcolors() was added. This option allows the user to manually specify colors, as in barcolors(`" red gs14 "215 25 28" gold cranberry "'). Any color listed in https://www.stata.com/manuals13/g-4colorstyle.pdf may be used.

Test this option like this:

sysuse auto, clear
replace foreign = floor(runiform()*5)

gen f1 = (foreign == 1)
gen f2 = (foreign == 2)
gen f3 = (foreign == 3)
gen f4 = (foreign == 4)
gen ctrl = (foreign == 5)

reg price f1 f2 f3 f4 weight
iegraph f1 f2 f3 f4 , legend(pos(6) rows(1)) barcolors(`" red gs14 "215 25 28" gold cranberry "') barlabel barlabelformat( %9.2f) mlabcolor(blue) 

If barcolors() is used together with baroptions(color(green)) then the later takes precedence, as baroption() has the highest precedence to allow the user to overwrite any options used.