--- 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'))
end
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:
http://www.maartenbuis.nl/stata/exampleFAQ.html )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/