Announcement

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

  • Alternatives for -tab- on imputed data

    Dear Statalist,

    When I do Cox regression on regular data using a categorical dependent variable, I run the command
    Code:
    tab depvar if e(sample)
    after -stcox- to assess the number of individuals within each category. -tab- is not possible to use on multiple imputed data, as far as I know. Does anyone know of a code or syntax that could do the same on mi data?

    Best regards,
    Sigrid

  • #2
    You may try something like:

    Code:
    . webuse mheart5
    (Fictional heart attack data)
    
    .  mi set mlong
    
    . mi register imputed age bmi
    (28 m=0 obs. now marked as incomplete)
    
    . set seed 1234
    
    . mi impute mvn age bmi = attack smokes hsgrad female, add(5)
    
    Performing EM optimization:
    note: 12 observations omitted from EM estimation because of all imputation variables missing
      observed log likelihood = -651.75868 at iteration 7
    
    Performing MCMC data augmentation ... 
    
    Multivariate imputation                     Imputations =        5
    Multivariate normal regression                    added =        5
    Imputed: m=1 through m=5                        updated =        0
    
    Prior: uniform                               Iterations =      500
                                                    burn-in =      100
                                                    between =      100
    
    ------------------------------------------------------------------
                       |               Observations per m             
                       |----------------------------------------------
              Variable |   Complete   Incomplete   Imputed |     Total
    -------------------+-----------------------------------+----------
                   age |        142           12        12 |       154
                   bmi |        126           28        28 |       154
    ------------------------------------------------------------------
    (complete + incomplete = total; imputed is the minimum across m
     of the number of filled-in observations.)
    
    . mi xeq: tabulate attack
    
    m=0 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    
    m=1 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    
    m=2 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    
    m=3 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    
    m=4 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    
    m=5 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    
    . */ only the fifth dataset
    
    . mi xeq 5: tabulate attack
    
    m=5 data:
    -> tabulate attack
    
        Outcome |
         (heart |
        attack) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |         85       55.19       55.19
              1 |         69       44.81      100.00
    ------------+-----------------------------------
          Total |        154      100.00
    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Below, a more realistic example, after generating missing values for the binary variable "attack":

      Code:
      . webuse mheart5
      (Fictional heart attack data)
      
      . */ create missing data for the binary variable attack
      
      . replace attack = . in 1/10
      (10 real changes made, 10 to missing)
      
      . */ check the tabulation
      
      . tab attack, missing
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         78       50.65       50.65
                1 |         66       42.86       93.51
                . |         10        6.49      100.00
      ------------+-----------------------------------
            Total |        154      100.00
      
      . */ now, the multiple imputation
      
      .  mi set mlong
      
      . mi register imputed age bmi attack
      (37 m=0 obs. now marked as incomplete)
      
      . mi impute chained (regress) bmi age (logit) attack = smokes hsgrad female, add(5)
      
      Conditional models:
                  attack: logit attack age bmi smokes hsgrad female
                     age: regress age i.attack bmi smokes hsgrad female
                     bmi: regress bmi i.attack age smokes hsgrad female
      
      Performing chained iterations ...
      
      Multivariate imputation                     Imputations =        5
      Chained equations                                 added =        5
      Imputed: m=1 through m=5                        updated =        0
      
      Initialization: monotone                     Iterations =       50
                                                      burn-in =       10
      
                     bmi: linear regression
                     age: linear regression
                  attack: logistic regression
      
      ------------------------------------------------------------------
                         |               Observations per m            
                         |----------------------------------------------
                Variable |   Complete   Incomplete   Imputed |     Total
      -------------------+-----------------------------------+----------
                     bmi |        126           28        28 |       154
                     age |        142           12        12 |       154
                  attack |        144           10        10 |       154
      ------------------------------------------------------------------
      (complete + incomplete = total; imputed is the minimum across m
       of the number of filled-in observations.)
      
      . */ now, tabulations for the variable attack
      
      . mi xeq: tabulate attack
      
      m=0 data:
      -> tabulate attack
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         78       54.17       54.17
                1 |         66       45.83      100.00
      ------------+-----------------------------------
            Total |        144      100.00
      
      m=1 data:
      -> tabulate attack
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         85       55.19       55.19
                1 |         69       44.81      100.00
      ------------+-----------------------------------
            Total |        154      100.00
      
      m=2 data:
      -> tabulate attack
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         85       55.19       55.19
                1 |         69       44.81      100.00
      ------------+-----------------------------------
            Total |        154      100.00
      
      m=3 data:
      -> tabulate attack
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         81       52.60       52.60
                1 |         73       47.40      100.00
      ------------+-----------------------------------
            Total |        154      100.00
      
      m=4 data:
      -> tabulate attack
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         84       54.55       54.55
                1 |         70       45.45      100.00
      ------------+-----------------------------------
            Total |        154      100.00
      
      m=5 data:
      -> tabulate attack
      
          Outcome |
           (heart |
          attack) |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         82       53.25       53.25
                1 |         72       46.75      100.00
      ------------+-----------------------------------
            Total |        154      100.00
      You can see that only the "original" data set shall present missing values for "atttack".

      Hopefully that helps.
      Best regards,

      Marcos

      Comment


      • #4
        Thank you Marcos, this was really helpful!

        Comment

        Working...
        X