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: graph: how to draw 45 degree reference line
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
RE: st: graph: how to draw 45 degree reference line
Date
Mon, 15 Mar 2010 12:06:49 -0000
Friedrich's point about sorting is correct but was precisely the reason I spelled out use of the -sort- option too in my original post. That got dropped some way along the thread.
I don't know about Stefan's proposal. One reaction is that you don't need Stata to do a regression to get a line y = x. On the other hand, Stata is very fast at regression, and it wouldn't surprise me vastly if this were faster. After all, my guess is that -twoway function- doesn't necessarily include any machinery to recognise simple functions and draw them directly. And -line- through the data is looking at all the data.
However, there is yet another way to do it:
. sysuse auto
. scatter weight price || scatteri 0 0 15000 15000, recast(line)
Nick
[email protected]
Stefan Gawrich [edited]
I think - twoway lfit - is best in this case:
// Line from min to max:
. twoway scatter weight price || lfit price price, aspect(1) range(. .) n(2)
// Line from 0 to max:
. twoway scatter weight price || lfit price price, aspect(1) range(0 .) n(2)
The "range" option of - lfit - is more versatile.
Friedrich's n(2)" trick works with - lfit -
Friedrich Huebler
-line price price- is easy but depending on the resolution of the
display the line will not appear entirely straight. The appearance
also depends on how the data are sorted. -function- with the option
n(2) yields a cleaner graph. The setting of the range can be
automated.
. sysuse auto, clear
. sum price, meanonly
. local xmin = r(min)
. local xmax = r(max)
. twoway (scatter weight price) (function y=x, range(`xmin' `xmax')
n(2)), aspect(1)
*
* 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/