webuse lbw
frame copy default lian_lbw
frame lian_lbw: statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(smoke) clear: ci mean bwt
frame lian_lbw:local text1 = mean[1]
frame lian_lbw:local text2 = mean[2]
frame lian_lbw: twoway bar mean smoke, text(3200 0 " Mean:`text1' " ) text(3200 1 " Mean:`text2' " ) ylabel(0(1000)3000) xscale(r (0 1)) xlabel(0 "Nonsmoker" 1 "Smoker" ) barw(0.5) || rcap ub lb smoke, legend(off)
参考资料:https://www.stata-journal.com/sjpdf.html?articlenum=gr0045
https://www.statalist.org/forums/forum/general-stata-discussion/general/1549742