Statalist


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

AW: st: Re: Quadratic regression


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: Re: Quadratic regression
Date   Tue, 17 Feb 2009 16:53:28 +0100

<> 

-regress- holds an advantage of btw 0.1 and 0.13 seconds. But lacks the
advantages enumerated in
http://www.stata-journal.com/article.html?article=st0141

*************
sysuse auto, clear
cap timer clear

timer on 1
gen weight2 = weight^2
regress mpg weight weight2
predict pmpg1
timer off 1


timer on 2
nl (mpg = {a} + {b1}*weight + {b2}*weight^2), variables(weight)
predict pmpg2
timer off 2

timer list
*************

Anyway, it was just a suggestion which hopefully helps Shell sometime down
the road. It is unlikely that all he will ever want from Stata is predicted
values. At some point, marginal effects will become part of his agenda...

HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Friedrich
Huebler
Gesendet: Dienstag, 17. Februar 2009 16:38
An: [email protected]
Betreff: Re: st: Re: Quadratic regression

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

Friedrich


. 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...
>
> HTH
> Martin
> _______________________
> ----- Original Message ----- From: "Shell makka" <[email protected]>
> To: <[email protected]>
> Sent: Tuesday, February 17, 2009 4:18 AM
> Subject: st: Quadratic regression
>
>
>> Dear statalist
>>
>>
>> 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?
>>
>>
>> Many thanks,
>> Shell
*
*   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/


*
*   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