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]

st: External variable does not change within a user-defined program


From   Yuliya Romanenko <[email protected]>
To   [email protected]
Subject   st: External variable does not change within a user-defined program
Date   Wed, 26 Mar 2014 13:23:10 +0100

Dear all,

I am running Maximum Likelihood and I am interested in saving the
contribution of each observation to the log-likelihood. I am using the
suggestion to define the external variable -lnLL- before my likelihood
code and change the code of my program to include replacement of
-lnLL- with an internally computed value of log-likelihood. However,
after defining the model and running the -ml maximize- I see no change
in my -lnLL- variable despite the fact that the  value of the
log-likelihood does change. To be more clear, I include a simple
example below:

. sysuse auto, clear
. program define mynorm_lf

    1. args lnf xb ln_sigma
    2. qui replace `lnf' = lnnormalden($ML_y1, `xb', exp(`ln_sigma'))
    3. qui replace lnLL=`lnf'
. end

. gen double lnLL=.
. ml model lf mynorm_lf (xb: mpg = foreign rep78 displacement) (ln_sigma:)
. ml max

  initial:           log likelihood = -16870.907
  alternative:   log likelihood =  -6014.006
  rescale:        log likelihood = -343.25904
  rescale eq:   log likelihood = -240.51981
  Iteration 0:    log likelihood = -240.51981  (not concave)
  ...
  Iteration 4:    log likelihood = -190.26779
  Iteration 5:    log likelihood = -190.26779

                                                    Number of obs  =  69
                                                    Wald chi2(3)   =  91.91
 Log likelihood = -190.26779       Prob > chi2     =     0.00

  ------------------------------------------------------------------------------
         mpg |    Coef.   Std. Err.    z    P>|z|     [95% Conf. Interval]
   -------------+----------------------------------------------------------------
 xb             | ...

  ...
   -------------+----------------------------------------------------------------
  ln_sigma  | ...

  ...
  ------------------------------------------------------------------------------



 . tabstat lnLL, stat(sum)

     variable |       sum
  -------------+----------
          lnLL |         0
  ------------------------

After running this all in Stata 13 I see that -lnLL- is still a
variable of  missing values, though the log-likelihood does change (=
-190.26779 after 5  iterations) and I would expect the -tabstat lnLL,
stat(sum)- to give me  exactly -190.26779. So I am wondering why
aren't all those changes saved in  my external -lnLL-? Is not the -qui
replace lnLL=`lnf'- line executed?

 I would be very grateful for any advice on this.

 Kind regards,
 Yuliya
*
*   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