use errorBar.dta, clear br , nolab gen halfsd=sd/2 gen low=mean-halfsd gen up=mean+halfsd sort race smoke gen id=0.5*_n replace id=id+1 if race==2 replace id=id+2 if race==3 two (bar mean id if smoke==0, barwidth(0.5) lcolor(blue)) (rcap low up id if smoke==0, lc(blue)) /// (bar mean id if smoke==1, barwidth(0.5) lcolor(red)) (rcap low up id if smoke==1, lc(red)) /// , name(p2, replace) /// yscale(r(0 4000)) ylab(0(1000)4000) /// legend(lab(1 "Birth weight from none-smokers mother") lab(2 "SD") lab(3 "Birth weight from smokers mothers") lab(4 "SD")) /// xlab(0.75 "White" 2.75 "Black" 4.75 "other") xtitle("") title("Barplot with error bars")