Brian,
Thanks for your fast reply, you saved me hours of double checking. I
have already spent more than 2 hours with this but your explanation
saves me many more.
About introducing -nl programmes in an ado file, it is not relevant to
my case anymore since I will use -nl in a single command rather than a
-nl programme. However, it may be relevant to others. Creating a new
command using ado files, it may be useful to use to structure the ado
file as follows
program define myprog
...
nl auxeq z
...
end
program define nl auxeq
...
end
for many reasons (especially, you minimize the number of ado files and
commands). However, I couldnt make it work.
Thanks again,
Paulo
On Wed, Nov 19, 2008 at 12:42 AM, Brian P. Poi <[email protected]> wrote:
> On Tue, 18 Nov 2008, Paulo Regis wrote:
>
>> 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)
>>
> ...
>>
>> 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)
>
>
> In Stata 9, we rewrote -nl- so that it produced more accurate results. In
> your command -nl equ z ...-, you are using the pre-Stata 9 syntax for -nl-
> and therefore calling the older code that uses local macros instead of
> scalars for internal computations. Your command -nl (z1 = ...)- is using
> the current version of -nl-.
>
> In short, the version of your results using -nl (z1 = ...)- are more
> accurate than the results using -nl equ z ...-. Your example shows that
> "more accurate" does not always mean "lower sum of squares."
>
>>
>> 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
>
> When I write an ado-file (command) that is going to use -nl-, I put the
> program that defines the nonlinear function in its own ado-file. If you
> look at -help nl-, in one of the examples we define a program called
> "nlces". You would put that code in a separate ado-file called nlces.ado.
> Then your main ado-file would use the "function evaluator program" version
> of -nl-.
>
>>
>> 2- Is illegal to name a programme if the name start with numbers?
>> (i.e.: a programme named 2sls)
>
> Program names must start with a letter.
>
> -- Brian Poi
> -- [email protected]
>
> *
> * 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/