Announcement

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

  • etable of multiple mlogit results: how to create multi-level column header

    The following code runs two mlogit models and then creates a table where the coefficients for two different outcomes are shown side-by-side rather than stacked. Each pair of outcomes is labeled (Model 1 and Model 2 respectively.) How can I add a row which labels each of the four columns with the label for the appropriate level of the dependent variable?

    Thanks,
    Devra

    Code:
    clear all
    use http://www.stata-press.com/data/r15/nmihs.dta
    
    mlogit bwgrp marital age highbp, baseoutcome(3)
    estimates store m1
    
    mlogit bwgrp marital age highbp race, baseoutcome(3)
    estimates store m2
    
    etable, estimates (m1 m2) showstars
    collect label levels cmdset 1 "Model 1" 2 "Model 2", modify
    collect layout (colname#result[_r_b _r_se] result[N]) ///
                    (cmdset#coleq[]#stars[])
    Devra Golbe
    Professor Emerita, Dept. of Economics
    Hunter College, CUNY

  • #2
    Thanks for the data example.

    Code:
    clear all
    use http://www.stata-press.com/data/r15/nmihs.dta
    
    mlogit bwgrp marital age highbp, baseoutcome(3)
    estimates store m1
    
    mlogit bwgrp marital age highbp race, baseoutcome(3)
    estimates store m2
    
    
    
    etable, estimates (m1 m2) showstars
    collect label levels cmdset 1 "Model 1" 2 "Model 2", modify
    collect label levels coleq 1 "`:lab (bwgrp) 1'" 2 "`:lab (bwgrp) 2'" 3 "`:lab (bwgrp) 3'", modify
    collect style header coleq, title(hide) level(value)
    collect layout (colname#result[_r_b _r_se] result[N]) ///
                    (cmdset#coleq[]#stars[])
    Res.:

    Code:
    . collect layout (colname#result[_r_b _r_se] result[N]) ///
    >                 (cmdset#coleq[]#stars[])
    
    Collection: ETable
          Rows: colname#result[_r_b _r_se] result[N]
       Columns: cmdset#coleq[]#stars[]
       Table 1: 10 x 8
    
    ---------------------------------------------------------------------------
                                           Model 1               Model 2       
                                       bw_15     bw15_25     bw_15     bw15_25 
    ---------------------------------------------------------------------------
    0=single, 1=married              -0.423 **  -0.346 **  -0.490 **  -0.419 **
                                    (0.062)    (0.062)    (0.069)    (0.069)   
    Mother's age in years             0.012 *    0.003      0.012 *    0.002   
                                    (0.005)    (0.005)    (0.005)    (0.005)   
    High blood pressure: 1=yes,0=no   0.664 **   0.635 **   0.664 **   0.634 **
                                    (0.107)    (0.108)    (0.107)    (0.108)   
    Race: 1=black, 0=white/other                           -0.145 *   -0.157 * 
                                                          (0.065)    (0.065)   
    Intercept                        -1.617 **  -1.427 **  -1.493 **  -1.292 **
                                    (0.129)    (0.129)    (0.140)    (0.141)   
    ---------------------------------------------------------------------------
    Last edited by Andrew Musau; 26 Oct 2023, 08:15.

    Comment


    • #3
      Andrew,

      Thanks so much! This is exactly what I need. In an effort to understand how your code works, I tried adding the additional lines one at a time. It appears that the following code produces the same results as your code. What am I missing?

      Code:
      clear all
      use http://www.stata-press.com/data/r15/nmihs.dta
      
      mlogit bwgrp marital age highbp, baseoutcome(3)
      estimates store m1
      
      mlogit bwgrp marital age highbp race, baseoutcome(3)
      estimates store m2
      
      etable, estimates (m1 m2) showstars
      collect label levels cmdset 1 "Model 1" 2 "Model 2", modify
      *collect label levels coleq  ///
      *     1 "`:lab (bwgrp) 1'" 2 "`:lab (bwgrp) 2'" 3 "`:lab (bwgrp) 3'", modify
      *collect style header coleq, title(label)
      collect style header coleq, title(hide) level(value)
      collect layout (colname#result[_r_b _r_se] result[N]) ///
                      (cmdset#coleq[]#stars[])

      Code:
      Collection: ETable
            Rows: colname#result[_r_b _r_se] result[N]
         Columns: cmdset#coleq[]#stars[]
         Table 1: 10 x 8
      
      ---------------------------------------------------------------------------
                                             Model 1               Model 2       
                                         bw_15     bw15_25     bw_15     bw15_25
      ---------------------------------------------------------------------------
      0=single, 1=married              -0.423 **  -0.346 **  -0.490 **  -0.419 **
                                      (0.062)    (0.062)    (0.069)    (0.069)   
      Mother's age in years             0.012 *    0.003      0.012 *    0.002   
                                      (0.005)    (0.005)    (0.005)    (0.005)   
      High blood pressure: 1=yes,0=no   0.664 **   0.635 **   0.664 **   0.634 **
                                      (0.107)    (0.108)    (0.107)    (0.108)   
      Race: 1=black, 0=white/other                           -0.145 *   -0.157 *
                                                            (0.065)    (0.065)   
      Intercept                        -1.617 **  -1.427 **  -1.493 **  -1.292 **
                                      (0.129)    (0.129)    (0.140)    (0.141)   
      ---------------------------------------------------------------------------
      Devra Golbe
      Professor Emerita, Dept. of Economics
      Hunter College, CUNY

      Comment


      • #4
        You are not missing anything. The following is unnecessary as the variable's values are already labeled.

        collect label levels coleq 1 "`:lab (bwgrp) 1'" 2 "`:lab (bwgrp) 2'" 3 "`:lab (bwgrp) 3'", modify
        You would only need to define the labels if the variable's values were not labeled or you wanted to change the labels on the fly.

        Comment


        • #5
          Thanks! I'm sure I will find that code useful not too far down the road. Not to impose on your time and expertise, but what does this line do?
          Code:
           
           collect style header coleq, title(label)
          Devra Golbe
          Professor Emerita, Dept. of Economics
          Hunter College, CUNY

          Comment


          • #6
            Explained in

            Code:
            help collect style header

            Comment


            • #7
              Thanks. I'll read that again, more carefully. :-)
              Devra Golbe
              Professor Emerita, Dept. of Economics
              Hunter College, CUNY

              Comment


              • #8
                So the description reads

                collect style header edits the content of the table headers. With this style, you can specify how the dimensions and levels are displayed in row, column, and table headers. For each dimension, the name of the dimension, the label of the dimension,
                or nothing may be displayed. Likewise, for levels within a dimension, the label of that level, the value of the level, or nothing may be displayed.
                You can see the dimensions in your table by running

                Code:
                collect dims

                Res.:

                Code:
                . collect dims
                
                Collection dimensions
                Collection: ETable
                -----------------------------------------
                                   Dimension   No. levels
                -----------------------------------------
                Layout, style, header, label
                                      cmdset   2        
                                       coleq   3        
                                     colname   13        
                               etable_depvar   2        
                              etable_dvlabel   2        
                            etable_estimates   2        
                                etable_title   2        
                               program_class   2        
                                      result   49        
                                 result_type   3        
                                     rowname   1        
                                       stars   2        
                
                Style only
                                border_block   4        
                                   cell_type   4        
                -----------------------------------------

                So "coleq" is a dimension with 3 levels. We know that these are the levels of the outcome in the multinomial logit. The option -level(value)- in

                collect style header coleq, title(hide) level(value)
                is described by the second part of the paragraph above:

                Likewise, for levels within a dimension, the label of that level, the value of the level, or nothing may be displayed
                Here, I opt for values of the levels to be displayed. Other possibilities would be

                Code:
                level(label)
                and

                Code:
                level(hide)
                corresponding to the label of the dimension and nothing, respectively. Finally


                title(tstyle) specifies the dimension title header style to be used in row, column, and table headers. tstyle may be label, name, or hide.
                In #2, I have -title(hide)- as the default is -title(label)- and I don't want the title of the dimension to be displayed. The other possibility is

                Code:
                title(name)
                corresponding to the name of the dimension as the title. Note that we can have other dimensions displayed (as well as their titles) in the column or row, using collect style header, as we have done for "coleq". Hope this helps.
                Last edited by Andrew Musau; 27 Oct 2023, 02:09.

                Comment


                • #9
                  Andrew: Thanks yet again for this detailed response. It's been very helpful to work through the options.
                  Devra Golbe
                  Professor Emerita, Dept. of Economics
                  Hunter College, CUNY

                  Comment

                  Working...
                  X