Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regress ≠ Twoway qfit !?

    Hi,

    I'am a bit puzzled as i got 2 different predictions from a simple quadratic regression (Y = aX +bX² + c), by 2 differents stata commands that i expected to be equivalent/exangeable.

    Here is a reproductible example :

    Code:
    sysuse auto, clear
    
    regress price mpg c.mpg#c.mpg /*** we fit a basic quadratic model with regress ****/
    predict fitted  /*** we get the predictions ****/
    sort mpg   /*** sort on mpg in order to use twoway line ***/
    
    graph tw (scatter  price mpg) /// /**** to get the scatter plot from crude values ****/
     (line fitted mpg) /// /*** the fitted values from regress ***/
    (qfit  price mpg) /*** the quadratic fitted values from qfit ***/
    As you can see, there is a small difference between the 2 curves (i got another set of data were the difference is not neglectable)
    I'am not sure were i'am wrong (Regress ≠ Twoway ?) or if i mess something ?
    Last edited by aurelien mulliez; 22 Feb 2022, 10:00.

  • #2
    This pivots entirely on line using straight-line segments to join data points. Change line to mspline and you should feel happier.

    Comment


    • #3
      Thank you,
      I didn't think this was a so obvious little thing
      Of course i feel happier ... but for a short while, as i still have a gap with my own data.
      I'am looking for an explanation before to bother you again (or not )

      Comment


      • #4
        All fixed, i got a mistake on the regress line (that were aX² + c, bX was missing)
        Sorry for the inconvenience and thanks again for the mspline plot tips that is better suited than line in quadratic situations.

        Comment

        Working...
        X