Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting the d0 method to lf0 method in an ml program

    Hello Stata users,
    I use Stata 13.1 and I'm trying to convert the d0 evaluation method of my ml program to the lf0 method to improve the execution speed of the program. The likelihood function in my program is a complex one but it meets the linear-form restrictions so I thought that changing quietly mlsum `lnf' to quietly replace `lnf' and changing ml model d0 to ml model lf0 would be enough for the program to run with the lf0 method. I actually tried this with a very simple example that I pasted below and it worked and improved the execution speed. However, when I try the same thing with my ml program, here is what happens:

    The program with the d0 method starts with an -ml search-, runs well (but slowly), and produces the correct results using the simulated data. I save the e(b) matrix. Then I convert the program method to lf0 method as I explained above. Now if I set the initial values to the saved e(b) matrix, the program with the lf0 method runs well and produces similar results. But if I don't assign any initial values, and just let it do an -ml search-, it starts iterating afterwards, but after a while, it gets "stuck" and iterates around a likelihood value without improving much, and it just doesn't converge... I don't understand what the problem is.

    Not starting from a good set of initial values may be the problem, but the program with the d0 method does well and converges simply with the same -ml search-. So I don't think that that is the problem. Any ideas about what the problem could be (without seeing the actual program)? The actual program is too big to post here but I can send it to those who want to take a look at it.


    Code:
    sysuse cancer, clear
    expand 1000
    
    capture program drop weib0
    program weib0
        version 13
        
        args todo b lnf
        tempvar theta1 theta2
        mleval `theta1' = `b', eq(1)
        mleval `theta2' = `b', eq(2)
        
        quietly mlsum `lnf' = -(($ML_y1 * exp(-`theta1'))^exp(`theta2')) + /*
        */    $ML_y2 * (`theta2'-`theta1' + (exp(`theta2')-1)*(ln($ML_y1)-`theta1'))
    end
    
    capture program drop weib1
    program weib1
        version 13
        
        args todo b lnf
        tempvar theta1 theta2
        mleval `theta1' = `b', eq(1)
        mleval `theta2' = `b', eq(2)
        
        quietly replace `lnf' = -(($ML_y1 * exp(-`theta1'))^exp(`theta2')) + /*
        */    $ML_y2 * (`theta2'-`theta1' + (exp(`theta2')-1)*(ln($ML_y1)-`theta1'))
    end
    
    timer clear
    
    timer on 1
    ml model d0 weib0 (studytime died = i.drug age) /s
    ml maximize
    timer off 1
    
    timer on 2
    ml model lf0 weib1 (studytime died = i.drug age) /s
    ml maximize
    timer off 2
    
    timer list
    Last edited by Cyrus Levy; 26 Nov 2014, 20:09.
Working...
X