Announcement

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

  • Transposing est table

    Dear Stata users,

    I need to estimate and compare a large number of models. To do so, I use an analogue of the following code:
    Code:
    clear
    est clear
    sysuse auto.dta
    
    reg price mpg
    est store mod_1
    
    reg price c.mpg#c.mpg
    est store mod_2
    
    est table *, stats(N aic bic r2_a rmse)
    Is there a way (i.e., an option or an alternative command) to transpose the estimates table? The model comparison would be easier if models were shown as rows and stats as columns; the default is the other way around.

  • #2
    I gather this can be achieved under - matrix - commands, by using r(coef) and r(stats).
    Best regards,

    Marcos

    Comment


    • #3
      Marcos Almeida inspired me to the following, since, on reflection, the wording in post #1 suggests that the stats (rather than the coefficients) might be the object of your interest. It takes more work to get the coefficients included and in most reasonable models makes for a very wide table, so I'm thinking that you want to be able to scan the statistics easily, and scanning down similar numbers is easier than scanning across a row. Perhaps this example code can start you to something productive. I demonstrate not only producing a tabulated report, but also moving the statistics into the dataset, so that you can more easily automate their examination, availing yourself of all of Stata's tools.
      Code:
      . est table *, stats(N aic bic r2_a rmse)
      
      ----------------------------------------
          Variable |   mod_1        mod_2     
      -------------+--------------------------
               mpg | -238.89435               
                   |
       c.mpg#c.mpg |              -4.2131542  
                   |
             _cons |  11253.061    8215.3548  
      -------------+--------------------------
                 N |         74           74  
               aic |  1377.0792    1382.3173  
               bic |  1381.6873    1386.9254  
              r2_a |  .20874373    .15070431  
              rmse |  2623.6529     2718.174  
      ----------------------------------------
      
      . 
      . return list
      
      macros:
                    r(names) : "mod_1 mod_2"
      
      matrices:
                    r(stats) :  5 x 2
                     r(coef) :  3 x 4
      
      . matrix stats = r(stats)'
      
      . matrix list stats
      
      stats[2,5]
                     N        aic        bic       r2_a       rmse
      mod_1         74  1377.0792  1381.6873  .20874373  2623.6529
      mod_2         74  1382.3173  1386.9254  .15070431   2718.174
      
      . svmat stats, names(matcol)
      
      . rename (stats*) (*)
      
      . list N-rmse in 1/2
      
           +------------------------------------------------+
           |  N        aic        bic       r2_a       rmse |
           |------------------------------------------------|
        1. | 74   1377.079   1381.687   .2087437   2623.653 |
        2. | 74   1382.317   1386.925   .1507043   2718.174 |
           +------------------------------------------------+

      Comment


      • #4
        Thank you, this works quite well! Actually, the command
        Code:
        matrix list stats
        is sufficient for my purpose of getting a quick glance of the model statistics.

        Comment


        • #5
          For future reference: I ended up using this code:
          Code:
          clear
          est clear
          sysuse auto.dta
          
          reg price mpg
          est store mod_1
          
          reg price c.mpg#c.mpg
          est store mod_2
          
          qui est table *, stats(N aic bic rmse r2 r2_a) drop(*)
          matrix stats = r(stats)'
          
          svmat2 stats, names(col) rnames(model) // Via findit svmat2 (package dm79)
          order model, before(N)
          format %7.2f aic bic
          format %10.2f rmse
          format %6.5f r2 r2_a
          
          sort N aic
          by N: list model-r2_a if !missing(N), sep(200)

          Comment


          • #6
            Thank you for informing and for sharing the solution so as other people could use it in similar problems. This act is in the best spirit of the Forum.
            Best regards,

            Marcos

            Comment

            Working...
            X