Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: -by- in ML


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   Re: st: -by- in ML
Date   Tue, 07 Jun 2005 00:22:26 +0200

>
> program mylogit2
> 	version 8.0
> 	args todo b lnf
> 	tempvar theta1 a c group_sum last
> 	mleval `theta1' = `b', eq(1)
> 	quietly gen double `a' = exp(`theta1')/(1+exp(`theta1'))
> 	quietly gen double `c' =  1/(1+exp(`theta1'))
> 	by us_id: gen double `group_sum' = sum(ln(`a'^($ML_y1) * `c'^(1-$ML_y1)))
> 	by us_id: gen double `last' = (_n==_N)
> 	mlsum `lnf' = `group_sum' if `last'
> end
>
> ml model d0 mylogit2 (y = x1 x2)
> ml check
> ml search
> ml maximize
>

Have you tried -egen- instead of -generate- ?
If I'm not mistaken, the -sum()- option with -generate- gives the
running sum, while with -egen- it gives the overall sum within the -by-
group.

If your data is randomly re-sorted within the -by- group, using -egen-
will ensure that the `last' observation of each group does give the
overall sum.

my 2 cents,

Antoine
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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