Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index