Announcement

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

  • postestimation in glm

    Hi Statalisters,

    I am fitting a glm model with this form:

    glm PS101 Yb wall urb, family(poisson) link(log) lnoffset(Meancount)

    I am trying to generate the predicted value "manually" (pred2 below) so I can use it in a simulation where I am going to vary my betas and the value of my offset. However I am getting a predicted value that is not equal to mu (i.e., predict pred1, mu).

    Here is an example of my codes: global xvars "Yb wall urb"
    glm PS101 Yb wall urb, family(poisson) link(log) lnoffset(Meancount)
    global px=e(df_m)
    matrix beta=e(b)'
    predict pred1, mu

    global px1=$px+1
    gen pred2=0
    forvalues i=1/$px {
    local v : word `i' of $xvars
    replace pred2=pred2 + Meancount* exp(beta[$px1,1]+ beta[`i',1]*`v')
    }
    If anyone could point out what is wrong with my pred2 formula or could provide a resource on the formula behind the GLM post estimation calculation for mu when you have Poisson distribution and there is an offset that would be really great!

    Thanks in advance!
    -Maris

  • #2
    The offset should be within the exponential function.

    For example:

    Code:
    webuse rod93,clear
    generate logexp=ln(exposure)
    qui glm  deaths cohort, offset(logexp) family(poisson) link(log)
    predict mu,mu
    gen my_mu= exp( [deaths]_b[cohort]*cohort + [deaths]_b[_cons] + logexp)
    l in 1/2

    Comment


    • #3
      As a sidelight, while the lnoffset option still works, it has been replaced by exposure. So Scott's code could be rewritten as

      Code:
      webuse rod93,clear
      qui glm  deaths cohort, exposure(exposure) family(poisson) link(log)
      predict mu,mu
      gen my_mu= exp( [deaths]_b[cohort]*cohort + [deaths]_b[_cons] + ln(exposure))
      l in 1/2
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Thanks for your help! Really appreciate it.

        Comment

        Working...
        X