Announcement

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

  • Formatting a table differently in esttab

    I'm trying to export regression output using esttab for a paper in which I would like a table showing just the interaction terms from a given regression on a survey experiment, where the interaction term is an interaction between respondent-level traits and treatment conditions. In order to save space, I'd like to structure the table such that treatment conditions show up as columns while respondent level traits show up as rows. So, for example, where treatment conditions are Treatment 1, Treatment 2, Treatment 3 & Treatment 4 and respondent level traits are age cohorts, it would look as follows:

    For context, I'd like it to look something like this:
    Treatment 1 Treatment 2 Treatment 3 Treatment 4
    18-30 18-30xTreatment1 18-30xTreatment2 18-30xTreatment3 18-30xTreatment4
    31-50 31-50xTreatment1 31-50xTreatment2 31-50xTreatment3 31-50xTreatment4
    51-64 51-64xTreatment1 51-64xTreatment2 51-64xTreatment3 51-64xTreatment4
    65-80 65-80xTreatment1 65-80xTreatment2 65-80xTreatment3 65-80xTreatment4
    80+ 80+xTreatment1 80+xTreatment2 80+xTreatment3 80+xTreatment4
    What's listed here as 18-30xTreatment2 or 80+xTreatment1 etc would be the interaction term coefficient with the standard error in parantheses.

    Is there a way to do this with esttab or another mechanism to extract this data from Stata, short of manually copying it out?


  • #2
    This can be done with the collect suite of commands (new in Stata 17).
    See help for the collect suite in the [Tables] manual.

    Here is an example
    Code:
    webuse cattaneo2
    
    * model
    regress bweight bn.prenatal#bn.mbsmoke, noconstant
    * collect results
    collect get e()
    
    * format and adorn results
    collect style cell result[_r_b _r_se], nformat(%9.2f)
    collect style cell result[_r_se], sformat("(%s)") 
    * hide result from headers
    collect style header result, title(hide) level(hide)
    * center duplicate column headers
    collect style column, dups(center)
    
    * arrange results for the table
    collect layout (prenatal) (mbsmoke#result[_r_b _r_se])
    Here is the resulting table
    Code:
    . collect layout (prenatal) (mbsmoke#result[_r_b _r_se])
    
    Collection: default
          Rows: prenatal
       Columns: mbsmoke#result[_r_b _r_se]
       Table 1: 4 x 4
    
    ------------------------------------
      |    Nonsmoker         Smoker     
    --+---------------------------------
    0 | 2864.60 (85.97) 2547.44 (108.49)
    1 | 3435.79 (10.09) 3154.54  (23.09)
    2 | 3342.91 (25.01) 3189.22  (41.01)
    3 | 3293.21 (55.55) 3063.23  (78.18)
    ------------------------------------
    Use collect export to export the table to MS Word, MS Excel, PDF, HTML, LaTeX, ...

    Comment


    • #3
      Thank you so much! I'll try it tomorrow. :-)

      Comment

      Working...
      X