Announcement

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

  • Customize Stata etable output

    Hello,

    I would like some help with customizing my etable output. Using the following code...

    . use https://www.stata-press.com/data/r18/nhanes2l, clear
    (Second National Health and Nutrition Examination Survey)

    . regress bpsystol age weight i.region

    Source | SS df MS Number of obs = 10,351
    -------------+---------------------------------- F(5, 10345) = 900.55
    Model | 1708779.02 5 341755.804 Prob > F = 0.0000
    Residual | 3925891 10,345 379.496472 R-squared = 0.3033
    -------------+---------------------------------- Adj R-squared = 0.3029
    Total | 5634670.03 10,350 544.412563 Root MSE = 19.481

    ------------------------------------------------------------------------------
    bpsystol | Coefficient Std. err. t P>|t| [95% conf. interval]
    -------------+----------------------------------------------------------------
    age | .6383029 .0111397 57.30 0.000 .6164668 .6601389
    weight | .4069294 .0124796 32.61 0.000 .382467 .4313917
    |
    region |
    MW | -.2397311 .5640029 -0.43 0.671 -1.345286 .8658237
    S | -.6187414 .5604584 -1.10 0.270 -1.717348 .4798654
    W | -.8617777 .570496 -1.51 0.131 -1.98006 .2565047
    |
    _cons | 71.70779 1.107732 64.73 0.000 69.53642 73.87916
    ------------------------------------------------------------------------------

    . etable

    -------------------------------
    bpsystol
    -------------------------------
    Age (years) 0.638
    (0.011)
    Weight (kg) 0.407
    (0.012)
    Region
    MW -0.240
    (0.564)
    S -0.619
    (0.560)
    W -0.862
    (0.570)
    Intercept 71.708
    (1.108)
    Number of observations 10351
    -------------------------------

    But I would actually like my etable so that one column includes the beta coefficient and the second column contains the corresponding SE, like below:
    bpsystol
    BE SE
    Age years 0.638 0.011
    Weight kg 0.407 0.012
    Region
    MW -0.240 0.564
    S -0.619 0.56
    W -0.862 0.57
    Intercept 71.708 1.108
    Thanks!

  • #2
    Use collect to create the wanted table.

    Code:
    use https://www.stata-press.com/data/r18/nhanes2l, clear
    collect clear
    collect create mytable
    collect: regress bpsystol age weight i.region
    collect style row stack , nobinder spacer
    collect style cell result[_r_b _r_se], nformat(%4.3f)
    collect layout (colname[]) (result[_r_b _r_se])
    Res.:

    Code:
    . collect layout (colname[]) (result[_r_b _r_se])
    
    Collection: mytable
          Rows: colname[]
       Columns: result[_r_b _r_se]
       Table 1: 10 x 2
    
    ------------------------------------
                | Coefficient Std. error
    ------------+-----------------------
    Age (years) |       0.638      0.011
    Weight (kg) |       0.407      0.012
                |                       
    Region      |                       
      NE        |       0.000      0.000
      MW        |      -0.240      0.564
      S         |      -0.619      0.560
      W         |      -0.862      0.570
                |                       
    Intercept   |      71.708      1.108
    ------------------------------------

    Comment

    Working...
    X