Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Two seemingly similar NL estimations give different results


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Two seemingly similar NL estimations give different results
Date   Thu, 23 Jan 2014 12:19:12 +0000

<>

Good catch.
Nick
[email protected]


On 23 January 2014 12:12, Schaffer, Mark E <[email protected]> wrote:
> Michael, Nick,
>
> I think I might have spotted an important difference in the two programs.
>
> The problem with the indirect code
>
> // Compute RHS of regression
>     tempvar RHS
>     qui gen `RHS'=.
>     replace `RHS' =...
>
> is that the temporary variable `RHS' is probably being created as a float.  If the original `rhs' variable is a double, you can get differences arising because of numerical imprecision in the indirect code.
>
> If you replace
>
>     qui gen `RHS'=.
>
> with
>
>     qui gen double `RHS'=.
>
> the discrepancy may go away.
>
> --Mark
>
>> -----Original Message-----
>> From: [email protected] [mailto:owner-
>> [email protected]] On Behalf Of Schaffer, Mark E
>> Sent: 23 January 2014 11:06
>> To: [email protected]
>> Subject: RE: st: Two seemingly similar NL estimations give different results
>>
>> Nick,
>>
>> Maybe I'm missing something but I don't see how that addresses Michael's
>> problem.
>>
>> As far as I can tell, his two nlexppremia programs are functionally identical.
>>
>> The first one replaces the contents of the variable `lhs' (first arg passed to the
>> program) in two steps, depending on the value of `s' (second arg).
>>
>> The second one creates a tempvar `RHS' and gives the same contents, again in
>> two steps depending on `s'.  Then it assigns the values of `RHS' to `lhs'.
>>
>> So when the two programs are done running, they both should have replaced
>> the contents of `lhs' with exactly the same thing (hence functionally identical).
>> Or at least that how it looks to Michael (and to me).
>>
>> Unless there is a typo lurking in one or the other, I'm puzzled too...
>>
>> --Mark
>>
>> > -----Original Message-----
>> > From: [email protected] [mailto:owner-
>> > [email protected]] On Behalf Of Nick Cox
>> > Sent: 23 January 2014 10:48
>> > To: [email protected]
>> > Subject: Re: st: Two seemingly similar NL estimations give different
>> > results
>> >
>> > As I read this, every time it is called, -nl- replaces parameters with
>> > values from the matrix you specified. That reduces the scope for
>> > moving away from those initial values.
>> > Nick
>> > [email protected]
>> >
>> >
>> > On 23 January 2014 09:21, Michael Boehm <[email protected]>
>> > wrote:
>> > > Dear Nick,
>> > >
>> > > Thanks for your answer. I am not quite sure I understand it though.
>> > > All the parameters we estimate are free to vary in both
>> > > implementations of the -nl- command (more detailed code below), but
>> > > the estimates are different. Or do I misunderstand something?
>> > >
>> > > program nlexppremia
>> > > version 13.1
>> > > syntax varlist(min=4 max=4) [aw fw iw] if, at(name)
>> > >
>> > > // Retrieve variables
>> > >         local lhs:    word 1 of `varlist'
>> > >         local s:       word 2 of `varlist'
>> > >         local j:       word 3 of `varlist'
>> > >         local e:       word 4 of `varlist'
>> > >
>> > > // Retrieve parameters, stored in "at"
>> > > tempname bG pi lambdaL1_0 lambdaL2_0 lambdaEL1_0 lambdaEL2_0
>> > > lambdaL1_1 lambdaL2_1 lambdaEL1_1 lambdaEL2_1
>> > >     scalar `bG' = `at'[1,1]
>> > >     scalar `pi' = `at'[1,2]
>> > >     scalar `lambdaL1_0' = `at'[1,3]
>> > >     scalar `lambdaL2_0' = `at'[1,4]
>> > >     scalar `lambdaEL1_0' = `at'[1,5]
>> > >     scalar `lambdaEL2_0' = `at'[1,6]
>> > >     scalar `lambdaL1_1' = `at'[1,7]
>> > >     scalar `lambdaL2_1' = `at'[1,8]
>> > >     scalar `lambdaEL1_1' = `at'[1,9]
>> > >     scalar `lambdaEL2_1' = `at'[1,10]
>> > >
>> > > // replace the lhs directly:
>> > >     replace `lhs' = `bG'+(`lambdaL1_0'*j+`lambdaL2_0'*j^2) +
>> > > log(1+`pi'*exp(`lambdaEL1_0'*j+`lambdaEL2_0'*j^2)*`e') if `s'==0
>> > >     replace `lhs' = `bG'+(`lambdaL1_1'*j+`lambdaL2_1'*j^2) +
>> > > log(1+`pi'*exp(`lambdaEL1_1'*j+`lambdaEL2_1'*j^2)*`e') if `s'==1 end
>> > >
>> > > nl exppremia @ lhs s j e, nparameters(10)
>> > >
>> > >
>> >
>> ****************************************************************
>> > ****
>> > >
>> > > program nlexppremia
>> > > version 13.1
>> > > syntax varlist(min=4 max=4) [aw fw iw] if, at(name)
>> > >
>> > > // Retrieve variables
>> > >         local lhs:    word 1 of `varlist'
>> > >         local s:       word 2 of `varlist'
>> > >         local j:       word 3 of `varlist'
>> > >         local e:       word 4 of `varlist'
>> > >
>> > > // Retrieve parameters, stored in "at"
>> > > tempname bG pi lambdaL1_0 lambdaL2_0 lambdaEL1_0 lambdaEL2_0
>> > > lambdaL1_1 lambdaL2_1 lambdaEL1_1 lambdaEL2_1
>> > >     scalar `bG' = `at'[1,1]
>> > >     scalar `pi' = `at'[1,2]
>> > >     scalar `lambdaL1_0' = `at'[1,3]
>> > >     scalar `lambdaL2_0' = `at'[1,4]
>> > >     scalar `lambdaEL1_0' = `at'[1,5]
>> > >     scalar `lambdaEL2_0' = `at'[1,6]
>> > >     scalar `lambdaL1_1' = `at'[1,7]
>> > >     scalar `lambdaL2_1' = `at'[1,8]
>> > >     scalar `lambdaEL1_1' = `at'[1,9]
>> > >     scalar `lambdaEL2_1' = `at'[1,10]
>> > >
>> > > // Compute RHS of regression
>> > >     tempvar RHS
>> > >     qui gen `RHS'=.
>> > >     replace `RHS' = `bG'+(`lambdaL1_0'*j+`lambdaL2_0'*j^2) +
>> > > log(1+`pi'*exp(`lambdaEL1_0'*j+`lambdaEL2_0'*j^2)*`e') if `s'==0
>> > >     replace `RHS' = `bG'+(`lambdaL1_1'*j+`lambdaL2_1'*j^2) +
>> > > log(1+`pi'*exp(`lambdaEL1_1'*j+`lambdaEL2_1'*j^2)*`e') if `s'==1
>> > >
>> > > //Assign lhs=rhs
>> > >     replace `lhs' = `RHS'
>> > >
>> > > end
>> > >
>> > > nl exppremia @ lhs s j e, nparameters(10)
>> > >
>> > >
>> >
>> ****************************************************************
>> > ****
>> > > *
>> > > *   For searches and help try:
>> > > *   http://www.stata.com/help.cgi?search
>> > > *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
>> > *   http://www.ats.ucla.edu/stat/stata/
>>
>>
>> -----
>> Sunday Times Scottish University of the Year 2011-2013 Top in the UK for
>> student experience Fourth university in the UK and top in Scotland (National
>> Student Survey 2012)
>>
>> We invite research leaders and ambitious early career researchers to join us in
>> leading and driving research in key inter-disciplinary themes.
>> Please see www.hw.ac.uk/researchleaders for further information and how to
>> apply.
>>
>> Heriot-Watt University is a Scottish charity registered under charity number
>> SC000278.
>>
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
> -----
> Sunday Times Scottish University of the Year 2011-2013
> Top in the UK for student experience
> Fourth university in the UK and top in Scotland (National Student Survey 2012)
>
> We invite research leaders and ambitious early career researchers to
> join us in leading and driving research in key inter-disciplinary themes.
> Please see www.hw.ac.uk/researchleaders for further information and how
> to apply.
>
> Heriot-Watt University is a Scottish charity
> registered under charity number SC000278.
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index