Statalist


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

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


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: RE: Legend with twoway rarea and a patterned border
Date   Sun, 8 Nov 2009 15:44:09 +0100

<> 

Point taken, but I could see a more useful representation of your data with a plot that reflects the discrete nature of "headroom" more adequately, and makes the -legend- easily legible. BTW, I think -statsby- is a useful command to replace your loops...


*************
clear*
vers 11
sysuse auto
drop if headroom>=5

statsby beta=_b[weight] se=_se[weight], /*
 */ by(headroom) clear: /*
 */ reg mpg weight
 
tempfile mytemp
save `mytemp', replace

sysuse auto, clear
drop if headroom>=5

statsby beta2=_b[price] se2=_se[price], /*
 */ by(headroom) clear: /*
 */ reg mpg price
 
merge 1:1 headroom using `mytemp', /* 
*/ norep nogen

gen lb = beta-invnormal(0.975)*se
gen ub = beta+invnormal(0.975)*se
lab var beta "Point Estimate for weight"

gen lb2 = beta2-invnormal(0.975)*se2
gen ub2 = beta2+invnormal(0.975)*se2
lab var beta2 "Point Estimate for price"

tw (rcap lb ub headroom) (rcap ub2 lb2 headroom, lpattern(dash))  /* 
*/ (line beta headroom) (line beta2 headroom,  /* 
*/ lpattern(longdash)), scheme(s1mono) /* 
*/  ytitle(Coefficient Estimate) xtitle(Headroom) /* 
*/  legend(on order(1 "" 3 "Point est./95% c.i.: mpg on weight"  /* 
*/  2 "" 4 "Point est./95% c.i.: mpg on price"))
*************



Just in case you are a user of 10.1, change the -version- statement to "10.1", and change the -merge- line to:


**************
merge headroom using `mytemp', sort
**************


HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Davide Cantoni
Gesendet: Sonntag, 8. November 2009 15:07
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: RE: Legend with twoway rarea and a patterned border

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/


*
*   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   |   What's new   |   Site index