Announcement

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

  • is it possible to calculate confidence intervals in the ir command?

    I am attemtping to calculate cumulative incidence using the "ir" command and I would like to report the incidence of the exposed and unexposed together with confidence intervals but stata output provides only the estimate as illustrated below (the outputs in bold). How do I go about it? My data structure is also illustrated below.
    treatment
    Exposed Unexposed Total
    depression 120 164 284
    timepoint 21651 74922 96573
    Incidence rate .0055425 .0021889 .0029408
    Point estimate [95% Conf. Interval]
    Inc. rate diff. .0033535 .0023068 .0044002
    Inc. rate ratio 2.53203 1.983938 3.223855 (exact)
    Attr. frac. ex. .6050599 .495952 .6898123 (exact)
    Attr. frac. pop .2556591
    (midp) Pr(k>=120) = 0.0000 (exact)
    (midp) 2*Pr(k>=120) = 0.0000 (exact)
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str8 id float(depression timepoint treatment)
    "C014F105"  0 38 0
    "C010F077"  0 33 0
    "C007F051"  0 40 1
    "C006F045"  0 37 1
    "C008F059"  0 36 0
    "C007F052"  0 46 1
    "C008F061"  0 38 0
    "C006F046"  0 39 1
    "C014F109"  0 41 0
    "C014F112"  0 40 0
    "C004F028"  0 35 1
    "C013F101"  0 39 0
    "C001F003"  0 38 1
    "C014F105"  0 43 0
    "C007F053"  0 39 1
    "C010F074"  0 45 1
    "C009F066"  0 40 1
    "C001F005"  0 33 1
    "C005F036"  0 35 0
    "C016F123"  0 33 0
    "C002F010"  0 34 1
    "C001F007"  0 36 1
    "C009F068"  0 44 1
    "C003F018"  0 40 1
    "C010F073"  1 43 1
    "C010F075"  0 36 0
    "C014F105"  0 42 0
    "C006F047"  0 33 0
    "C008F057"  0 36 0
    "C008F063"  0 35 0
    "C002F011"  0 42 1
    "C006F043"  0 39 1
    "C010F075"  0 43 1
    "C004F027"  0 33 0
    "C015F119"  0 40 0
    "C011F081"  0 34 0
    "C006F048"  0 39 1
    "C002F015"  0 35 1
    "C007F053"  0 41 1
    "C008F063"  0 42 1
    "C010F073"  0 41 1
    "C007F049"  0 42 1
    "C006F041"  0 33 0
    "C009F065"  0 39 0
    "C014F109"  0 43 0
    "C015F116"  0 34 0
    "C001F004"  2 38 1
    "C008F061"  0 34 0
    "C009F066"  0 45 1
    "C015F115"  0 38 0
    "C005F034"  0 33 0
    "C002F011"  0 35 1
    "C004F027"  0 40 1
    "C010F077"  0 38 0
    "C015F114"  0 35 0
    "C014F111"  0 41 0
    "C007F053"  0 37 0
    "C007F049"  0 38 1
    "C004F029"  0 37 1
    "C003F020"  0 33 0
    "C010F077"  0 33 0
    "C003F022"  0 36 1
    "C003F023"  0 36 1
    "C006F042"  0 48 1
    "C013F101"  0 37 0
    "C002F016"  2 40 1
    "C004F029"  1 35 1
    "C007F056"  0 36 0
    "C016F129"  0 40 0
    "C010F077"  0 37 0
    "C014F112"  0 38 0
    "C001F005" 22 36 1
    "C004F029"  0 38 1
    "C009F068"  0 39 0
    "C005F040"  1 38 1
    "C016F122"  0 42 0
    "C004F027"  0 39 1
    "C015F119"  0 39 0
    "C016F124"  0 36 0
    "C010F074"  0 36 0
    "C009F072"  0 40 1
    "C007F053"  0 36 0
    "C015F115"  0 42 0
    "C012F094"  0 40 0
    "C008F061"  1 44 1
    "C004F027"  4 37 1
    "C016F123"  0 42 0
    "C010F075"  0 44 1
    "C010F076"  0 41 1
    "C005F036"  0 34 0
    "C010F078"  0 44 1
    "C013F104"  0 39 0
    "C001F007"  0 38 1
    "C007F054"  0 35 0
    "C005F039"  0 38 1
    "C002F009"  0 34 1
    "C014F107"  0 34 0
    "C013F099"  0 40 0
    "C004F032"  0 40 1
    "C010F078"  0 34 0
    end

  • #2
    Code:
    poisson depression i.treatment, exposure(timepoint)
    lincom _cons, eform
    lincom _cons + 1.treatment, eform

    Comment


    • #3
      Many of the IDs have multiple observations. So wouldn't you want to cluster on the IDs? And in that case wouldn't you also want to use elapsed time as the exposure variable?

      Also, I suggest that the OP do some inspection of the dataset: there seems to be at least one duplicate data entry and a handful of anomalous outcome values for what I assume is intended to be an indicator variable.
      Code:
      bysort id (timepoint): generate int eti = cond(_n > 1, timepoint - timepoint[_n-1], timepoint)
      
      // Error trapping, Part 1: duplicate data
      quietly levelsof id if eti == 0, local(ids)
      foreach id of local ids {
          list id-treatment eti if id == "`id'", noobs abbreviate(20)
      }
      
      // Error trapping, Part 2: unexpected values for outcome
      quietly levelsof id if !inlist(depression, 0, 1), local(ids)
      foreach id of local ids {
          list id-treatment if id == "`id'", noobs abbreviate(20)
      }

      Comment


      • #4
        Originally posted by Andrea Discacciati View Post
        Code:
        poisson depression i.treatment, exposure(timepoint)
        lincom _cons, eform
        lincom _cons + 1.treatment, eform
        Exactly what I needed, thank you!!

        Comment


        • #5
          Originally posted by Andrea Discacciati View Post
          Code:
          poisson depression i.treatment, exposure(timepoint)
          lincom _cons, eform
          lincom _cons + 1.treatment, eform
          Sorry about my earlier reply Andrea, this doesnt actually do what I want. This generates a beta coefficient for a regression model. I needed to calculate incidence rate

          Comment


          • #6
            Originally posted by Joseph Coveney View Post
            Many of the IDs have multiple observations. So wouldn't you want to cluster on the IDs? And in that case wouldn't you also want to use elapsed time as the exposure variable?

            Also, I suggest that the OP do some inspection of the dataset: there seems to be at least one duplicate data entry and a handful of anomalous outcome values for what I assume is intended to be an indicator variable.
            Code:
            bysort id (timepoint): generate int eti = cond(_n > 1, timepoint - timepoint[_n-1], timepoint)
            
            // Error trapping, Part 1: duplicate data
            quietly levelsof id if eti == 0, local(ids)
            foreach id of local ids {
            list id-treatment eti if id == "`id'", noobs abbreviate(20)
            }
            
            // Error trapping, Part 2: unexpected values for outcome
            quietly levelsof id if !inlist(depression, 0, 1), local(ids)
            foreach id of local ids {
            list id-treatment if id == "`id'", noobs abbreviate(20)
            }
            Thanks Joseph, yes there are duplicate data because its a repeated measures study. I do intend to do clustered analysis, but for this specific question, I would like to just present results for before and after treatment just to give a snapshot of findings before I proceed with further analysis

            Comment


            • #7
              Originally posted by Mary Atieno View Post

              Sorry about my earlier reply Andrea, this doesnt actually do what I want. This generates a beta coefficient for a regression model. I needed to calculate incidence rate
              The output from the 2 lincom commands is what you asked: the incidence rate of `depresssion` per unit of time in the 2 `treatment` groups.
              (I generated a random treatment variable because in your example data there are 0 events in the treatment=0 group).

              Code:
              . set seed 123
              
              . replace treatment = rbinomial(1, 0.5)
              (50 real changes made)
              
              .
              . ir depression treatment timepoint
              
                               | treatment              |
                               |   Exposed   Unexposed  |      Total
              -----------------+------------------------+------------
                    depression |        31           3  |         34
                     timepoint |      1933        1891  |       3824
              -----------------+------------------------+------------
                               |                        |
                Incidence rate |  .0160372    .0015865  |   .0088912
                               |                        |
                               |      Point estimate    |    [95% Conf. Interval]
                               |------------------------+------------------------
               Inc. rate diff. |         .0144508       |    .0085268    .0203748
               Inc. rate ratio |         10.10881       |    3.153376    51.67503 (exact)
               Attr. frac. ex. |         .9010764       |    .6828796    .9806483 (exact)
               Attr. frac. pop |         .8215697       |
                               +-------------------------------------------------
                                   (midp)   Pr(k>=31) =                    0.0000 (exact)
                                   (midp) 2*Pr(k>=31) =                    0.0000 (exact)
              
              .
              . poisson depression i.treatment, exposure(timepoint)
              
              Iteration 0:   log likelihood = -111.85601  
              Iteration 1:   log likelihood = -111.82008  
              Iteration 2:   log likelihood = -111.82001  
              Iteration 3:   log likelihood = -111.82001  
              
              Poisson regression                              Number of obs     =        100
                                                              LR chi2(1)        =      26.23
                                                              Prob > chi2       =     0.0000
              Log likelihood = -111.82001                     Pseudo R2         =     0.1050
              
              ------------------------------------------------------------------------------
                depression |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
               1.treatment |   2.313408   .6046415     3.83   0.000     1.128332    3.498483
                     _cons |  -6.446249   .5773503   -11.17   0.000    -7.577835   -5.314663
              ln(timepo~t) |          1  (exposure)
              ------------------------------------------------------------------------------
              
              . lincom _cons, eform
              
               ( 1)  [depression]_cons = 0
              
              ------------------------------------------------------------------------------
                depression |     exp(b)   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                       (1) |   .0015865   .0009159   -11.17   0.000     .0005117    .0049189
              ------------------------------------------------------------------------------
              
              . lincom _cons + 1.treatment, eform
              
               ( 1)  [depression]1.treatment + [depression]_cons = 0
              
              ------------------------------------------------------------------------------
                depression |     exp(b)   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                       (1) |   .0160372   .0028804   -23.01   0.000     .0112785     .022804
              ------------------------------------------------------------------------------

              Comment

              Working...
              X