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

Re: st: keeping likelihood for every observation

From   Maarten buis <>
Subject   Re: st: keeping likelihood for every observation
Date   Sun, 7 Feb 2010 10:12:48 +0000 (GMT)

--- On Sun, 7/2/10, Stephane Mahuteau wrote:
> Could anyone let me know how I can save the log likelihood
> for every observation in my dataset and keep it as a
> variable? 

You can recreate the likelihood relatively simply with the
-predictnl- command, as in the example below. Whether that
is efficient depends on how you want to use that variable.

*--------------------- begin example -----------------------------------
program drop _all
program define mynorm_lf
        args lnf xb ln_sigma
        qui replace `lnf' = lnnormalden($ML_y1, `xb', exp(`ln_sigma'))
sysuse auto, clear
ml model lf mynorm_lf (mu: mpg = foreign rep78 displacement) /ln_sigma
ml check
ml search
ml maximize

predictnl double lnf = lnnormalden(mpg,xb(#1),exp(xb(#2))) if e(sample)

// check if this is the correct variable
sum lnf, meanonly
di r(sum)
*----------------------- end example -----------------------------------
( For more on how to use examples I sent to statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

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