Statalist


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

st: RE: -ml- : how to save the likelihood contribution for each observation in a variable?


From   "Michael Anthony Carlton" <[email protected]>
To   <[email protected]>
Subject   st: RE: -ml- : how to save the likelihood contribution for each observation in a variable?
Date   Fri, 10 Oct 2008 09:25:23 -0400

The easiest thing to do would be to create a variable likesave in your
dataset before you run the program. Then within the program simple add a
line:
quietly replace likesave =`lnf'

This will leave you with the log-likelihood value for each observation for
the last iteration of the problem, which is presumably what you want.

Mike

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Eva Poen
Sent: Friday, October 10, 2008 8:46 AM
To: Statalist
Subject: st: -ml- : how to save the likelihood contribution for each
observation in a variable?

This is what I'm trying to implement:
In my d0 likelihood evaluator, I would like to save the likelihood
contribution (`lnf') for each observation in a variable, for later
use. However, the newly created variable doesn't seem to be touched by
the d0 evaluator, but there is no error message either.

Here is what's in my estimation program:
/*----mm3w0w1.ado---*/
...
    // save likelihood?
    if "`llsave'" != "" {
        confirm new variable `llsave'
        tempvar likesave
        qui gen double `likesave' = .
        global LL_save "`likesave'"
    }
...
ml model d0 ...
ml maximize ...
...
    // save likelihood?
    if "`llsave'" != "" {
        qui gen double `llsave' = `likesave'
    }
...
/*-------------------------*/

where llsave() is an option to the program, which takes the new
variable name. The idea is to save a (temporary, in case the program
fails) variable name in $LL_save, and then process it in the
likelihood evaluator. In the evaluator, I have:

/*----mm3w0w1_d0.ado---*/
...
...
      gen double `lnj' = ...

       // save likelihood?
       if "$LL_save" != "" {
           replace $LL_save = `lnj'
       }

     mlsum `lnf' = `lnj'
...
/*-------------------------*/

The program runs fine (without error) and produces the expected
results, apart from the new variable. This variable will still be what
I set it to in mm3w0w1.ado in the first place. Can someone tell me
where the mistake is? I have a feeling that I'm missing something very
obvious.


Thanks,
Eva
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index