Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: colouring options of serrbar


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: colouring options of serrbar
Date   Thu, 29 Sep 2011 12:58:43 +0100

For completeness note that a || is missing in the last example. 

Nick 
n.j.cox@durham.ac.uk 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 28 September 2011 21:27
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: colouring options of serrbar

-serrbar- is really only a token command for plotting error bars. (I
am rather generously credited in at least some versions of the manual
with some responsibility for it only because I suggested some
extensions a long time ago, but it was born an official command and
remains one.)

It's better to back-track to the premise that you have

mvar
svar
xvar

For simplicity, suppose that you want your bars to go from mvar - 1 *
svar to mvar + 1 * svar. In your real problem you can generalise that
multiplier of 1 to what you want (even a variable).

Then first calculate

gen lvar = mvar - svar
gen uvar = mvar + svar

Now you can go

twoway scatter mvar xvar || rcap lvar uvar xvar

Now you can extend this however you want

twoway scatter mvar xvar if group == 1, ms(pink) || rcap lvar uvar
xvar if group == 1, lc(pink)
            scatter mvar xvar if group == 2, ms(blue) || rcap lvar
uvar xvar if group == 2, lc(blue)

and so on. In practice, put this code in the do-file editor, use lots
of lines and /// to connect lines.

-search statsby- for another useful approach and an article on that.

Nick

On Wed, Sep 28, 2011 at 8:53 PM, Truus F. Hausman
<truus.hausman@googlemail.com> wrote:

> I am struggling with the colouring options of serrbar. I would like to
> colour groups of markers and change the style of error bars.
> Specifically, I have got three different estimates from 20 countries
> (e.g. from three different years or three different estimators). The
> countries form the x-axis, at each unit of the x-axis there are three
> estimates. Now, I would like to colour those estimates that stem from
> the same group (i.e. the same estimator or year). So far I am unable
> to find a solution. I tried two different approaches:
>
> a) conditions in mvopts
> serrbar mvar svar xvar, mvopts(mcolor(black if group==1, blue if group==2
>
> b) addplot()
> serrbar mvar svar xvar if group==1, mvopts(mcolor(black))
> addplot(serrbar mvar svar xvar if group==2, mvopts(mcolor(blue)))
>
> Both do not work. The first does not change the colour of the markers,
> the second is not allowed ("serrbar is not a twoway plot type"
> r(198)).
>
> Has anyone an idea how I can change the colour of the markers and
> maybe also the style of the error bars? Or will I have to use a
> different type of graph?
>

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index