With the second approach, the -predict- is
unnecessary for a graph. But note that the
polynomial must sometimes be tweaked with
-bands()-. (-regplot- is just a wrapper
for a call to -twoway mspline- and -twoway
scatter-.)
n j cox wrote:
Even with Maarten's example, things can be made
simpler. Starting as before,
sysuse auto, clear
gen weight2 = weight^2
reg price weight weight2
if you
predict quad
twoway mspline quad weight || scatter price weight
you get the data shown as well.
Alternatively, if you install the -modeldiag- package
from either SSC or the Stata website, then
predict quad
regplot
will give you the same graph. This is because -regplot-
defaults to a plot of the observed and predicted response
against the first predictor named.
Maarten Buis
sysuse auto, clear
gen weight2 = weight^2
reg price weight weight2
sum weight
twoway function y = _b[_cons]+_b[weight]*x+_b[weight2]*x^2, range(1760
4840)
Tinna
I am using an independent variable in its regular and squared forms in
an OLS and 2SLS regressions. Can I graph this polynomial relationship
as indicated by the regression in an easy way?
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/