Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the Stata graph twoway command, I have created a scatterplot with a quadratic best fit line, using the qfit command. How can I get the equation of the best fit line?


graph tw (scatter y x) (qfit y x)
share|improve this question
You should include your specific code to make it easier for people to give an answer. – David Robinson Jan 8 '12 at 20:00
up vote 1 down vote accepted

Your graph, using auto as an example.

sysuse auto, clear
graph tw (scatter  price mpg) (qfit  price mpg), name(graph1)

regress y on x and x^2 and get predicted values (seehelp fvvarlist if you don't know about this notation)

regress price mpg c.mpg#c.mpg  

The output from regress gives you the "equation" of the fitted line (y=b1*x + b2*x*x + b3) and the following graph is equivalent:

predict fitted
sort mpg
graph tw (scatter  price mpg) (line fitted mpg) , name(graph2)
share|improve this answer

qfit is a convenience command that simply calls regress, then obtains and plots the predicted values. So if you want the fit parameters, you can call regress yourself.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.