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: maximum likelihood
From
"Abhimanyu Arora" <[email protected]>
To
<[email protected]>
Subject
RE: st: maximum likelihood
Date
Tue, 13 Apr 2010 16:35:24 +0200
Thanks a lot Maarten for your reply. Upon closer inspection, yes, the 1-
should be inside the log, thanks for pointing it out. I am trying to solve a
problem based on Rust's (1987) capital replacement model but I am completely
revising my code now after a finding a crucial error in my procedure.
In general, while doing maximum likelihood, why is it so that running
exactly the same do-file containing the ml commands twice can give no output
once (missing values encountered, unable to calculate numerical derivatives)
and can give you the estimates (with std error) the other time?
Regards
Abhimanyu
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Maarten buis
Sent: dinsdag 13 april 2010 14:01
To: [email protected]
Subject: Re: st: maximum likelihood
It is hard to comment on such code without knowing what kind of model you
want to estimate, but the one thing that looks odd is that in case of "i==0"
you have "1-" part that happens outside the "ln()". The element
inside ln() is usually a probability, so a "1-" often happens when you
want the complement of that. In that case the "1-" part should happen
within the "ln()" part.
However, I can't help but feel you should be able to do all this wihtout
resorting to -ml-, but instead look at -mlogit- maybe in combination with
-constraint- or -clogit-.
-- Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
--- On Tue, 13/4/10, Abhimanyu Arora <[email protected]>
wrote:
> From: Abhimanyu Arora <[email protected]>
> Subject: st: maximum likelihood
> To: [email protected]
> Date: Tuesday, 13 April, 2010, 12:06
> Dear statalist
> I have been trying to find the maximum likelihood estimates
> of my model, but
> I do not obtain standard errors (likelihood function
> non-concave and just a
> couple of iterations achieved). Following the section
> "Importance of
> generating temporary variables as doubles" pg 58-60 of the
> book by Gould et
> al, I generate temporary variables which are functions of
> my parameters to
> be estimated, only to obtain totally different coefficient
> values but still
> no standard errors+no concavity. What is the reason behind
> this puzzling
> phenomenon and its solution? Is my ml model command ok even
> though I may not
> have any _dependent_ variable as such?
>
> Please find below the initial and final likelihood
> evaluators. I have two
> variables "i" (0/1) and "age"(1-5) and a constant matrix
> V(1X5) and need to
> find parameters theta_1 and R which determine the
> likelihood of each
> observation as below.
>
> Thanks and regards
> Abhimanyu Arora
> KU Leuven
>
>
> *******************
> Initial ml commands
> *******************
>
> cap program drop maxl
>
> program define maxl
> qui{
> args lnf theta_1 R
>
> replace
>
`lnf'=ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,2])+exp(`R'+0.9*V
> [1,1])) if i==1 & age ==1
>
> replace
>
`lnf'=ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,3])+exp(`R'+0.9*V
> [1,1])) if i==1 & age ==2
>
> replace
>
`lnf'=ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,4])+exp(`R'+0.9*V
> [1,1])) if i==1 & age ==3
>
> replace
>
`lnf'=ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,5])+exp(`R'+0.9*V
> [1,1])) if i==1 & age ==4
>
> replace
>
`lnf'=ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,5])+exp(`R'+0.9*V
> [1,1])) if i==1 & age ==5
>
>
> replace
>
`lnf'=1-ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,2])+exp(`R'+0.9
> *V[1,1])) if i==0 & age ==1
> replace
>
`lnf'=1-ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,3])+exp(`R'+0.9
> *V[1,1])) if i==0 & age ==2
> replace
>
`lnf'=1-ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,4])+exp(`R'+0.9
> *V[1,1])) if i==0 & age ==3
> replace
>
`lnf'=1-ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,5])+exp(`R'+0.9
> *V[1,1])) if i==0 & age ==4
> replace
>
`lnf'=1-ln((exp(`R'+0.9*V[1,1]))/exp(age*(`theta_1')+0.9*V[1,5])+exp(`R'+0.9
> *V[1,1])) if i==0 & age ==5
>
> }
>
> end
> ml model lf maxl (theta_1:) (R:)
> ml check
> ml init 0 0,copy
> ml maximize,difficult
>
> *****************************************
> Introducing double temporary variables
> *****************************************
> cap program drop maxl
>
> program define maxl
> qui{
> args lnf theta_1 R
> tempvar a b
> gen double `a' =age*(`theta_1')
> gen double `b'=exp(`R'+0.9*V[1,1])
>
> replace `lnf'=ln(`b'/(exp(`a'+0.9*V[1,2])+`b')) if
> i==1 & age ==1
>
> replace `lnf'=ln(`b'/(exp(`a'+0.9*V[1,3])+`b')) if
> i==1 & age ==2
>
> replace `lnf'=ln(`b'/(exp(`a'+0.9*V[1,4])+`b')) if
> i==1 & age ==3
>
> replace `lnf'=ln(`b'/(exp(`a'+0.9*V[1,5])+`b')) if
> i==1 & age ==4
>
> replace `lnf'=ln(`b'/(exp(`a'+0.9*V[1,5])+`b')) if
> i==1 & age ==5
>
>
> replace `lnf'=1-ln(`b'/(exp(`a'+0.9*V[1,2])+`b')) if
> i==0 & age ==1
> replace `lnf'=1-ln(`b'/(exp(`a'+0.9*V[1,3])+`b')) if
> i==0 & age ==2
> replace `lnf'=1-ln(`b'/(exp(`a'+0.9*V[1,4])+`b')) if
> i==0 & age ==3
> replace `lnf'=1-ln(`b'/(exp(`a'+0.9*V[1,5])+`b')) if
> i==0 & age ==4
> replace `lnf'=1-ln(`b'/(exp(`a'+0.9*V[1,5])+`b')) if
> i==0 & age ==5
>
> }
>
> end
> ml model lf maxl (theta_1:) (R:)
> ml check
> ml init 0 0,copy
> ml maximize,difficult
>
> *
> * 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/
*
* 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/