 Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: Plot means with SD

 From "Trelle Sven" To Subject RE: st: Plot means with SD Date Wed, 4 Apr 2012 09:34:37 +0200

```I usually do this the complicated way but it allows to extend what is
plotted e.g. you could show the means and SDs in the plot if you want to
(same principle as was used for displaying the variable var in the code
below). However, you have to fiddle with the positioning of the
different "objects" on the y-/x-scale.
I am sure the more advanced Stata users have much simpler solutions ...:
Sven

****
* Example starts
sysuse auto, clear

gen index = _n
gen var = ""
gen mean = .
gen sd = .
gen lsd = .
gen usd = .

local n=1
foreach var of varlist price weight {

sum `var'
replace var = "`var'" in `n'
replace mean = r(mean) in `n'
replace sd = r(sd) in `n'
local n = `n'+1
}

replace lsd = mean - sd
replace usd = mean + sd
replace index = . if var==""

qui sum usd
local u = r(max) // could be used to determine range of axis
qui sum lsd
local l = r(min) // could be used to determine range of axis
sum index
local i = r(max) + 1
gen labpos = `l'-10

scatter index mean, msymbol(O) yscale(r(1 `i') off) ///
|| scatter index labpos, msymbol(i) mlabel(var) ///
|| rspike lsd usd index, hor legend(off)

* Example ends

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Patricia
Biedermann
Sent: Mittwoch, 4. April 2012 08:11
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Plot means with SD

Thank you.
But I don't wanna have a dotplot. More like a box plot, but just with
mean instead of median and SD instead of quintiles. Or a bar- graph.
Is this somehow possible?

On 03.04.2012, at 19:10, Nick Cox wrote:

> Your options include -dotplot- (official), -stripplot- (SSC).
>
> Examples:
>
> sysuse bpwide, clear
> dotplot bp*, mean bar
> stripplot bp*,  bar vertical stack height(0.3) width(2)
>
> -stripplot- with these options plots a 95% c.i. based on the mean.
>
> Nick
>
> On Tue, Apr 3, 2012 at 6:02 PM, Patricia Biedermann
> <pati.biedermann@gmail.com> wrote:
>
>> I have two variables
>> 1) medstable (days after a patient achieves medical stability, in
days)
>> 2) durofstay    (duration of hospital stay; in days)
>>
>> now I wanna plot these two variables with mean and SD, so that I can
see the differences of both.
>> How can I do this?
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```