Announcement

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

  • Etable from large number of models

    I have fourty predictors (x1 ... 40), each to anlayse in univariate regressions and would like to report the results in a compact table like this (ultimately I would also like to report margins for binary variables):
    y CI
    x1 -0.1 [-0.1 -0.0]
    x2 0.1 [-0.7 1.0]
    x3 0.4 [-0.4 1.2]
    x4 -0.9 [-2.1 0.3]
    Number of observations 147 147
    The progress so far yields an enormous table with a lot of white space (here shown only for predictors x1 to x4).

    I've toyed with importing from Excel and reshaping in Stata (with limited success), but wonder if there is a better way?

    Thankyou!


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(x1 x2 x3 x4 y)
    32 0 0 0 22
    16 0 1 0 20
    18 0 0 0 23
    25 0 1 0 21
    31 0 1 1 20
    29 0 1 0 23
    30 0 0 0 20
    29 0 0 0 22
    22 0 1 0 23
    18 0 1 0 23
    29 0 0 0 20
    40 0 1 1 20
    19 0 1 0 21
    27 1 1 1 23
    34 0 1 1 23
    28 0 1 0 22
    18 0 1 0 20
    40 0 1 0 20
    30 1 0 0 20
    16 1 1 0 22
    29 1 0 0 23
    27 0 0 0 21
    21 0 0 1 20
    25 0 1 1 21
    32 0 1 0 20
    31 1 0 0 20
    41 1 0 0 20
    22 0 1 0 22
    27 0 0 0 22
    34 0 0 0 23
    29 0 0 0 24
    21 0 0 1 23
    24 0 0 0 21
    27 0 1 0 21
    29 0 0 0 20
    33 1 0 0 23
    38 0 1 0 23
    22 1 1 0 21
    34 1 1 0 22
    24 0 1 0 20
    22 0 0 0 23
    25 0 0 1 23
    27 0 1 1 21
    36 0 0 0 21
    39 0 0 0 21
    40 0 0 0 21
    25 1 0 0 22
    24 0 0 0 23
    35 0 0 0 20
    34 0 0 0 20
    24 0 0 0 20
    25 0 0 0 22
    38 1 0 0 20
    36 0 1 1 21
    26 0 0 0 20
    31 1 0 0 20
    28 1 0 0 22
    42 0 0 1 23
    37 0 0 1 21
    22 1 0 0 21
    24 0 0 0 23
    21 0 1 0 21
    20 0 1 0 21
    38 0 1 0 20
    24 0 0 0 23
    24 0 1 0 27
    38 1 1 0 27
    17 0 0 0 27
    24 0 1 0 28
    22 0 0 0 27
    28 0 1 0 27
    27 0 0 0 26
    29 1 0 0 25
    21 1 1 0 26
    25 1 0 0 26
    21 0 1 0 29
    34 1 1 0 23
    16 1 0 0 20
    33 0 0 0 21
    29 0 1 0 21
    39 0 0 0 21
    39 0 0 0 22
    34 0 1 0 21
    29 0 1 0 22
    25 0 0 0 23
    22 1 0 0 21
    22 1 0 0 21
    27 1 0 0 20
    21 0 0 0 23
    22 0 1 0 23
    23 0 0 1 21
    27 1 1 0 21
    27 0 0 0 23
    32 0 0 1 21
    37 1 1 0 29
    21 1 0 0 21
    17 1 0 0 27
    21 0 0 0 20
    40 0 0 0 20
    21 1 0 0 23
    end

    foreach var of varlist x1 x2 x3 x4 {
    qui reg y `var'
    estimates store m`var'
    }

    etable, replace estimates(m*) cstat(_r_b, nformat(%6.1f)) cstat(_r_ci, cidelimiter(" to") nformat(%6.1f))











  • #2
    You are almost there. You just need to use some collect commands to change header styles for the results of interest and change the layout.
    Code:
    * show header labels for coefficients and CI
    collect style header result[_r_b _r_ci], level(label)
    * change layout
    collect layout (colname) (result[_r_b _r_ci]#stars[value])
    Here is the resulting table.
    Code:
    ------------------------------
       Coefficient      95% CI    
    ------------------------------
    x1        -0.1 [-0.1 to   0.0]
    x2         0.5 [-0.5 to   1.4]
    x3         0.6 [-0.3 to   1.5]
    x4        -0.7 [-2.0 to   0.5]
    ------------------------------
    In your example there are no missing values in any of the x variables, so all the estimation results use the same observations. In this case you could arrange it so the common sample size shows up at the end with the following code.
    Code:
    collect addtag sample[N] , fortags(cmdset[1]#result[N])
    collect composite define bN = _r_b N
    collect label levels result bN "y"
    collect layout (colname sample) (result[bN _r_ci]#stars[value])
    Here is the resulting table.
    Code:
    -----------------------
         y       95% CI    
    -----------------------
    x1 -0.1 [-0.1 to   0.0]
    x2  0.5 [-0.5 to   1.4]
    x3  0.6 [-0.3 to   1.5]
    x4 -0.7 [-2.0 to   0.5]
    N   100                
    -----------------------

    Comment


    • #3
      So elegant! Thankyou Jeff for showing me that.

      Janine

      Comment

      Working...
      X