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: MLE problem could not converge


From   Fernando Rios Avila <[email protected]>
To   [email protected]
Subject   Re: st: MLE problem could not converge
Date   Mon, 10 Mar 2014 08:30:11 -0400

Dear Jie Li,
Couples of words of advise. First, In my experience, a non converging
MLE might be symptom that the model specification is not correct. I
dont see any obvious mistakes on the the program, and Im assuming you
solve the math problem, and there are no errors copying the forumulas.
It could also be a symtom the problem is simply highly non linear,
thus is difficult to maximize. There is no fix for this, as it is not
a problem itself. it means you need to play around with the
specification and data, until you find feasible and credible initial
values. This initial values can be calibrated, either based on the old
specification you were referring, or you can come up with some, based
on your expectation of the model.
The second option is just playing around with the data, until it
provides appropriate initial values. I would do this using the next
steps:
   1. Estimate the model for a small random sample, allowing for, say,
20 iterations.
   2. Once the model finish the X number of iterations, check if the
parameters on that step are consistent with your expectations, or make
no sense.
   3. If they make no sense, do step 1. If they make sense, attempt to
estimate the model using the the results from 1 as initial values.
The idea of estimating the results for a random sample, is not to have
a representative sample from the your data, but to accelerate the
estimation process and find feasible parameters.
Allowing for 20 iteration (or more/less depending on your preference),
gives the algorithm time to attempt finding a solution to the problem,
but if that is unsuccessful, let you check what is happening at that
at that step.
Hope this helps.
Fernando


