Statalist


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

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


From   "Eva Poen" <[email protected]>
To   Statalist <[email protected]>
Subject   st: -ml- : how to save the likelihood contribution for each observation in a variable?
Date   Fri, 10 Oct 2008 13:45:49 +0100

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/



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