# st: mle programming for fixed effects poisson

 From "Eiji Mangyo" To Subject st: mle programming for fixed effects poisson Date Tue, 18 Jun 2002 14:21:22 -0400

```Dear Statalist,

I am new to stata programming. I want to calculate the robust variance
matrix for the fixed effects Poisson estimator. (Wooldridge 2001,
Econometric Analysis of Cross Section and Panel Data, p676). As far as I can
see, there seems no module for this at SSC. (I would appreciate your
directing me to any related module if any.) I've started programming the
maximum likelihood algorithm for the fixed effects Poisson estimator. My
program produces the same coefficient and standard error estimates as the
Stata _xtpois, fe_ does. (The outputs for both are attached below.) However,
I have three concerns:

1. My program produces the description "8112 real changes made" many times
on the process of maximing the likelihood. (Please see below.) What does
that mean?

2. The log likelihood differs a lot between my program and the Stata
_xtpois, fe_. Any idea about how this happens?

3. The number of observations differs between the two. I suspect this is
because the Stata _xtpois, fe_ drops the following individuals when
maximizing the log likelihood: i) those individuals with only one
observation and ii) those with the dependent variable being equal to zero
for all repeated observations. At least the math is correct: 8112 = 5976 +
585  + 1551 (please see below.) Is my guess correct?

Thank you very much for advices.

Eiji

OUTPUT using my program:

12 . program define mypoisfe;
1. version 7;
2. args todo b lnf;
3. tempvar flag theta mit mi pit lnfit lnfi T;
4. /* flag non-missing observations; */
> gen byte `flag'=0;
5. replace `flag'=1 if nohosp1~=.&mar~=.&work~=.&
> prop~=.&save~=.&othass~=.&srhs~=.&srhssq~=.&
> lival~=.&cht~=.&hins~=.&d89~=.&d96~=.;
6. mleval `theta'=`b';
7. quietly {;
8. gen double `mit'=exp(`theta') if `flag'==1;
9. by id: egen double `mi'=sum(`mit') if `flag'==1;
10. gen double `pit'=`mit'/`mi' if `flag'==1;
11. gen double `lnfit'=\$ML_y1*log(`pit') if `flag'==1;
12.  by id: egen double `lnfi'=sum(`lnfit') if `flag'==1;
13. by id: gen byte `T'=cond(_n==_N,_N,.) if `flag'==1;
14. mlsum `lnf'=`lnfi' if `T'~=.;
15. };
16. end;

13 . ml model d0 mypoisfe (nohosp1=mar work prop save othass
> srhs srhssq lival cht hins d89 d96, noconstant);

14 . ml max;

initial:       log likelihood = -10794.703
alternative:   log likelihood = -10792.961
rescale:       log likelihood = -10790.706

.........the same description repeated many times.............

Iteration 0:   log likelihood = -10790.706

.........the same description repeated many times.............

Iteration 1:   log likelihood = -10332.409

.........the same description repeated many times.............

Iteration 2:   log likelihood = -10330.838
.........the same description repeated many times.............

Iteration 3:   log likelihood = -10330.838

Number of obs
=8112
Wald chi2(12)
=869.89
Log likelihood = -10330.838                       Prob > chi2
=0.0000

----------------------------------------------------------------------
--------
nohosp1 |      Coef.   Std. Err.      z    P>|z|     [95%
Conf.Interval]
-------------+--------------------------------------------------------
--------
mar |    .075184   .0542964     1.38   0.166     -.031235
.1816029
work |   -.006175   .0418165    -0.15   0.883    -.0881338
.0757837
prop |  -.0541184   .0387712    -1.40   0.163    -.1301085
.0218717
save |  -.0157391   .0306826    -0.51   0.608     -.075876
.0443978
othass |   -.110837   .0772474    -1.43   0.151    -.2622392
.0405652
srhs |   .2071323   .0636344     3.26   0.001     .0824111
.3318534
srhssq |   .0176558   .0105749     1.67   0.095    -.0030706
.0383822
lival |   .0539819   .0420495     1.28   0.199    -.0284336
.1363973
cht |   .0431224   .0211307     2.04   0.041     .0017071
.0845378
hins |   .2528749   .0475968     5.31   0.000      .159587
.3461629
d89 |  -.2045044   .0269524    -7.59
0.000    -.2573302   -.1516787
d96 |    .155866    .026792     5.82   0.000     .1033547
.2083773
----------------------------------------------------------------------
--------

OUTPUT using _xtpois, fe_:

11 . xtpois nohosp1 mar work prop save othass
> srhs srhssq lival cht hins d89 d96, fe;
note: 585 groups (585 obs) dropped because of only one obs per group
note: 630 groups (1551 obs) dropped due to all zero outcomes

Iteration 0:   log likelihood =  -6445.882
Iteration 1:   log likelihood = -5983.6536
Iteration 2:   log likelihood =  -5982.017
Iteration 3:   log likelihood = -5982.0169

Conditional fixed-effects Poisson               Number of obs      =
5976
Group variable (i) : id                         Number of groups   =
2221

Obs per group: min =
2
avg =
2.7
max =
3

Wald chi2(12)      =
869.89
Log likelihood  = -5982.0169                    Prob > chi2        =
0.0000

----------------------------------------------------------------------
--------
nohosp1 |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+--------------------------------------------------------
--------
mar |    .075184   .0542964     1.38   0.166     -.031235
.1816029
work |   -.006175   .0418165    -0.15   0.883    -.0881338
.0757837
prop |  -.0541184   .0387712    -1.40   0.163    -.1301086
.0218717
save |  -.0157391   .0306826    -0.51   0.608    -.0758759
.0443978
othass |  -.1108369   .0772474    -1.43   0.151     -.262239
.0405653
srhs |   .2071322   .0636345     3.26   0.001     .0824109
.3318535
srhssq |   .0176558   .0105749     1.67   0.095    -.0030706
.0383822
lival |   .0539819   .0420495     1.28   0.199    -.0284336
.1363974
cht |   .0431224   .0211307     2.04   0.041     .0017071
.0845377
hins |   .2528749   .0475968     5.31   0.000      .159587
.3461629
d89 |  -.2045044   .0269524    -7.59
0.000    -.2573301   -.1516786
d96 |   .1558661    .026792     5.82   0.000     .1033548
.2083773
----------------------------------------------------------------------
--------

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