On Mon, Mar 10, 2014 at 3:36 AM, jie li <[email protected]> wrote:
> I am currently trying to program my own patent value elimination models
> using Statas ml command, and I have got a original code that one author had
> used for the same question. And my model is a bit different with his one.
> So I have to make some adapt. So far, my attempts have not been very
> successful. I have checked the help files of Stata, Statalist and gone
> through the book of William Gould et al. on programming maximum likelihood
> in Stata (they have some advice on ml check but I cannot fix the problem)
> and have asked people at my department to no avail, and I have discussed
> the model with teachers and they said the model setting is ok. Since I am
> really a rookie in programming mle problem using stata, any advice will be
> useful. My do file is shown below:
> *estimate the parameter with mle
> set more off
> capture program drop myprog_patent
> program define myprog_patent
> version 12.0
> args lnf mu sigma d
> *d stands for the depreciation rate
> tempvar lnzt lnzt1
> * termiyear means the expired year of the patent
> quietly gen double `lnzt'=ln(1-exp(-(`d'+0.1)))-(`d'*t)-ln(`d'+0.1)
> quietly gen double `lnzt1'=ln(1-exp(-(`d'+0.1)))-(`d'*(t-1))-ln(`d'+0.1)
> * this means that the patent is expired but not renewed full term
> quietly replace `lnf' =
> ln(normal(-(`mu'+`lnzt'-ln(nextfee))/`sigma')-normal(-(`mu'+`lnzt1'-ln(lastfee))/`sigma'))
> if stat==2
> * this means that the patent is not expired
> quietly replace `lnf' = ln(normal((`mu'+`lnzt'-ln(nextfee))/`sigma')) if stat==4
> end
>
> * t stands for termiyear - applyear if the patent is expired or 2011 -
> applyear if the patent is still renewed
> ml model lf myprog_patent (mu: t = ) /sigma /d
> ml check
> ml search d 0 1 mu 2 10 sigma 4 20
> ml maximize, difficult
>
> And here is the results of the do file, which shows the problem is not
> converged and the value of log likelihood doesn't change since the 5th
> iteration is over:
> . ml check
>
> Test 1:  Calling myprog_patent to check if it computes log likelihood and
>          does not alter coefficient vector...
>          Passed.
>
> Test 2:  Calling myprog_patent again to check if the same log likelihood value
>          is returned...
>          Passed.
>
> ------------------------------------------------------------------------------
> The initial values are not feasible.  This may be because the initial values
> have been chosen poorly or because there is an error in myprog_patent and it
> always returns missing no matter what the parameter values.
>
> Stata is going to search for a feasible set of initial values.
> If myprog_patent is broken, this will not work and you will have to press
> Break to stop the search.
>
> Searching...
> initial:       log likelihood =     -<inf>  (could not be evaluated)
> searching for feasible values .+
>
> feasible:      log likelihood = -767909.24
> improving initial values ....+.....
> improve:       log likelihood = -699963.77
> rescaling entire vector .++++++++++++++++++++++++++++++++++++++++++++++++++.
> rescale:       log likelihood = -683197.33
> rescaling equations .++...+.
> rescaling equations ......
> rescale eq:    log likelihood = -292418.69
>
> restarting tests...
> ------------------------------------------------------------------------------
>
> Test 1:  Calling myprog_patent to check if it computes log likelihood and
>          does not alter coefficient vector...
>          Passed.
>
> Test 2:  Calling myprog_patent again to check if the same log likelihood value
>          is returned...
>          Passed.
>
> Test 3:  Calling myprog_patent to check if 1st derivatives are computed...
>          test not relevant for type lf evaluators.
>
> Test 4:  Calling myprog_patent again to check if the same 1st derivatives are
>          returned...
>          test not relevant for type lf evaluators.
>
> Test 5:  Calling myprog_patent to check if 2nd derivatives are computed...
>          test not relevant for type lf evaluators.
>
> Test 6:  Calling myprog_patent again to check if the same 2nd derivatives are
>          returned...
>          test not relevant for type lf evaluators.
>
> ------------------------------------------------------------------------------
> Searching for alternate values for the coefficient vector to verify that
> myprog_patent returns different results when fed a different coefficient
> vector:
>
> Searching...
> initial:       log likelihood =     -<inf>  (could not be evaluated)
> searching for feasible values .+
>
> feasible:      log likelihood = -936696.18
> improving initial values ..+.......
> improve:       log likelihood =  -586671.1
>
> continuing with tests...
> ------------------------------------------------------------------------------
>
> Test 7:  Calling myprog_patent to check log likelihood at the new values...
>          Passed.
>
> Test 8:  Calling myprog_patent requesting 1st derivatives at the new values...
>          test not relevant for type lf evaluators.
>
> Test 9:  Calling myprog_patent requesting 2nd derivatives at the new values...
>          test not relevant for type lf evaluators.
>
> ------------------------------------------------------------------------------
>                          myprog_patent HAS PASSED ALL TESTS
> ------------------------------------------------------------------------------
>
> Test 10: Does myprog_patent produce unanticipated output?
>          This is a minor issue.  Stata has been running myprog_patent with all
>          output suppressed.  This time Stata will not suppress the output.  If
>          you see any unanticipated output, you need to place quietly in front
>          of some of the commands in myprog_patent.
>
> -------------------------------------------------------------- begin execution
> ---------------------------------------------------------------- end execution
>
> . ml search d 0 1 mu 2 10 sigma 4 20
> initial:       log likelihood =  -586671.1
> rescale:       log likelihood = -475204.17
> rescale eq:    log likelihood = -288695.29
>
> . ml maximize, difficult
>
> initial:       log likelihood = -288695.29
> rescale:       log likelihood = -288695.29
> rescale eq:    log likelihood = -288695.29
> Iteration 0:   log likelihood = -288695.29  (not concave)
> Iteration 1:   log likelihood = -275824.93  (not concave)
> Iteration 2:   log likelihood = -270886.91  (not concave)
> Iteration 3:   log likelihood = -270752.57  (not concave)
> Iteration 4:   log likelihood = -270740.94  (not concave)
> Iteration 5:   log likelihood = -270740.34  (not concave)
> Iteration 6:   log likelihood = -270740.34  (not concave)
> Iteration 7:   log likelihood = -270740.34  (not concave)
> Iteration 8:   log likelihood = -270740.34  (not concave)
> Iteration 9:   log likelihood = -270740.34  (not concave)
> Iteration 10:  log likelihood = -270740.34  (not concave)
> Iteration 11:  log likelihood = -270740.34  (not concave)
> Iteration 12:  log likelihood = -270740.34  (not concave)
> Iteration 13:  log likelihood = -270740.34  (not concave)
> Iteration 14:  log likelihood = -270740.34  (not concave)
> Iteration 15:  log likelihood = -270740.34  (not concave)
> Iteration 16:  log likelihood = -270740.34  (not concave)
> Iteration 17:  log likelihood = -270740.34  (not concave)
>
> And the results doesn't change, even I have run this for more than
> 1000 iteration. So I really don't know what the problem may be. And
> what kind of problem it is, when the log likelihood value doesn't
> change and the problem doesn't converge, too.
> Could you give me some advice on how to fix this problem, does this
> mean I have something wrong with my data set, or it is my function
> setting which is wrong, or some other things that I just haven't come
> up with.
> Many regards.
> *
> *   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