Announcement

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

  • estout and dropping different equations in different models

    I am performing a multinomial logistic regression and would like to have results for all the unique combinations of the categories in my data (i.e., have a model comparing group 1 to group 2, group 1 to group 3, and group 2 to group 3). My current solution is to run two separate mlogit models with base category 1 (picks up 1 vs. 2 and 1 vs. 3 comparisons) and base category 2 (picks up 2 vs. 3 comparison).

    I am using estout (SSC) on Stata 16.1 to tabulate the output. Estimating the two models separately and appending them using estout gives:

    Code:
    Code:
    clear all
    webuse auto
    keep if rep78 <= 3 // keeping only 3 levels for simplicity
    
    qui mlogit rep78 weight length turn displacement, base(1)
    est store mlogit1
    
    qui mlogit rep78 weight length turn displacement, base(2)
    est store mlogit2
    
    estout mlogit1 mlogit2, stats(r2_p N, labels("Psuedo R-Squared" "N")) cells(b(star fmt(4)) ///
    se(par fmt(4))) label unstack eqlabels("1v1" "1v2" "1v3" "2v1" "2v2" "2v3")
    Output:
    Code:
    --------------------------------------------------------------------------------------------------------------------
                              mlogit1                                         mlogit2                                  
                                  1v1             1v2             1v3             1v1             1v2             1v3  
                                 b/se            b/se            b/se            b/se            b/se            b/se  
    --------------------------------------------------------------------------------------------------------------------
    Weight (lbs.)              0.0000         -0.0050         -0.0010          0.0050          0.0000          0.0040  
                                  (.)        (0.0044)        (0.0036)        (0.0044)             (.)        (0.0028)  
    Length (in.)               0.0000          0.0612          0.0329         -0.0612          0.0000         -0.0283  
                                  (.)        (0.1249)        (0.1043)        (0.1249)             (.)        (0.0793)  
    Turn Circle (ft.)          0.0000          0.2626         -0.2390         -0.2626          0.0000         -0.5016  
                                  (.)        (0.5053)        (0.4706)        (0.5053)             (.)        (0.2651)  
    Displacement .. in.)       0.0000          0.0252          0.0150         -0.0252          0.0000         -0.0102  
                                  (.)        (0.0264)        (0.0240)        (0.0264)             (.)        (0.0126)  
    _cons                      0.0000        -10.9911          6.3386         10.9911          0.0000         17.3298  
                                  (.)       (14.1205)       (11.6565)       (14.1205)             (.)        (9.1018)  
    --------------------------------------------------------------------------------------------------------------------
    Psuedo R-Squared           0.1337                                          0.1337                                  
    N                         40.0000                                         40.0000                                  
    --------------------------------------------------------------------------------------------------------------------
    I would like to drop the first, third, and fourth columns. Since the first and third columns have the same name ("1") I can do the following:

    Code:
    estout mlogit1 mlogit2, stats(r2_p N, labels("Psuedo R-Squared" "N")) cells(b(star fmt(4)) ///
    se(par fmt(4))) label unstack eqlabels("1v2" "1v3" "2v2" "2v3") drop(1:)
    which has the desired effect. I have two questions:
    1. How can I drop equation "2" in the second model only? I have attempted using the pattern(0 1) syntax used elsewhere with no results.
    2. How can I have different equation labels in the different models? Currently estout is repeating the equation labels across both models, which is incorrect.
    Last edited by Joe Moran; 01 Aug 2022, 11:24.

  • #2
    Change the equation names in the second model.

    Comment


    • #3
      Andrew Mus

      Comment


      • #4
        Andrew Musau thanks! I have not been able to find documentation for changing the names of equations in esttab or eststo. How would I be able to do that in this example?

        Comment


        • #5
          erepost is from SSC.

          Code:
          clear all
          webuse auto
          keep if rep78 <= 3 // keeping only 3 levels for simplicity
          qui mlogit rep78 weight length turn displacement, base(1)
          est store mlogit1
          
          qui mlogit rep78 weight length turn displacement, base(2)
          local eqs: coleq e(b)
          di "`eqs'"
          local neweqs 
          foreach eq in `eqs'{
              local neweqs "`neweqs' `=`eq'+5'"
          }
          di "`neweqs'" 
          mat b= e(b)
          mat coleq b= `neweqs'
          erepost b=b, rename
          est sto mlogit2
          
          estout mlogit1 mlogit2, stats(r2_p N, labels("Psuedo R-Squared" "N")) cells(b(star fmt(4)) ///
          se(par fmt(4))) label unstack eqlabels("1v1" "1v2" "1v3" "2v1" "2v2" "2v3")
          Res.:

          Code:
          . estout mlogit1 mlogit2, stats(r2_p N, labels("Psuedo R-Squared" "N")) cells(b(star fmt(4)) ///
          > se(par fmt(4))) label unstack eqlabels("1v1" "1v2" "1v3" "2v1" "2v2" "2v3")
          
          --------------------------------------------------------------------------------------------------------------------
                                    mlogit1                                         mlogit2                                   
                                        1v1             1v2             1v3             2v1             2v2             2v3   
                                       b/se            b/se            b/se            b/se            b/se            b/se   
          --------------------------------------------------------------------------------------------------------------------
          Weight (lbs.)              0.0000         -0.0050         -0.0010          0.0050          0.0000          0.0040   
                                        (.)        (0.0044)        (0.0036)        (0.0044)             (.)        (0.0028)   
          Length (in.)               0.0000          0.0612          0.0329         -0.0612          0.0000         -0.0283   
                                        (.)        (0.1249)        (0.1043)        (0.1249)             (.)        (0.0793)   
          Turn Circle (ft.)          0.0000          0.2626         -0.2390         -0.2626          0.0000         -0.5016   
                                        (.)        (0.5053)        (0.4706)        (0.5053)             (.)        (0.2651)   
          Displacement .. in.)       0.0000          0.0252          0.0150         -0.0252          0.0000         -0.0102   
                                        (.)        (0.0264)        (0.0240)        (0.0264)             (.)        (0.0126)   
          _cons                      0.0000        -10.9911          6.3386         10.9911          0.0000         17.3298   
                                        (.)       (14.1205)       (11.6565)       (14.1205)             (.)        (9.1018)   
          --------------------------------------------------------------------------------------------------------------------
          Psuedo R-Squared           0.1337                                          0.1337                                   
          N                         40.0000                                         40.0000                                   
          --------------------------------------------------------------------------------------------------------------------

          Comment


          • #6
            Andrew Musa

            Comment


            • #7
              Andrew Musau thank you! As a first time estpost user your answers have been extremely helpful!

              Comment


              • #8
                If is valuable for anyone who has this same issue, I've generalized the code above to handle string and numeric equation names:

                Code:
                * Define function for renaming equations
                
                program define estrename
                    
                    *** Define arguments
                    
                    args suffix
                    
                    *** Check to ensure model estimates exist in memory
                    
                    confirm matrix e(b)
                    
                    *** Store column names as local matrix
                    
                    local eqs: coleq e(b)
                
                    *** Append suffix to each element in local matrix eqs
                    
                    local neweqs 
                    foreach eq in `eqs'{
                        local neweqs "`neweqs' `eq'`suffix'"
                    }
                    matrix b = e(b)
                    matrix coleq b = `neweqs'
                    
                    *** Repost new column names back to original estimate
                    
                    erepost b=b, rename
                    
                end

                Comment

                Working...
                X