Code:
webuse stan3 stset stptime stptime, by(surgery) stir surgery
webuse stan3 stset stptime stptime, by(surgery) stir surgery
stset timevar [pw=weight] ,id(idvar) failure(failvar)
set seed 98034 generate WEIGHT = trunc(runiform()*1000) stset stime[pweight = WEIGHT], id stptime stptime, by(surgery) stir surgery
* The reported IRR is the incidence rate ratio, weighted by your smoking weights, for the surgery group versus non-surgical group. poisson outcome i.surgery [pw=wtvar], irr exposure(timevar) vce(rob) * To check incidence rates in each group: margins i.surgery
clear * cls // example data from [ST] stcox manual, Example 9. Data have already been stset. use https://www.stata-press.com/data/r17/drugtr, clear // incidence rates in drug groups stir drug // using poisson regression to estimate incidence rate and their ratios poisson died i.drug , exposure(studytime) vce(robust) irr nolog margins i.drug, predict(ir) // generate a fake pweight gen wt = 1 + rnormal(0, 0.01) // Start again, adding weights stset, clear stset studytime [pw=wt], failure(died) // note: -stir- won't work with pweights so this step isn't necessary poisson died i.drug [pw=wt], exposure(studytime) vce(robust) irr nolog margins i.drug, predict(ir)
. stir drug Failure _d: died Analysis time _t: studytime Incidence-rate comparison Exposed: drug = 1 Unexposed: drug = 0 | Drug type [0=placebo] | | Exposed Unexposed | Total -----------------+------------------------+----------- Failures | 12 19 | 31 Time | 564 180 | 744 -----------------+------------------------+----------- | | Incidence rate | .0212766 .1055556 | .0416667 | | | Point estimate | [95% conf. interval] |------------------------+------------------------ Inc. rate diff. | -.084279 | -.1332445 -.0353134 Inc. rate ratio | .2015677 | .0892308 .4373619 (exact) Prev. frac. ex. | .7984323 | .5626381 .9107692 (exact) Prev. frac. pop | .6052632 | +------------------------------------------------- . poisson died i.drug , exposure(studytime) vce(robust) irr nolog Poisson regression Number of obs = 48 Wald chi2(1) = 27.59 Prob > chi2 = 0.0000 Log pseudolikelihood = -51.746927 Pseudo R2 = 0.1564 ------------------------------------------------------------------------------ | Robust died | IRR std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- 1.drug | .2015677 .0614619 -5.25 0.000 .1108851 .3664114 _cons | .1055556 .0173419 -13.69 0.000 .0764954 .1456554 ln(studyt~e) | 1 (exposure) ------------------------------------------------------------------------------ . margins i.drug, predict(ir) Adjusted predictions Number of obs = 48 Model VCE: Robust Expression: Predicted incidence rate, predict(ir) ------------------------------------------------------------------------------ | Delta-method | Margin std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- drug | 0 | .1055556 .0173419 6.09 0.000 .071566 .1395451 1 | .0212766 .0054654 3.89 0.000 .0105646 .0319886 ------------------------------------------------------------------------------ . poisson died i.drug [pw=wt], exposure(studytime) vce(robust) irr nolog Poisson regression Number of obs = 48 Wald chi2(1) = 27.59 Log pseudolikelihood = -51.69405 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Robust died | IRR std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- 1.drug | .20152 .0614614 -5.25 0.000 .1108437 .3663744 _cons | .1053375 .0172558 -13.74 0.000 .0764089 .1452185 ln(studyt~e) | 1 (exposure) ------------------------------------------------------------------------------ . margins i.drug, predict(ir) Adjusted predictions Number of obs = 48 Model VCE: Robust Expression: Predicted incidence rate, predict(ir) ------------------------------------------------------------------------------ | Delta-method | Margin std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- drug | 0 | .1053375 .0172558 6.10 0.000 .0715167 .1391582 1 | .0212276 .005461 3.89 0.000 .0105242 .031931 ------------------------------------------------------------------------------
Comment