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)