Announcement

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

  • Create a table comparing output from diffrent regression models

    Hello All,

    A frequent problem I have in Stata is that I have to run different regression models (for example an unadjusted model, one adjusted for just age and sex, and one adjusted for age, sex, and other parameters). I am looking for a rapid way to put the output of these models into one table for easy comparison and to be able to send it to others. Currently I do a lot of copy and pasting.

    For example, take the following where I want to compare 3 models.

    Code:
    sysuse auto
    quietly regress mpg weight
    estimates store r_unadjusted
    quietly regress mpg weight displ
    estimates store r_adjust1
    quietly regress mpg weight displ foreign
    estimates store r_adjust2
    I could do:
    Code:
     estimates table _all, keep(weight) se p
    Which would give a simple way to see how the variable weight compares in all 3 models and gives me the standard error and p-value.

    And I suppose in many situtions this would be fine, but what I am looking for is a way (if one exists) to include the confidence intervals in such a table that would make it easily shareable with my collaborators so I could show them the outputs of the various models without me having to copy and past each output into a word file.

    For example something that would like this:
    Coefficient lower limit 95% CI upper limit 95% CI p-value
    Model 1
    unadjusted
    Model 2
    adjusted for age/sex
    Model 3
    adjusted for everything
    and the kitchen sink
    I have been tinkering around with this and trying to see if could save estimates and parameters from the various outputs in order to make such a table but ended up taking more time than simply copy and pasting.

    If there is an easier solution to this problem, I would be greatly appreciative of any help.

    Using Stata version 13 for Mac.

    Sincerely,

    Christopher Labos

  • #2
    Code:
    ssc install estout
    Code:
    sysuse auto
    eststo clear
    eststo: quietly regress mpg weight
    eststo: quietly regress mpg weight displ
    eststo: quietly regress mpg weight displ foreign
    esttab, cells(b(fmt(3)) ci(fmt(3) par) p(fmt(3) par)) gaps lines ///
    collabels(none) nonumbers mtitles("Model 1" "Model 2" "Model 3") ///
    keep(weight) addnotes("95% confidence intervals in brackets; p-values in parentheses.")
    Res.:

    Code:
    . esttab, cells(b(fmt(3)) ci(fmt(3) par) p(fmt(3) par)) gaps lines ///
    > collabels(none) nonumbers mtitles("Model 1" "Model 2" "Model 3") ///
    > keep(weight) addnotes("95% confidence intervals in brackets; p-values in parentheses.") 
    
    ---------------------------------------------------
                      Model 1      Model 2      Model 3
    ---------------------------------------------------
    weight             -0.006       -0.007       -0.007
                 [-0.007,-0.005] [-0.009,-0.004] [-0.009,-0.004]
                      (0.000)      (0.000)      (0.000)
    ---------------------------------------------------
    N                      74           74           74
    ---------------------------------------------------
    95% confidence intervals in brackets; p-values in parentheses.
    Last edited by Andrew Musau; 23 Aug 2020, 15:52.

    Comment


    • #3
      Sweet !! Thank you Andrew.

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        Code:
        ssc install estout
        Code:
        sysuse auto
        eststo clear
        eststo: quietly regress mpg weight
        eststo: quietly regress mpg weight displ
        eststo: quietly regress mpg weight displ foreign
        esttab, cells(b(fmt(3)) ci(fmt(3) par) p(fmt(3) par)) gaps lines ///
        collabels(none) nonumbers mtitles("Model 1" "Model 2" "Model 3") ///
        keep(weight) addnotes("95% confidence intervals in brackets; p-values in parentheses.")
        Res.:

        Code:
        . esttab, cells(b(fmt(3)) ci(fmt(3) par) p(fmt(3) par)) gaps lines ///
        > collabels(none) nonumbers mtitles("Model 1" "Model 2" "Model 3") ///
        > keep(weight) addnotes("95% confidence intervals in brackets; p-values in parentheses.")
        
        ---------------------------------------------------
        Model 1 Model 2 Model 3
        ---------------------------------------------------
        weight -0.006 -0.007 -0.007
        [-0.007,-0.005] [-0.009,-0.004] [-0.009,-0.004]
        (0.000) (0.000) (0.000)
        ---------------------------------------------------
        N 74 74 74
        ---------------------------------------------------
        95% confidence intervals in brackets; p-values in parentheses.
        Andrew, how to add another column to this table which shows the difference in the regression coefficients from say Model 1 & Model 2?
        Thanks in advance!

        Regards,
        Abhishek M.

        Comment


        • #5
          You would usually use suest to test cross-model hypotheses and erepost from SSC to replace the coefficients' matrix. For generally adding a column with custom statistics, see e.g., https://www.statalist.org/forums/for...rs-with-esttab.

          Code:
          sysuse auto, clear
          eststo clear
          eststo m1: quietly regress mpg weight
          eststo m2: quietly regress mpg weight displ
          eststo m3: quietly regress mpg weight displ foreign
          suest m1 m2 m3
          margins, expression(_b[m1_mean: weight] - _b[m2_mean: weight]) post
          mat b= e(b)
          mat colname b= "weight"
          erepost b=b, rename
          est sto m4
          esttab m*, cells(b(fmt(3)) ci(fmt(3) par) p(fmt(3) par)) gaps lines modelwidth(20) ///
          collabels(none) nonumbers mtitles("Model 1" "Model 2" "Model 3" "Difference 1 & 2") ///
          keep(weight) drop(:) addnotes("95% confidence intervals in brackets; p-values in parentheses.")
          Res.:

          Code:
          . esttab m*, cells(b(fmt(3)) ci(fmt(3) par) p(fmt(3) par)) gaps lines modelwidth(20) ///
          > collabels(none) nonumbers mtitles("Model 1" "Model 2" "Model 3" "Difference 1 & 2") ///
          > keep(weight) drop(:) addnotes("95% confidence intervals in brackets; p-values in parentheses.")
          
          ------------------------------------------------------------------------------------------------
                                    Model 1              Model 2              Model 3     Difference 1 & 2
          ------------------------------------------------------------------------------------------------
          weight                     -0.006               -0.007               -0.007                0.001
                            [-0.007,-0.005]      [-0.009,-0.004]      [-0.009,-0.004]       [-0.001,0.002]
                                    (0.000)              (0.000)              (0.000)              (0.473)
          ------------------------------------------------------------------------------------------------
          N                              74                   74                   74                   74
          ------------------------------------------------------------------------------------------------
          95% confidence intervals in brackets; p-values in parentheses.

          Comment

          Working...
          X