Announcement

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

  • Results of multiple regressions in one column

    Hi Statalist

    I'm trying to run multiple regressions with different variables, but I want to have all the estimates in one column. Here's what I'm doing:

    Code:
    sysuse auto
    est clear
    
    foreach x of varlist mpg price rep78 {
        logistic foreign `x'
        estimates store m_`x'
    }
    
    etable, estimates(m_*) ///
        cstat(_r_b, nformat(%4.2f)) ///
        cstat(_r_ci, cidelimiter("-") nformat(%6.2f)) ///
        column(depvar)
    And I get:


    Code:
    . etable, estimates(m_*) ///
    >         cstat(_r_b, nformat(%4.2f)) ///
    >         cstat(_r_ci, cidelimiter("-") nformat(%6.2f)) ///
    >         column(depvar)
    
    ----------------------------------------------------------------
                              foreign       foreign       foreign  
    ----------------------------------------------------------------
    Mileage (mpg)                   1.17                            
                           [1.06-  1.30]                            
    Price                                         1.00              
                                         [1.00-  1.00]              
    Repair record 1978                                          7.17
                                                       [2.80- 18.30]
    Intercept                       0.01          0.34          0.00
                           [0.00-  0.13] [0.11-  1.08] [0.00-  0.01]
    Number of observations            74            74            69
    ----------------------------------------------------------------

    But I'm looking for something like this:

    Code:
    --------------------------------------------------------------------------
                              foreign_coef        CIs        P-values
    --------------------------------------------------------------------------
    Mileage (mpg)                   1.17        [1.06-  1.30]        <0.05            
    Price                           1.00        [1.00-  1.00]        0.676            
    Repair record 1978              7.17        [2.80- 18.30]        <0.001            
    ---------------------------------------------------------------------------
    I'm also trying some "collect" commands here, but it does not work for me. I'd appreciate if anyone can help.
    Last edited by Sa Fe; 14 Mar 2024, 15:41.

  • #2
    Thank you for a working example.

    In the following I add a cstat() option to style the p-values, then use collect commands to make further style changes and rearrange the items according to the requested layout.
    Code:
    sysuse auto
    estimates clear
    
    * we will reference this list more than once
    unab xvars : mpg price rep78
    
    foreach x of local xvars {
        logistic foreign `x'
        estimates store m_`x'
    }
    
    etable, estimates(m_*) ///
        cstat(_r_b, nformat(%4.2f)) ///
        cstat(_r_ci, cidelimiter("-") nformat(%6.2f)) ///
        cstat(_r_p, nformat(%6.3f) minimum(.001)) /// <-- NEW
        column(depvar)
    
    * show layout specification
    collect layout
    
    * fix autolevels
    collect style autolevels colname `xvars', clear
    collect style autolevels result _r_b _r_ci _r_p, clear
    
    * fix header styles for results of interest
    collect style header result[_r_b _r_ci _r_p], level(label)
    
    * add square brackets to CIs
    collect style cell cell_type[item]#result[_r_ci], sformat("[%s]") 
    
    * fix layout
    collect layout (colname) (result#stars[value])
    Here is the resulting table.
    Code:
    ----------------------------------------------------
                       Coefficient     95% CI    p-value
    ----------------------------------------------------
    Mileage (mpg)             1.17 [1.06-  1.30]   0.002
    Price                     1.00 [1.00-  1.00]   0.676
    Repair record 1978        7.17 [2.80- 18.30]  <0.001
    ----------------------------------------------------

    Comment


    • #3
      Thanks Jeff. That's really great.
      Can we append the full model results to the right side of this table?

      the model: logistic foreign mpg price rep78

      the results should be something like:

      Code:
       -------------------------------------------------------------------------------------
                                 SRM                              MTM
                                                                (n = ...}
                         Coefficient     95% CI    p-value    Coefficient 95% CI p-value
      -------------------------------------------------------------------------------------
      Mileage (mpg)             1.17 [1.06-  1.30]   0.002    1.17 [1.06- 1.30] 0.2
      Price                     1.00 [1.00-  1.00]   0.676    1.17 [1.06- 1.30] <.05
      Repair record 1978        7.17 [2.80- 18.30]  <0.001    1.17 [1.06- 1.30] <.001
      -------------------------------------------------------------------------------------

      Comment


      • #4
        Yes. The following code shows one way this can be done if appended to the
        above example.
        Code:
        * tag the current results as group[SRM], also add dimension size that we
        * will use to show the sample size for the MTM
        collect addtags group[SRM] size[SRM]
        
        * collect results for MTM
        collect, tag(group[MTM] size[MTM]) : logistic foreign `xvars'
        
        * style and label the new dimensions
        collect style header group, title(hide)
        collect style header size, title(hide) level(label)
        * the space for SRM is a unicode space U+2800
        collect label levels size SRM "⠀" MTM "(n = `e(N)')"
        
        * update layout
        collect layout (colname) (group#size#result#stars[value])
        Here is the resulting table.
        Code:
        --------------------------------------------------------------------------------------
                                          SRM                               MTM
                                           ⠀                              (n = 69)
                           Coefficient     95% CI    p-value Coefficient     95% CI    p-value
        --------------------------------------------------------------------------------------
        Mileage (mpg)             1.17 [1.06-  1.30]   0.002        1.18 [1.01-  1.39]   0.043
        Price                     1.00 [1.00-  1.00]   0.676        1.00 [1.00-  1.00]   0.305
        Repair record 1978        7.17 [2.80- 18.30]  <0.001        5.32 [2.00- 14.16]  <0.001
        --------------------------------------------------------------------------------------

        Comment

        Working...
        X