Announcement

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

  • -etable-: How to horizontally "merge" the display for two sets of regression coefficients with a different response variable


    I'd like help to get -etable- to horizontally "merge" the coefficients for two (or more) regression models that have the same set of explanatory variables but which have a different response variable. My example below shows how I *can* produce what I want using the user-written -outreg- package, followed by what I get but don't like using -etable-. I like various features of -etable-, so I'm hoping there might be some option to get -etable- to put the model2 coefficients alongside the model1 coefficients. I can't find something relevant in the documentation about this.

    Code:
    . sysuse auto
    (1978 automobile data)
    . quiet regress price weight headroom
    . est store model1
    
    . outreg
                                                                      ----------------------
                                                                                   price  
                                                                      ----------------------
                                                                       weight      2.393  
                                                                                  (5.63)**
                                                                       headroom   -663.776
                                                                                   (1.70)  
                                                                       _cons      925.394  
                                                                                   (0.72)  
                                                                       R2           0.32  
                                                                       N             74    
                                                                      ----------------------
                                                                       * p<0.05; ** p<0.01
    
    
    . //
    . quiet regress length weight headroom
    . est store model2
    . // Coefficients appended horizontally -- yes.
    . outreg, merge
                                                                ---------------------------------
                                                                             price     length  
                                                                ---------------------------------
                                                                 weight      2.393      0.026  
                                                                            (5.63)**  (21.14)**
                                                                 headroom   -663.776    2.025  
                                                                             (1.70)    (1.79)  
                                                                 _cons      925.394    103.254  
                                                                             (0.72)   (27.78)**
                                                                 R2           0.32      0.90    
                                                                 N             74        74    
                                                                ---------------------------------
                                                                       * p<0.05; ** p<0.01
    
    . //
    . // Coefficients appended vertically -- no.
    . etable, estimates(model1 model2)
    
    -----------------------------------------
                              price    length
    -----------------------------------------
    Weight (lbs.)               2.393        
                              (0.425)        
    Headroom (in.)           -663.776        
                            (390.383)        
    Intercept                 925.394        
                           (1282.380)        
    Weight (lbs.)                       0.026
                                      (0.001)
    Headroom (in.)                      2.025
                                      (1.131)
    Intercept                         103.254
                                      (3.717)
    Number of observations         74      74
    -----------------------------------------
    Last edited by Mike Lacy; 20 Oct 2025, 19:32. Reason: Better title.

  • #2
    The challenge here is that etable uses column equations (dimension coleq) in the layout. With regress results, or any other command that posts results without explicit column equations, etable uses the dependent variable name from macro e(depvar) in place of an "empty" equation. To see the equations, use etable option showeq (with option novarlabel) or replay the layout with collect layout followed by collect label list coleq, all.

    You can change the layout by removing coleq from the row specification in the layout with collect layout or the tables builder following your call to etable. Launch the tables builder from the command window with command
    Code:
    db tables
    More directly, etable has option eqrecode() that allows you to recode the levels of coleq. Here is your example, modified to recode both equations to a common xb.
    Code:
    sysuse auto
    quiet regress price weight headroom
    est store model1
    quiet regress length weight headroom
    est store model2
    etable, estimates(model1 model2) eqrecode(price=xb length=xb)
    Here is the resulting table.
    Code:
    -----------------------------------------
                              price    length
    -----------------------------------------
    Weight (lbs.)               2.393   0.026
                              (0.425) (0.001)
    Headroom (in.)           -663.776   2.025
                            (390.383) (1.131)
    Intercept                 925.394 103.254
                           (1282.380) (3.717)
    Number of observations         74      74
    -----------------------------------------

    Comment


    • #3
      Thanks, that was a very quick and helpful response. I would never have figured out that solution.

      After trying out -eqrecode()-, I went back and searched on it in the documentation, but little was there. Given the complexity of -etable- and the underlying -collect- facility, I appreciate that giving full explanatory detail on everything would be difficult. For what it's worth, my suggestion would be to include more examples in the documentation of ways to use options in -etable-.

      Comment


      • #4
        Thank you Jeff for your helpful solution here. Like Mike, I don't think I could have worked that out. The documentation on the eqrecode option is especially thin.

        I wonder if anyone could help with an extension of the same problem. Here I use a mixed and a melogit command to estimate similar models on a continuous outcome and its binary relation. Should I be able to line up the estimates of variance at the constant (var(_cons) and var(_cons[turn])) in this example? (I understand the difference in the variance estimations between the two model types and would be comfortable explaining that in a footnote: lining up the table would be better for the reader.)

        Code:
        webuse auto
        
        gen hi_mpg = mpg >= 21.3
        
        mixed mpg trunk || turn:,
        est store cont1
        melogit hi_mpg trunk || turn:,
        est store binary2
        As expected the equations do not line up automatically:

        Code:
        etable, estimates(cont1 binary2)
        
        
        --------------------------------------
                                 mpg    hi_mpg
        --------------------------------------
        Trunk space (cu. ft.)   -0.638        
                               (0.135)        
        Intercept               30.052        
                               (1.999)        
        var(_cons)               4.554        
                               (4.309)        
        var(e)                  18.059        
                               (3.617)        
        Trunk space (cu. ft.)           -0.500
                                       (0.155)
        Intercept                        6.174
                                       (2.113)
        var(_cons[turn])                 5.195
                                       (4.997)
        Number of observations      74      74
        --------------------------------------
        Using Jeff's instructions I can solve that, with the exception of the variance at the constant estimates:

        Code:
        etable, estimates(cont1 binary2) showeq eqrecode(mpg=mileage hi_mpg=mileage)
        
        
        ---------------------------------------
                                  mpg    hi_mpg
        ---------------------------------------
        mileage                                
          Trunk space (cu. ft.)  -0.638  -0.500
                                (0.135) (0.155)
          Intercept              30.052   6.174
                                (1.999) (2.113)
        Turn circle (ft.)                      
          var(_cons)              4.554        
                                (4.309)        
        Residual                               
          var(e)                 18.059        
                                (3.617)        
        /                                      
          var(_cons[turn])                5.195
                                        (4.997)
        Number of observations       74      74
        ---------------------------------------
        Is there a way to line up the two? Thank you.

        Comment


        • #5
          The shortest/easiest way to get variance components to line up is to use meglm instead of mixed. meglm with the default family/link (i.e. Guassian/identity) fits the same model as mixed in the above example provided by Kate OHara. In addition, meglm and melogit use the same matrix stripe specification for variance components.

          Here is Kate's example, using meglm
          Code:
          webuse auto
          
          gen hi_mpg = mpg >= 21.3
          
          meglm mpg trunk || turn:,
          est store cont1
          melogit hi_mpg trunk || turn:, est store binary2
          
          etable, estimates(cont1 binary2) eqrecode(mpg=mileage hi_mpg=mileage)
          Here is the resulting table.
          Code:
          --------------------------------------
                                   mpg    hi_mpg
          --------------------------------------
          Trunk space (cu. ft.)   -0.638  -0.500
                                 (0.163) (0.155)
          Intercept               30.052   6.174
                                 (2.366) (2.113)
          var(_cons[turn])         4.554   5.195
                                 (4.309) (4.997)
          var(e.mpg)              18.059
                                 (3.617)
          Number of observations      74      74
          --------------------------------------


          If you prefered to keep using mixed, then you need to use option coeflegend to look at how mixed and melogit stripe their estimates.
          Code:
          melogit, coeflegend
          mixed mpg trunk || turn:,
          est store cont1
          mixed, coeflegend
          The resulting tables are:
          Code:
          . melogit, coeflegend
          
          Mixed-effects logistic regression               Number of obs     =         74
          Group variable: turn                            Number of groups  =         18
          
                                                          Obs per group:
                                                                        min =          1
                                                                        avg =        4.1
                                                                        max =         12
          
          Integration method: mvaghermite                 Integration pts.  =          7
          
                                                          Wald chi2(1)      =      10.34
          Log likelihood = -29.272223                     Prob > chi2       =     0.0013
          ------------------------------------------------------------------------------
                hi_mpg | Coefficient  Legend
          -------------+----------------------------------------------------------------
                 trunk |  -.4996131  _b[trunk]
                 _cons |   6.173901  _b[_cons]
          -------------+----------------------------------------------------------------
          turn         |
             var(_cons)|   5.195282  _b[/var(_cons[turn])]
          ------------------------------------------------------------------------------
          LR test vs. logistic model: chibar2(01) = 8.58        Prob >= chibar2 = 0.0017
          
          . mixed, coeflegend
          
          Mixed-effects ML regression                          Number of obs    =     74
          Group variable: turn                                 Number of groups =     18
                                                               Obs per group:
                                                                            min =      1
                                                                            avg =    4.1
                                                                            max =     12
                                                               Wald chi2(1)     =  22.33
          Log likelihood = -217.92736                          Prob > chi2      = 0.0000
          
          ------------------------------------------------------------------------------
                   mpg | Coefficient  Legend
          -------------+----------------------------------------------------------------
                 trunk |  -.6381491  _b[trunk]
                 _cons |   30.05183  _b[_cons]
          ------------------------------------------------------------------------------
          
          ------------------------------------------------------------------------------
            Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
          -----------------------------+------------------------------------------------
          turn: Identity               |
                            var(_cons) |   4.553746   4.309006      .7127132     29.0953
          -----------------------------+------------------------------------------------
                         var(Residual) |   18.05873   3.617251      12.19516    26.74158
          ------------------------------------------------------------------------------
          Using this output and looking at collect levelsof output for coleq and colname from the original example, you will find that melogit stripes the random slope with column equation "/" and column name "var(_cons[turn])". For mixed, the column equation is "turn" and column name is "var(_cons)".

          Here is the code I used to make the random slope estimates show up in the same row.
          Code:
          etable, estimates(cont1 binary2) eqrecode(mpg=mileage hi_mpg=mileage) ///
                  eqrecode(turn=/)
          collect recode colname var(_cons)=var(_cons[turn])
          Here is the resulting table.
          Code:
          --------------------------------------
                                   mpg    hi_mpg
          --------------------------------------
          Trunk space (cu. ft.)   -0.638  -0.500
                                 (0.135) (0.155)
          Intercept               30.052   6.174
                                 (1.999) (2.113)
          var(e)                  18.059
                                 (3.617)
          var(_cons[turn])         4.554   5.195
                                 (4.309) (4.997)
          Number of observations      74      74
          --------------------------------------

          Comment


          • #6
            Jeff, thanks so much. That's enormously helpful - both solutions are useful.

            Comment

            Working...
            X