Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to obtain estimates via Margins after a Poisson regression with an offset

    Dear all,

    It may be a silly question, but I was unable to resolve it after some time searching the manuals.

    Here is a quick example to illustrate my question:

    Code:
    *! simulate data for a Poisson model
    clear
    set obs 100
    set seed 123456
    gen x1 = runiform()
    gen xb = 1 + 0.62*x1
    gen exb = exp(xb)
    gen events = rpoisson(exb)
    tab events
    gene total_participants = round(rnormal(100,10))
    gene lntotal = ln(total)
    *! fit the model with an offset -aggregated data
    glm events x1 , family(poisson) offset(lntotal)
    *! predict mean events at two levels of the predictor
    margins, at(x1=(0.25 0.75))
    Margins is correctly predicting the mean number of events per exposure level - for the mean of the offset variable, which is 99.9974 participants.

    Is there a way to specify any number of participants, say, 70 or 120 instead [something like at(total_participants=100)]?

    All the best,

    Tiago

  • #2
    This may be a naive answer, but from help glm we have
    Code:
          exposure(varname)         include ln(varname) in model with coefficient constrained to 1
          offset(varname)           include varname in model with coefficient constrained to 1
    which suggested to me something like what you suggested in your post.
    Code:
    . glm events x1 , family(poisson) offset(lntotal)
    ...
    ------------------------------------------------------------------------------
                 |                 OIM
          events |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              x1 |   .4939772   .1773807     2.78   0.005     .1463175    .8416369
           _cons |  -3.516855   .1103418   -31.87   0.000    -3.733121   -3.300589
         lntotal |          1  (offset)
    ------------------------------------------------------------------------------
    
    . *! predict mean events at two levels of the predictor
    . local lnt = ln(100)
    
    . margins, at(x1=(0.25 0.75) lntotal=`lnt')
    variable lntotal not found in list of covariates
    r(322);
    And I assume this is the path you went down as well. It is unfortunate that the offset (or exposure) variable is "included in the model" but apparently not added to some list of covariates. Perhaps this warrants a question to Stata Technical Services.

    But brute force appears (see note below) to work - I changed the desired value for the offset to ln(50) so the results would be more clearly different - ln(100) isn't that much different from ln(99.9974).
    Code:
    . margins, at(x1=(0.25 0.75))
    
    Adjusted predictions                            Number of obs     =        100
    Model VCE    : OIM
    
    Expression   : Predicted mean events, predict()
    
    1._at        : x1              =         .25
    
    2._at        : x1              =         .75
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |   3.358886   .2481695    13.53   0.000     2.872483    3.845289
              2  |   4.299926   .2659391    16.17   0.000     3.778695    4.821158
    ------------------------------------------------------------------------------
    
    . clonevar lntotal_save = lntotal
    
    . replace lntotal = ln(50)
    (100 real changes made)
    
    . margins, at(x1=(0.25 0.75))
    
    Adjusted predictions                            Number of obs     =        100
    Model VCE    : OIM
    
    Expression   : Predicted mean events, predict()
    
    1._at        : x1              =         .25
    
    2._at        : x1              =         .75
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |   1.679779   .1241096    13.53   0.000     1.436529    1.923029
              2  |   2.150393   .1329962    16.17   0.000     1.889726    2.411061
    ------------------------------------------------------------------------------
    With that said, I don't know if this makes sense methodologically. I'm thinking that the identical z values reflects the fact that there is no variability in the coefficient of lntotal, but maybe I'm in over my head.

    Comment


    • #3
      Dear William,

      Thank you so much for your message. Very helpful and very insightful!

      Cordially,

      Tiago

      Comment

      Working...
      X