how to show SE along with dots in a dot plot in Stata

63 Views Asked by At

I want to make a dot plot with showing mean and SE in the plot in Srara. But, I am not able to make the SEs in graph. Anyone has any example code to do that? I have a continuous value in the y-axis and 6 variables type in my x-axis.

I have only used the code below:

dotplot val1 val2 val3 val4 val5 val6, mean

A reproducible data can be see as following:

clear
set obs 100
set seed 12345

forval j = 1/6 {
    gen val`j' = rnormal(`j' * 10, `j' * 2)
}

rename val1 baseline1
rename val2 vrs
rename val3 sgbd
rename val4 baseline2
rename val5 fdst
rename val6 sgvf

but I expect to get the SE in graph and also mean.

1

There are 1 best solutions below

7
Nick Cox On

Here is some technique -- in the absence of a reproducible example from you.

clear 
set obs 100
set seed 314159 

forval j = 1/6 {
    gen val`j' = rnormal(`j', `j')
}

* you start here 
preserve 

forval j = 1/6 { 
    local call `call' (mean) mean`j'=val`j' (semean) semean`j'=val`j'
}

collapse `call'

gen id = 1 

reshape long mean semean, i(id) j(which)

gen upper = mean + se 
gen lower = mean - se 

twoway scatter mean which || rcap upper lower which, xla(1/6) ytitle(val) xtitle(which)

restore 

EDIT

Making use of the reproducible example, here is some sample code.

clear
set obs 100
set seed 12345

forval j = 1/6 {
    gen val`j' = rnormal(`j' * 10, `j' * 2)
}

rename (val1-val6) (baseline1 vrs sgbd baseline2 fdst sgvf) 

* ssc install stripplot
stripplot baseline1-sgvf, bar(level(68)) stack ///
width(2) vertical msize(vsmall) ms(Sh)