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