Statalist


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

Re: st: RE: Legend with twoway rarea and a patterned border


From   Davide Cantoni <[email protected]>
To   [email protected]
Subject   Re: st: RE: Legend with twoway rarea and a patterned border
Date   Sun, 8 Nov 2009 09:07:04 -0500

Dear Martin,

> Normally playing around with the Graph Editor solves this stuff, but I could not find the magic bullet in this case... Still, why not just go for three -line-s then?

Thanks for your answer. I'm glad it seems there's nothing obvious I
overlooked. The reason why I do not use three lines is that actually
in my real graph I have two -rarea-s partly overlapping, and I want
the legend to reflect this accordingly:

*** begin example

sysuse auto, clear
drop if headroom>=5

gen headr=.
gen beta=.
gen se=.
gen lb=.
gen ub=.

levelsof headroom, local(levelsofheadr)

local i=0

foreach X of local levelsofheadr {
       local i `=`i'+1'
       replace headr=`X' in `i'
       qui reg mpg weight if headroom==`X'
       replace beta=_b[weight] in `i'
       replace se=_se[weight] in `i'
}

replace lb = beta-invnormal(0.975)*se
replace ub = beta+invnormal(0.975)*se

gen beta2=.
gen se2=.
gen lb2=.
gen ub2=.

foreach X of local levelsofheadr {
       qui reg mpg price if headroom==`X'
       replace beta2=_b[price] if headr==`X'
       replace se2=_se[price] if headr==`X'
}

replace lb2 = beta2-invnormal(0.975)*se2
replace ub2 = beta2+invnormal(0.975)*se2

twoway (rarea ub lb headr) (line beta headr) ///
	(rarea ub2 lb2 headr, lpattern(longdash) fcolor(none)) ///
	(line beta2 headr), ///
	legend(order(2 1 4 3) label(1 "Point est./95% c.i.: mpg on weight") ///
	label (2 "") label(3 "Point est./95% c.i.: mpg on price") label (4 "")) ///
	scheme(s1mono) xtitle(Headroom) ytitle(Coefficient estimate)

*** end example

And such a legend, I think, would be hard to achieve with -twoway
line-. Not to speak of the vertical lines that join the upper and
lower bound of the ci...

Thanks for your thoughts on this,

Davide
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index