Announcement

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

  • Stata stir command with pweights

    Code:
    webuse stan3
    stset
    stptime
    stptime, by(surgery)
    stir surgery
    My objective is to estimate incidence rate ratios for surgery vs non surgery but in a setting when I have individual-level sample weights to weight up to a population of interest. How can I estimate the incidence rate ratios while incorporating these sample weights?

  • #2
    Specify weights when you declare data to be survival-time data,
    Code:
    stset timevar [pw=weight] ,id(idvar) failure(failvar)

    Comment


    • #3
      Originally posted by Øyvind Snilsberg View Post
      Specify weights when you declare data to be survival-time data,
      Code:
      stset timevar [pw=weight] ,id(idvar) failure(failvar)
      Thank you very much But when I try this I get an error:: stir does not allow pweights
      Code:
      set seed 98034
      generate WEIGHT = trunc(runiform()*1000)
      stset stime[pweight = WEIGHT], id
      stptime
      stptime, by(surgery)
      stir surgery
      ]

      Comment


      • #4
        Leon, you should know by now our policy on cross-posting as mentioned in the FAQ. This question is cross-posted to Stack Exchange.

        It's not something I do, but you can either use -stcox- to work with hazards and their ratios (additionally, I suppose the you can use the baseline hazards and time information to get incidence rates but that's going to require you to do the math). I believe this was the suggestion you received from Stack Exchange.

        Alternatively, I think the manual for -stcox- has an example of using Poisson regression as a way to approximate a Cox regression model (and under some conditions will be identical). That might be a way to get reasonable incidence rates, using -margins- after -poisson-, for example.

        Comment


        • #5
          Originally posted by Leonardo Guizzetti View Post
          Leon, you should know by now our policy on cross-posting as mentioned in the FAQ. This question is cross-posted to Stack Exchange.

          It's not something I do, but you can either use -stcox- to work with hazards and their ratios (additionally, I suppose the you can use the baseline hazards and time information to get incidence rates but that's going to require you to do the math). I believe this was the suggestion you received from Stack Exchange.

          Alternatively, I think the manual for -stcox- has an example of using Poisson regression as a way to approximate a Cox regression model (and under some conditions will be identical). That might be a way to get reasonable incidence rates, using -margins- after -poisson-, for example.
          Leonardo Guizzetti Thank you but what about for the incidence rate ratios? I can calculate the WEIGHTED incidence rates using the stcox command with stset and I can get the incidence rate ratio by division but what about the confidence interval for the incidence rate ratio?

          Comment


          • #6
            They can be read directly as the exponentiated coefficient from Poisson regression (e.g., -poisson ..., ... irr-) and similarly for the hazard ratio after stcox. In either case, you need a variable for surgery indicating yes(=1) or no (=0).

            Comment


            • #7
              Originally posted by Leonardo Guizzetti View Post
              They can be read directly as the exponentiated coefficient from Poisson regression (e.g., -poisson ..., ... irr-) and similarly for the hazard ratio after stcox. In either case, you need a variable for surgery indicating yes(=1) or no (=0).
              Leonardo Guizzetti Is it possible by any chance that you can provide sample syntax for this? To get weighted incidence rate ratios with confidence intervals?

              Comment


              • #8
                I am out of the office for the next week but will revisit this when I return.

                Comment


                • #9
                  Just writing this from the top of my head and not tested, so errors may be present, and you will need to substitute in your own variable names.

                  Code:
                  * 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

                  Comment


                  • #10
                    Here's an example using an example dataset from the -stcox- manual, example #9.

                    Code:
                    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)
                    The -predict(ir)- option to -margins- is needed to request incidence rates. These calls to -margin- will generate incidence rates in each drug group. The incidence rate ratio (here about 0.2) and 95% CI is taken directly from the coefficient for -1.drug-. The incorporation of -pweights- in the survival date is not needed since we already know -stir- can't use them, but added to show how it would work in general. Finally, the pweights are generated to yield very similar results to the unweighted case to show that they are similar.

                    Selected results:

                    Code:
                    . 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

                    Working...
                    X