Announcement

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

  • collect layout with regression coefficients for continuous independent variables

    Hi,
    I am having issues using -collect- to make a table of regression coefficients especially when an independent variable is continuous.
    Here are three options I have tried but each is unsatisfactory to me, as noted in the comment.

    Code:
    . clear all
    
    . set obs 1000
    Number of observations (_N) was 0, now 1,000.
    
    . gen x=runiformint(0,1)
    
    . label var x "Outcome"
    
    . gen c = runiform()
    
    . lab var c "Continuous"
    
    . gen i = runiformint(1,3)
    
    . label var i "Discrete"
    
    . cap collect drop c1
    
    . collect create c1
    (current collection is c1)
    
    . collect OR=_r_b P=_r_p _r_ci,name(c1) : /// 
    >         logistic x c.c i.i
    
    Logistic regression                                     Number of obs =  1,000
                                                            LR chi2(3)    =   1.43
                                                            Prob > chi2   = 0.6974
    Log likelihood = -692.03768                             Pseudo R2     = 0.0010
    
    ------------------------------------------------------------------------------
               x | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
               c |   1.289403   .2840073     1.15   0.249     .8373382    1.985531
                 |
               i |
              2  |   1.033049   .1635239     0.21   0.837      .757499    1.408834
              3  |   1.042367   .1573393     0.27   0.783     .7754193    1.401214
                 |
           _cons |   .9074241   .1386773    -0.64   0.525     .6725511    1.224321
    ------------------------------------------------------------------------------
    Note: _cons estimates baseline odds.
    
    . est store e
    
    .         
    . collect dims //no dim for c?
    
    Collection dimensions
    Collection: c1
    -----------------------------------------
                       Dimension   No. levels
    -----------------------------------------
    Layout, style, header, label
                          cmdset   1         
                           coleq   1         
                         colname   9         
               colname_remainder   1         
                               i   3         
                   program_class   2         
                          result   46        
                     result_type   3         
                         rowname   1         
    
    Style only
                    border_block   4         
                       cell_type   4         
    -----------------------------------------
    
    . 
    . collect style header, level(label) title(label)
    
    . collect style row  stack ,spacer
    
    . collect style cell result, nformat(%4.2f)
    
    . collect style cell _r_ci, cidelimiter(",") sformat("(%s)")
    
    . //option 1
    . collect layout (c i)(result[OR _r_ci])            // ?? does not show c at all ??
    (dimension c not found)
    
    Collection: c1
          Rows: c i
       Columns: result[OR _r_ci]
       Table 1: 4 x 2
    
    -----------------------------
             | Result    Result  
             |     OR    95% CI  
    ---------+-------------------
    Discrete |                   
      1      |   1.00            
      2      |   1.03 (0.76,1.41)
      3      |   1.04 (0.78,1.40)
    -----------------------------
    
    . 
    . //option 2
    . collect layout (colname)(result[OR _r_ci])        // ?? does not show var label for discrete ??
    
    Collection: c1
          Rows: colname
       Columns: result[OR _r_ci]
       Table 1: 8 x 2
    
    -----------------------------------------------------
                                     | Result    Result  
                                     |     OR    95% CI  
    ---------------------------------+-------------------
    Covariate names and column names |                   
      Continuous                     |   1.29 (0.84,1.99)
                                     |                   
      Discrete=1                     |   1.00            
      Discrete=2                     |   1.03 (0.76,1.41)
      Discrete=3                     |   1.04 (0.78,1.40)
                                     |                   
      Intercept                      |   0.91 (0.67,1.22)
    -----------------------------------------------------
    
    . 
    . //option 3                      ?? cannot get CI next to OR instead of below??
    . etable , estimates(e) cstat(_r_b, label("OR") nformat("%03.2f")) cstat(_r_ci, label("95%CI
    > ") cidelimiter(",") sformat("(%s)") nformat("%03.2f")) 
    
    ----------------------------------
                                x     
    ----------------------------------
    Continuous                    1.29
                           (0.84,1.99)
    Discrete                          
      2                           1.03
                           (0.76,1.41)
      3                           1.04
                           (0.78,1.40)
    Intercept                     0.91
                           (0.67,1.22)
    Number of observations        1000
    ----------------------------------
    I also could not get the desired table with the Tables Builder.
    It would look like,
    Code:
    -----------------------------
             | Result    Result  
             |     OR    95% CI  
    ---------+-------------------
    Continuous | 1.29 (0.84, 1.99)
    
    Discrete |                   
      1      |   1.00            
      2      |   1.03 (0.76,1.41)
      3      |   1.04 (0.78,1.40)
    -----------------------

    Thanks,
    Scott

  • #2
    OK here's a solution I found
    Code:
    collect set c1
    collect style header colname, level(label) title(hide)
    
    collect layout (colname[c] i) (result[OR] result[_r_ci]) (), name(c1)
    Not especially intuitive to me that continuous variables require colname but factors do not, but ... it seems to work.

    Comment


    • #3
      Factor variables found in colname are added to tags on the
      collected items to help with alternative layouts, but are not necessary
      for the intended/requested table.

      All model coefficients exist as levels in dimension colname.

      Here is a rework of the above example:
      Code:
      clear all
      set obs 1000
      gen x=runiformint(0,1)
      label var x "Outcome"
      gen c = runiform()
      lab var c "Continuous"
      gen i = runiformint(1,3)
      label var i "Discrete"
      
      collect create c1
      collect : logistic x c i.i
      
      * coefficient names are stored in dimension -colname-
      collect dims
      collect levelsof colname
      
      * target cell styles to the results of interest
      collect style cell result[_r_b _r_ci], nformat(%4.2f)
      collect style cell result[_r_ci], cidelimiter(",") sformat("(%s)")
      
      * turn off factor variables binder so that the row headers can stack
      * their levels
      collect style row stack , nobinder spacer
      
      * show result's label in header
      collect style header result, title(label)
      * center repeated column headers
      collect style column, dups(center)
      
      * change the label for the collected odds ratios
      collect label levels result _r_b "OR", modify
      
      * specify the coefficients and results to report in the table
      collect layout (colname[c i]) (result[_r_b _r_ci])
      Here is the resulting table
      Code:
      . collect layout (colname[c i]) (result[_r_b _r_ci])
      
      Collection: c1
            Rows: colname[c i]
         Columns: result[_r_b _r_ci]
         Table 1: 6 x 2
      
      -----------------------------
                 |      Result
                 |   OR    95% CI
      -----------+-----------------
      Continuous | 1.03 (0.66,1.58)
                 |
      Discrete   |
        1        | 1.00
        2        | 0.96 (0.71,1.31)
        3        | 1.00 (0.73,1.35)
      -----------------------------

      Comment


      • #4
        Thanks Jeff.
        Your construction is similar to my Option 2 in using colname as the rows. But I do not see the difference that causes yours to show the variable name "Discrete" and the level labels, where mine showed Discrete=1, Discrete=2, and Discrete=3.
        Which collect statement triggered that?
        Thanks,
        Scott

        Comment


        • #5
          Code:
          * turn off factor variables binder so that the row headers can stack
          * their levels
          collect style row stack , nobinder spacer

          Comment

          Working...
          X