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: equation of a lfit in a scatter plot


From   "Radwin, David" <[email protected]>
To   <[email protected]>
Subject   RE: st: equation of a lfit in a scatter plot
Date   Fri, 9 Aug 2013 12:20:23 -0400

Maarten's solution is fine and gives you a lot of flexibility, but if
you want something simpler, try -aaplot- by Nick Cox, available from
SSC.

. ssc install aaplot
. aaplot wage_dip urate

David

--
David Radwin
Senior Research Associate
Education Studies Division
RTI International
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-665-8274

www.rti.org


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Maarten Buis
> Sent: Friday, August 09, 2013 3:12 AM
> To: [email protected]
> Subject: Re: st: equation of a lfit in a scatter plot
> 
> On Fri, Aug 9, 2013 at 11:34 AM, Chiara Mussida wrote:
> > is there an option to show the equation of a linear fit on a scatter
> > plot. In detail, my command is as follows:
> >
> > twoway (scatter wage_dip urate, mlabel(regio)) (lfit wage_dip urate)
> >
> > It shows the scatter plot between my variable and their linear fit.
> > How would I get the corresponding equation on my graph?
> 
> *------------------ begin example ------------------
> sysuse auto, clear
> reg price mpg
> 
> // find the dependt variable
> local eq `"`e(depvar)' ="'
> 
> // choose a nice display format for the constant
> local eq "`eq' `: di  %7.2f _b[_cons]'"
> 
> // should we add or subtract
> local eq `"`eq' `=cond(_b[mpg]>0, "+", "-")'"'
> 
> // we already chose the plus or minus sign
> // so we need to strip a minus sign when it is there
> local eq `"`eq' `:di %6.2f abs(_b[mpg])' mpg"'
> 
> // add the error term
> local eq `"`eq' + {&epsilon}"'
> 
> // add the equation as a note to the graph
> twoway scatter price mpg || ///
>        lfit price mpg,      ///
> 	   note("`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