Quadratic fit in Stata | Johan Osterberg - Product Engineer

Quadratic fit in Stata

May 23, 2019

In the last post we looked at linear fit in order to visualize relationships between two variables. For instance we can explore the relationship between wage and age in the nlsw88 dataset.

sysuse nlsw88, clear twoway (scatter wage age) (lfit wage age)

Scatter plot with linear fit overlay

There actually seems to be a negative relationship between those two variables. Maybe this can be seen clearer if we apply the quadratic fit instead:

twoway (scatter wage age) (qfit wage age)

Scatter plot with quadratic fit overlay

As shown in this example the quadratic fit makes a slightly better job of visualizing the negative relationship between the two variables, meaning that among surveytakers in the sample wage actually goes down with age.


Profile picture

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin

2024 © Johan Osterberg