Statalist


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

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


From   "Eva Poen" <eva.poen@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: -ml- : how to save the likelihood contribution for each observation in a variable?
Date   Fri, 10 Oct 2008 15:24:17 +0100

Thanks a lot, Mike. I tried your suggestion by adding a line

        replace     LL   = `lnj'

in the d0 evaluator program. I then generated LL and ran the program:

gen LL = 99
myestimator ....

. sum LL

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          LL |      6840          99           0         99         99


It seems like nothing happened to the LL variable at all. However, the
program will complain if I -drop- LL :

variable LL not found
r(111);

So, whatever is being done to LL along the way, is also being undone
again. I'm slightly puzzled.

Eva


2008/10/10 Michael Anthony Carlton <carlto12@msu.edu>:
> 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: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] 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
> *

> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index