Bookmark and Share

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


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

Re: st: twoway scatter plot -- how to show the regression equation in the legend


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: twoway scatter plot -- how to show the regression equation in the legend
Date   Tue, 17 Sep 2013 10:30:12 +0200

On Tue, Sep 17, 2013 at 9:56 AM, Alice Guerra wrote:
> I was wondering if it is possible to compute and show in the legend
> the regression line in a twoway scatter plot with lfit.

*------------------ begin example ------------------
sysuse auto
reg price mpg
local eq "`e(depvar)' ="
local eq "`eq' `: display %7.0g _b[_cons]'"
local eq "`eq' `=cond(_b[mpg] > 0, "+", "-")'"
local eq "`eq' `: display %5.0g abs(_b[mpg])' mpg"

twoway lfit price mpg || ///
       scatter price mpg, ///
       legend(order(1 2 - "`eq'"))
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index