Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# st: maximum likelihood estimation of discrete random effects

 From Giorgia Lee To statalist@hsphsun2.harvard.edu Subject st: maximum likelihood estimation of discrete random effects Date Fri, 23 Jul 2010 14:01:10 +0200

```Hi,

I am studying exit of firms as a function of competition in their
market. I have yearly data.

My dataset stacks obervations on the same firms over 10 years.

I model the per period hazard with a logit .

I introduce unobserved heterogeneity using a discrete random effect
with 2 points of support, the heterogeneity is introduced through the
intercept in the logit and have come up with the following program to
estimate this with Stata:

program define likemine4_d0

version 9.1

args todo b lnf

tempname theta1 theta2 t1 xb den a1 a2

tempvar coeff1 coeff2 lj1 product1 last lj2  product2 somma logproduct

mleval `theta1'=`b', eq(1) scalar

mleval `theta2'=`b', eq(2) scalar

mleval `t1'=`b', eq(3) scalar

mleval `xb'=`b', eq(4)

scalar `den'=1+exp(`t1')

scalar `a1'=exp(`t1')/`den'

scalar `a2'=1/`den'

sort oshpdpermidnum

quietly{

gen double `coeff1'=`theta1'+`xb'

gen double `coeff2'=`theta2'+`xb'

gen double `lj1'=invlogit(`coeff1')  if  \$ML_y1==1

replace `lj1'=invlogit(-`coeff1')  if  \$ML_y1==0

by oshpdpermidnum: egen `product1'=prod(`lj1')

by oshpdpermidnum: gen `last'=_n==_N

gen double `lj2'=invlogit(`coeff2')  if  \$ML_y1==1

replace `lj2'=invlogit(-`coeff2')  if  \$ML_y1==0

by oshpdpermidnum: egen `product2'=prod(`lj2')

by oshpdpermidnum: gen double
`somma'=`a1’*`product1’+`a2’*`product2’ if `last’==1

by oshpdpermidnum: gen double `logproduct'=ln(`somma’) if
`last’==1

mlsum `lnf'=`logproduct' if `last'==1

}

end

ml model d0 likemine4_d0 (theta1:) (theta2:) (t1:) (closed=compet
logddep logddep2 logddep3)

ml maximize

However, Stata starts the calculations and then the iterations never
stop because of non concavity. I know that gllamm can estimate this
type of heterogenetity, but I still would like to know what’s wrong
with my code.

Thanks a lot!!

*
*   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/
```