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

Re: st: adjust after poisson


From   <[email protected]>
To   [email protected]
Subject   Re: st: adjust after poisson
Date   Sat, 09 Nov 2002 11:31:35 -0500

Thank-you very much Ken for the enlightening response and for explaining the
behavior of adjust. However, I still believe in my case, adjust with the
nooffset option still produces the correctly adjusted rates, butr, as yuor
example shows, not the counts.

This is because the model I am estimating is:

log(count)=alpha +beta*X+log(ptime)

if I want to predict a rate then I don't need the offset:

log(count)-log(ptime)=alpha+beta*x or
log(count/ptime)=alpha+beta*x

so exp(alpha+beta*x) should be the correct predicted rate. 


this can also be illustrated with another nonsense example from auto data. If
predict adjusted rates with the nooffset option and then , I get the same
results as if I  generate the counts and then divide by the exposure, trunk,
holding the by variable constant at the mean.

. poisson price mpg gear_ratio, exposure(trunk)
------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 mpg |  -.0157005   .0003584   -43.81  0.000    -.0164029   -.0149981
 gear_ratio |   .1412555   .0042963    32.88   0.000     .1328349    .1496761
 _cons |   6.005301     .00988  07.82   .000     5.985937    6.024666
       trunk | (exposure)
-------------------------------------------------

/*adjust with nooffset*/

. adjust mpg, by(gear_ratio)  gen(x1) exp nooffset

-------------------------------------------------------------------------------
     Dependent variable: price     Equation: price     Command: poisson
       Created variable: x1
  Covariate set to mean: mpg = 21.297297
-------------------------------------------------

/*predict log counts holding mpg constant at mean*/

. gen x4=6.005301+gear_ratio*.1412555+21.297297*-0.0157005+log(trunk)

/*generate counts*/

. gen x5=exp(x4)

/*generate rates*/
. gen x6=x5/trunk

. list x1 x6

        x1         x6
  1.  481.3611   481.3608
  2.  415.0086   415.0085
  3.  448.5364   448.5365
  4.  439.1327   439.1327

x1 and x6 are equal.


(Previous thread)


Timothy J. Wade <tjwade@c...> asks:

> I'm trying to obtain adjusted rates by month after the following poisson 
> regression:
> 
> xi: poisson count i.monthnum cycle, exposure(pyear)
> 
> when I type: . adjust cycle, by(monthnum) exp
> 
> I get the following error:
> offset (ln(pyear)) not constant within by()
> 
> however, when I use type the same adjust command with the "nooffset" 
> option. I get returned results that look approximately correct (see below).
> 
> My questions are: are the rates given after adjust with the nooffset option 
> the correct adjusted rates? Also, why do I need to specify the nooffset 
> option in adjust?
> Thanks very much in advance!
> 
> (stata 7.0/Windows)
> 
> . adjust cycle, by(month) exp nooffset
> ----------------------
> monthnum | exp(xb)
> ----------+-----------
> 1 | 2.38068
> 2 | 2.67684
> 3 | 2.18642
> 4 | 2.20107
> 5 | 2.09517
> 6 | 1.70584
> 7 | 2.01013
> 8 | 1.86005
> 9 | 1.64766
> 10 | 1.68153
> 11 | 2.37351
> 12 | 2.15014
> ----------------------
> Key: exp(xb) = exp(xb)


See the entry for 14oct2002 in -help whatsnew-. The -adjust-
command used to arbitrarily take one of the offsets within each
group defined by the by() option and use it in the prediction.
This is arbitrary, and hence no longer allowed. Instead, it
checks that offsets (or exposures) were not specified, and if
they were it checks to see if they are constant within the by()
groups.

The answers with and without the -nooffset- option will be
different. The -adjust- command is really just a convienent
front-end for -predict-. You can get a feel for what predict
does with the -nooffset- option by running -predict- on your data
with and without it and observing the difference in the
predictions.

I ran a nonsense example using the auto data. I do not show
the output for the sake of brevity.

use auto
xi : poisson mpg weight i.rep , offset(trunk)

adjust weight , by(rep) /* <--- gives error */
adjust weight , by(rep) nooffset

predict double z1
predict double z2 , nooffset
list z1 z2

z1 and z2 are different, and so would be the results from -adjust-.

When I say

adjust somevar , by(catvar)

Stata preserves your data, sets up a dataset with "somevar"
replaced by its mean and does the prediction for each group
defined by "catvar". What should -adjust- do with the offset (or
exposure) that has different values within each group?

The decision was made that -adjust- would complain and put the
burden back on the user to figure out how they would like to
collapse (see -help collapse-) such data before producing
predictions for each group.


Ken Higbee khigbee@s...
StataCorp 1-800-STATAPC


On Sat, 09 Nov 2002 16:06:19 -0000 tj_wade <[email protected]> wrote:

> --- In statalist@y..., khigbee@s... wrote:
> Timothy J. Wade  asks:
> 
> > I'm trying to obtain adjusted rates by month
> after the following  
> poisson 
> > regression:
> > 
> >   xi: poisson count i.monthnum cycle, 
> exposure(pyear)
> > 
> > when I type: . adjust cycle, by(monthnum) 
> exp
> > 
> > I get the following error:
> > offset (ln(pyear)) not constant within by()
> > 
> > however, when I use type the same adjust
> command with 
> the "nooffset" 
> > option. I get returned results that look
> approximately correct 
> (see below).
> > 
> > My questions are: are the rates given after
> adjust with the 
> nooffset option 
> > the correct adjusted rates? Also, why do I
> need to specify the 
> nooffset 
> > option in adjust?
> > Thanks very much in advance!
> > 
> > (stata 7.0/Windows)
> > 
> > . adjust cycle, by(month)  exp nooffset
> > ----------------------
> >   monthnum |    exp(xb)
> > ----------+-----------
> >          1 |    2.38068
> >          2 |    2.67684
> >          3 |    2.18642
> >          4 |    2.20107
> >          5 |    2.09517
> >          6 |    1.70584
> >          7 |    2.01013
> >          8 |    1.86005
> >          9 |    1.64766
> >         10 |    1.68153
> >         11 |    2.37351
> >         12 |    2.15014
> > ----------------------
> >       Key:  exp(xb)  =  exp(xb)
> 
> 
> See the entry for 14oct2002 in -help whatsnew-.
>  The -adjust-
> command used to arbitrarily take one of the
> offsets within each
> group defined by the by() option and use it in
> the prediction.
> This is arbitrary, and hence no longer allowed.
>  Instead, it
> checks that offsets (or exposures) were not
> specified, and if
> they were it checks to see if they are constant
> within the by()
> groups.
> 
> The answers with and without the -nooffset-
> option will be
> different.  The -adjust- command is really just
> a convienent
> front-end for -predict-.  You can get a feel
> for what predict
> does with the -nooffset- option by running
> -predict- on your data
> with and without it and observing the
> difference in the
> predictions.
> 
> I ran a nonsense example using the auto data. 
> I do not show
> the output for the sake of brevity.
> 
>     use auto
>     xi : poisson mpg weight i.rep ,
> offset(trunk)
> 
>     adjust weight , by(rep)              /* 


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