Add Confidence Intervals to your Bar Graph

You can use a range plot with capped spikes to plot confidence intervals on top of a bar graph.

To generate this graph in Stata, use the following commands:

. sysuse auto, clear

. egen cutMpg=cut(mpg), group(5) icode

. levelsof cutMpg, local(levels)

. generate proportions = .

. generate upper_bound = .

. generate lower_bound = .

. generate labels = .

. local z = 1

. foreach i of local levels {
	ci proportions foreign if cutMpg == `i', wilson
	replace proportions = r(proportion) in `z'
	replace upper_bound = r(ub) in `z'
	replace lower_bound = r(lb) in `z'
	replace labels = `i' in `z'
	local ++z
}
. label define lbl 0 "very poor" 1 poor 2 OK 3 good 4 vgood

. label value labels lbl

  . twoway bar proportions labels || rcap upper_bound lower_bound labels, xlabel(, valuelabel angle(45)) xtitle("Fuel Consumption") ytitle(Proportions) legend(off)