Statalist


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

st: Alternative uses of -nl


From   "Paulo Regis" <[email protected]>
To   [email protected]
Subject   st: Alternative uses of -nl
Date   Tue, 18 Nov 2008 23:54:34 +0800

Dear all,

Departing from the following data

      v1               v2                v3                   z
0.0375815    0.0480932     -1                 -0.3227311
-0.0192965   0.0261546    -0.1428161     -0.0480932
-0.097088     0.0096482     0                   0.0187907

I am using NLS to estimate the following function

z = v1*rho+v2*(rho^2)+v3*(sigma^2)

where you have two parameters (rho and sigma^2). The problem is I
tried two different ways to estimate the parameters that lead me to
different values but this shouldnt be the case. Originally, I was
using the following programme:

               program define nlequ
               version 9
               if "`1'"== "?" {
               global S_1 " rho sigma2 "
               global rho=1
               global sigma2=1
               exit
               }
               replace `1'=v1*$rho +v2*$rho^2 +v3*$sigma2
               end

and typing in the command line something like:

              nl equ z, init(rho=0.7, sigma2=1)

The regression output is

Iteration 0:   residual SS =   .409458	
Iteration 1:   residual SS =  .0018054	
Iteration 2:   residual SS =  .0000357	
Iteration 3:   residual SS =  .0000355	
Iteration 4:   residual SS =  .0000355	

      Source |       SS       df       MS            Number of obs =         3	
-------------+------------------------------         F(  2,     1) =   1503.70	
       Model |  .106785885     2  .053392943         Prob > F      =    0.0182	
    Residual |  .000035508     1  .000035508         R-squared     =    0.9997	
-------------+------------------------------         Adj R-squared =    0.9990	
       Total |  .106821393     3  .035607131         Root MSE      =  .0059588	
                                                     Res. dev.     = -25.51948	
(equ)	
------------------------------------------------------------------------------	
          z1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]	
-------------+----------------------------------------------------------------	
         rho |  -.1857942   .0626628    -2.96   0.207    -.9820006    .6104122	
      sigma2 |   .3149169   .0067697    46.52   0.014     .2288992    .4009345	
------------------------------------------------------------------------------	


Likewise, we should be able to get to the same result if we type in
the command line

              nl (z1 = v1*{rho=1}+v2*{rho}^2+v3*{sigma2=1})  ,
init(rho -.1857942 sigma2 .3149169)

the regression output is

Iteration 0:  residual SS =  .0026024
Iteration 1:  residual SS =  .0000491
Iteration 2:  residual SS =  .0000487
Iteration 3:  residual SS =  .0000487
Iteration 4:  residual SS =  .0000487

      Source |       SS       df       MS
-------------+------------------------------         Number of obs =         3
       Model |  .106772687     2  .053386344         R-squared     =    0.9995
    Residual |  .000048706     1  .000048706         Adj R-squared =    0.9986
-------------+------------------------------         Root MSE      =   .006979
       Total |  .106821393     3  .035607131         Res. dev.     = -24.57133

------------------------------------------------------------------------------
           z |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        /rho |   -.169541   .0664627    -2.55   0.238     -1.01403    .6749475
     /sigma2 |   .3186849   .0069996    45.53   0.014      .229746    .4076239
------------------------------------------------------------------------------


Notice that I even introduced the previous estimates as initial values
but even then Stata finds an alternative minimum. Further, the
residual SS is higher.

I would appreciate any comment that help me to understand why Stata
provides different values depending on what strategy I use for NLS.Is
there any mistake in my command lines?


Cheers

Paulo

SP: I am creating and ado file and I have some additional questions.

1- The reason i ask about nl is because I had some problems
introducing a nl programme in an ado file. is it illegal to use an nl
programme?  The structure of my ado file is as follows:

         program define  estim1
         ...
         nl equ z
         ...
         end
         program define nl equ
         ...
         end

2- Is illegal to name a programme if the name start with numbers?
(i.e.: a programme named 2sls)
*
*   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