Dear Stata Community,
I am having some difficulties in placing mean numbers as labels above each bar. I use Stata 14.2. I want to produce a bar graph with CI. So far so good. However, after having struggled for more than an hour and half on trying to use available commands to generate labels for mean bar above each bar, I am helpless and desperate. I have used the following commands:

ci means swd_post if amount==1
ci means swd_post if amount==2
ci means swd_post if amount==3
ci means swd_post if amount==4

gen lb =4.929435 if amount==1
gen ub=5.532104 if amount==1

replace lb=5.358832 if amount==2
replace ub=5.700756 if amount==2

replace lb=5.487815 if amount==3
replace ub=5.825519 if amount==3

replace lb=5.262667 if amount==4
replace ub=5.85683 if amount==4

egen mean_swd_0=mean(swd_post) if amount==1
egen mean_swd_1=mean(swd_post) if amount==2
egen mean_swd_2=mean(swd_post) if amount==3
egen mean_swd_3=mean(swd_post) if amount==4

gen mean_swd=mean_swd_0 if mean_swd_0!=.
replace mean_swd=mean_swd_1 if mean_swd_1!=.
replace mean_swd=mean_swd_2 if mean_swd_2!=.
replace mean_swd=mean_swd_3 if mean_swd_3!=.

twoway (bar mean_swd amount, barwidth(0.3)) (rcap lb ub amount) ///
, xlabel(1 "Three losses" 2 "Two losses" 3"One loss" 4"No loss") xscale(range(1 4.20)) legend(off) ytitle("Satisfaction With Democracy") scheme(s1mono)

I came across the following post in Statalist: https://www.statalist.org/forums/for...way-bar-graphs
But I could not replicate it for some reason, perhaps I am too dumb, but I would be super grateful if you could walk me through it.

Thanks a million for your contribution.

Best,

L

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(swd_post amount)
9 4
7 4
3 4
6 4
8 4
4 4
4 4
. 4
5 4
3 4
end