Using version 15.1
Having trouble estimating 30-day marginal mean rates using margins command with expression
sid = subject identifier
week = panel identifier
drgdays = count outcome
expose2 = days at risk, days of exposure varies considerably from subject to subject and week of panel.
Example data:
Commands and output:
Simple model estimating an overall marginal rate:
. menbreg drgdays , exp(expose2) ///
> || sid:, vce(robust) irr nolog
Mixed-effects nbinomial regression Number of obs = 567
Overdispersion: mean
Group variable: sid Number of groups = 178
Obs per group:
min = 1
avg = 3.2
max = 4
Integration method: mvaghermite Integration pts. = 7
Wald chi2(0) = .
Log pseudolikelihood = -1238.2894 Prob > chi2 = .
(Std. Err. adjusted for 178 clusters in sid)
------------------------------------------------------------------------------
| Robust
drgdays | Inc. Rate Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | .0397512 .0096893 -13.23 0.000 .0246531 .0640958
ln(expose2) | 1 (exposure)
-------------+----------------------------------------------------------------
/lnalpha | .6354762 .1293867 .3818829 .8890696
-------------+----------------------------------------------------------------
sid |
var(_cons)| 6.919573 .9967897 5.217478 9.176942
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
. margins
Predictive margins Number of obs = 567
Model VCE : Robust
Expression : Marginal predicted mean, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 53.45887 18.36544 2.91 0.004 17.46327 89.45447
------------------------------------------------------------------------------
. margins, expression(predict(mu)/expose2)
Predictive margins Number of obs = 567
Model VCE : Robust
Expression : predict(mu)/expose2
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 1.264494 .4344084 2.91 0.004 .4130689 2.115919
------------------------------------------------------------------------------
. margins, expression((predict(mu)/expose2)*30)
Predictive margins Number of obs = 567
Model VCE : Robust
Expression : (predict(mu)/expose2)*30
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 37.93481 13.03225 2.91 0.004 12.39207 63.47756
------------------------------------------------------------------------------
.
If I just calculate a simple 30-day rate:
gen rate30 = (drgdays/expose2)*30
The overall mean is around 6.2
Am I specifying the expression incorrectly? Thanks.
Having trouble estimating 30-day marginal mean rates using margins command with expression
sid = subject identifier
week = panel identifier
drgdays = count outcome
expose2 = days at risk, days of exposure varies considerably from subject to subject and week of panel.
Example data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int sid float(week drgdays expose2) 1 1 0 13 1 4 0 48 1 12 0 49 1 24 0 59 2 1 0 11 2 4 11 11 2 12 58 70 2 24 1 86 3 1 0 10 3 4 3 4 3 12 2 59 3 24 1 90 4 1 7 7 4 4 26 27 4 12 57 57 5 1 0 7 5 4 0 17 5 12 0 42 5 24 0 134 6 1 0 16 end
Commands and output:
Simple model estimating an overall marginal rate:
. menbreg drgdays , exp(expose2) ///
> || sid:, vce(robust) irr nolog
Mixed-effects nbinomial regression Number of obs = 567
Overdispersion: mean
Group variable: sid Number of groups = 178
Obs per group:
min = 1
avg = 3.2
max = 4
Integration method: mvaghermite Integration pts. = 7
Wald chi2(0) = .
Log pseudolikelihood = -1238.2894 Prob > chi2 = .
(Std. Err. adjusted for 178 clusters in sid)
------------------------------------------------------------------------------
| Robust
drgdays | Inc. Rate Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | .0397512 .0096893 -13.23 0.000 .0246531 .0640958
ln(expose2) | 1 (exposure)
-------------+----------------------------------------------------------------
/lnalpha | .6354762 .1293867 .3818829 .8890696
-------------+----------------------------------------------------------------
sid |
var(_cons)| 6.919573 .9967897 5.217478 9.176942
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
. margins
Predictive margins Number of obs = 567
Model VCE : Robust
Expression : Marginal predicted mean, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 53.45887 18.36544 2.91 0.004 17.46327 89.45447
------------------------------------------------------------------------------
. margins, expression(predict(mu)/expose2)
Predictive margins Number of obs = 567
Model VCE : Robust
Expression : predict(mu)/expose2
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 1.264494 .4344084 2.91 0.004 .4130689 2.115919
------------------------------------------------------------------------------
. margins, expression((predict(mu)/expose2)*30)
Predictive margins Number of obs = 567
Model VCE : Robust
Expression : (predict(mu)/expose2)*30
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 37.93481 13.03225 2.91 0.004 12.39207 63.47756
------------------------------------------------------------------------------
.
If I just calculate a simple 30-day rate:
gen rate30 = (drgdays/expose2)*30
The overall mean is around 6.2
Am I specifying the expression incorrectly? Thanks.