Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Re: Quadratic regression


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Re: Quadratic regression
Date   Tue, 17 Feb 2009 15:46:02 -0000

That's what you'd guess. -regress- is compiled code, beyond a minor
wrapper, and it knows the direct way to a  solution. Neither is quite
true of -nl-. 

The advantage of -nl- here is at most convenience in making the call. 

Nick 
[email protected] 

Friedrich Huebler

-nl- is slower than -regress- and produces identical results.

. sysuse auto
. gen weight2 = weight^2
. regress mpg weight weight2

      Source |       SS       df       MS              Number of obs =
74
-------------+------------------------------           F(  2,    71) =
72.80
       Model |  1642.52197     2  821.260986           Prob > F      =
0.0000
    Residual |  800.937487    71  11.2808097           R-squared     =
0.6722
-------------+------------------------------           Adj R-squared =
0.6630
       Total |  2443.45946    73  33.4720474           Root MSE      =
3.3587

------------------------------------------------------------------------
------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf.
Interval]
-------------+----------------------------------------------------------
------
      weight |  -.0141581   .0038835    -3.65   0.001    -.0219016
-.0064145
     weight2 |   1.32e-06   6.26e-07     2.12   0.038     7.67e-08
2.57e-06
       _cons |   51.18308   5.767884     8.87   0.000     39.68225
62.68392
------------------------------------------------------------------------
------

. predict pmpg1
. nl (mpg = {a} + {b1}*weight + {b2}*weight^2), variables(weight)
(obs = 74)

Iteration 0:  residual SS =  800.9375
Iteration 1:  residual SS =  800.9375

      Source |       SS       df       MS
-------------+------------------------------         Number of obs =
74
       Model |  1642.52197     2  821.260986         R-squared     =
0.6722
    Residual |  800.937487    71  11.2808097         Adj R-squared =
0.6630
-------------+------------------------------         Root MSE      =
3.358692
       Total |  2443.45946    73  33.4720474         Res. dev.     =
386.25

------------------------------------------------------------------------
------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf.
Interval]
-------------+----------------------------------------------------------
------
          /a |   51.18308   5.767884     8.87   0.000     39.68225
62.68392
         /b1 |  -.0141581   .0038835    -3.65   0.001    -.0219016
-.0064145
         /b2 |   1.32e-06   6.26e-07     2.12   0.038     7.67e-08
2.57e-06
------------------------------------------------------------------------
------
  Parameter a taken as constant term in model & ANOVA table

. predict pmpg2
. compare pmpg1 pmpg2

                                        ---------- difference ----------
                            count       minimum      average     maximum
------------------------------------------------------------------------
pmpg1=pmpg2                    74
                       ----------
jointly defined                74             0            0           0
                       ----------
total                          74


On Tue, Feb 17, 2009 at 2:15 AM, Martin Weiss <[email protected]>
wrote:
> <>
>
> Three responses advised you to create a new variable and then use
-regress-.
> Note, though, that a better option would be to use -nl-
>
> nl (y = {a} + {b1}*x + {b2}*x^2), variables(x)
>
> as in http://www.stata-journal.com/article.html?article=st0141
>
> which would allow Stata to know that x and x squared "move in tandem"
and
> calculate the correct marginal effects...
>
_______________________
> ----- Original Message ----- From: "Shell makka"
<[email protected]>
>>
>> It would be greatly appreciated if you can answer my question.
>> I would like to fit a quadratic regression Model (Y=a+bX+cX^2) on my
>> data and do predictions , would you please let me know what will be
>> the code for that in stata?

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index