Announcement

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

  • Stata Collect System: Combining two models into one model prior to making table

    Hello,

    I would like to have a table that includes only one column, but is reporting results from two models. I would think that the following command should work, however, the predictors that are shared between the two regressions do not show in the table:

    Code:
    webuse nhanes2l, clear
    collect clear
                    
    collect _r_b _r_ci, tag(model[combined_results]): regress bpsystol hgb i.race i.rural
    collect _r_b _r_ci, tag(model[combined_results): regress bpsystol hct i.race i.rural
    collect layout (colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result) (model)
    This results in:

    Code:
    . collect layout (colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result) (model)
    
    Collection: default
          Rows: colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result
       Columns: model
       Table 1: 6 x 1
    
    --------------------------------------
                      |   combined_results
    ------------------+-------------------
    Hemoglobin (g/dL) |                   
      Coefficient     |           1.714797
      95% CI          | 1.384949  2.044645
    Hematocrit (%)    |                   
      Coefficient     |           .6554286
      95% CI          | .5325924  .7782647
    --------------------------------------
    Although I understand that I can use the following code with two separate models, one for each regression, however, this would result in a table with two columns:

    Code:
    webuse nhanes2l, clear
    collect clear
                    
    collect _r_b _r_ci, tag(model[model_1]): regress bpsystol hgb i.race i.rural
    collect _r_b _r_ci, tag(model[model_2]): regress bpsystol hct i.race i.rural
    collect layout (colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result) (model)
    Which results in:

    Code:
    . collect layout (colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result) (model)
    
    Collection: default
          Rows: colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result
       Columns: model
       Table 1: 19 x 2
    
    -----------------------------------------------------------
                      |             model_1             model_2
    ------------------+----------------------------------------
    Hemoglobin (g/dL) |                                        
      Coefficient     |            1.714797                    
      95% CI          |  1.384949  2.044645                    
    Hematocrit (%)    |                                        
      Coefficient     |                                .6554286
      95% CI          |                      .5325924  .7782647
    White             |                                        
      Coefficient     |                   0                   0
    Black             |                                        
      Coefficient     |            5.155836            4.643728
      95% CI          |  3.642232  6.669441  3.146876   6.14058
    Other             |                                        
      Coefficient     |            -1.63656           -1.674051
      95% CI          | -4.891694  1.618573 -4.928377  1.580275
    Urban             |                                        
      Coefficient     |                   0                   0
    Rural             |                                        
      Coefficient     |            1.331342            1.325153
      95% CI          |  .3859748  2.276709  .3800328  2.270272
    -----------------------------------------------------------
    I understand that the covariates result in different coefficients and confidence intervals pending on the models, however, with the actual data I am using (I am not using nhanes2l data), the coefficients/CI's are exactly the same in the two models that I want to include in one column.

    How can I make a table that includes the coefficient/CI's for hematocrit in the first table, that contains the results for model 1?

    Thank you in advance!

  • #2
    Hello Nathan,
    maybe you are looking for something like this?

    I am sure you could further format the table.
    I wasn't able to get rid of the labels "model_1" & "model_2"...

    Code:
    webuse nhanes2l, clear
    collect clear
    
    collect get, tag(model[model_1]): regress bpsystol hgb i.race i.rural
    collect get, tag(model[model_2]): regress bpsystol hct i.race i.rural
    
    collect layout (colname[hgb 1.race 2.race 3.race 0.rural 1.rural]#model[model_1]#result[_r_b  _r_ci] colname[hct]#model[model_2]#result[_r_b  _r_ci])
    
    collect style showbase off
    collect style cell, nformat(%5.2f)
    collect style column, extraspace(1)
    collect preview
    Code:
    
    --------------------------------
    Hemoglobin (g/dL) |             
      model_1         |             
        Coefficient   |         1.71
        95% CI        |   1.38  2.04
    Black             |             
      model_1         |             
        Coefficient   |         5.16
        95% CI        |   3.64  6.67
    Other             |             
      model_1         |             
        Coefficient   |        -1.64
        95% CI        |  -4.89  1.62
    Rural             |             
      model_1         |             
        Coefficient   |         1.33
        95% CI        |   0.39  2.28
    Hematocrit (%)    |             
      model_2         |             
        Coefficient   |         0.66
        95% CI        |   0.53  0.78
    --------------------------------

    Comment


    • #3
      Thank you very much Simon, this helps me understand how to frame tables using the Collect system! However, I would need models to be present on the columns still. I plan to eventually combine 6 models into three columns, where only one coefficient/confidence interval from one model is appended to a different model. Is there is a way to add/append just one set of coefficient/confidence interval from one model to the tags associated with a separate model, so that ultimately the resultant table will include estimates from two separate model in the same column?

      Best regards,

      Comment


      • #4
        Hello Nathan,

        I hope I don't get you wrong, "collect remap" might help.

        Code:
        webuse nhanes2l, clear
        collect clear
        
        collect get, tag(model[model_1]): regress bpsystol hgb i.race i.rural
        collect get, tag(model[model_2]): regress bpsystol hct i.race i.rural
        
        collect remap model[model_2]=model[model_1], fortags(colname[hct])
        
        collect layout (colname[hgb hct 1.race 2.race 3.race 0.rural 1.rural]#result[_r_b  _r_ci]) (model[model_1])
        
        collect style showbase off
        collect style cell, nformat(%5.2f)
        collect style column, extraspace(1)
        collect preview
        Code:
        
        --------------------------------
                          |      model_1
        ------------------+-------------
        Hemoglobin (g/dL) |             
          Coefficient     |         1.71
          95% CI          |   1.38  2.04
        Hematocrit (%)    |             
          Coefficient     |         0.66
          95% CI          |   0.53  0.78
        Black             |             
          Coefficient     |         5.16
          95% CI          |   3.64  6.67
        Other             |             
          Coefficient     |        -1.64
          95% CI          |  -4.89  1.62
        Rural             |             
          Coefficient     |         1.33
          95% CI          |   0.39  2.28
        --------------------------------

        Comment


        • #5
          Hi Simon,

          Thank you so much -- this is exactly what I needed!!

          Best regards,
          Last edited by Nathan Yu; 23 Sep 2024, 14:36.

          Comment

          Working...
          X