Announcement

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

  • Pulling out results that are stored in vectors from a estpost tabstat command

    Hello,

    I have the following table which is produced using the following code.

    Code:
    . estpost tabstat revenue_rl empend if year==2017, ///
    >         listwise statistics(mean sd N) by(firm_type) column(statistics)
    
    Summary statistics: mean sd count
         for variables: revenue_rl empend
      by categories of: firm_type
    
       firm_type |   e(mean)      e(sd)   e(count) 
    -------------+---------------------------------
    Foreign      |                                 
      revenue_rl |  402222.6    5995239       7616 
          empend |  514.9238   1986.279       7616 
    -------------+---------------------------------
    Private      |                                 
      revenue_rl |  20261.36   226966.1      69817 
          empend |  31.99059   269.8946      69817 
    -------------+---------------------------------
    State        |                                 
      revenue_rl |    338584    1886141       1307 
          empend |  388.6687    881.151       1307 
    -------------+---------------------------------
    Total        |                                 
      revenue_rl |  62489.76    1895996      78740 
          empend |  84.62201   693.4873      78740
    I'd like to pull out any one of these results but I'm not sure how to do this. For example when I write 'display `e(mean)'' an error appears (no matrix found). Any ideas on how I can pull out these results? Also I'd like to pull them out rounded to a certain number of decimal places if it's possible to do that. Essentially I wanna store these results in a local macro.

    Thanks,
    Jad

  • #2
    estout is from SSC, as you are asked to explain in FAQ Advice #12. Look at what the command leaves behind in e().

    Code:
    webuse grunfeld, clear
    estpost tabstat invest mvalue if year==1948, listwise statistics(mean sd N)  column(statistics)
    ereturn list
    di e(mean)[1,1]
    di e(sd)[1,2]
    Res.:

    Code:
    . estpost tabstat invest mvalue if year==1948, listwise statistics(mean sd N)  column(statistics)
    
    Summary statistics: mean sd count
         for variables: invest mvalue
    
                 |   e(mean)      e(sd)   e(count) 
    -------------+---------------------------------
          invest |   153.948   192.2528         10 
          mvalue |    896.98   1000.735         10 
    
    . 
    . ereturn list
    
    scalars:
                      e(N) =  10
    
    macros:
                    e(cmd) : "estpost"
                 e(subcmd) : "tabstat"
                  e(stats) : "mean sd count"
                   e(vars) : "invest mvalue"
    
    matrices:
                   e(mean) :  1 x 2
                     e(sd) :  1 x 2
                  e(count) :  1 x 2
    
    . 
    . di e(mean)[1,1]
    153.948
    
    . 
    . di e(sd)[1,2]
    1000.7353
    
    .

    Comment


    • #3
      The error message you got is misleading. The problem is simply that e(mean) is a matrix containing all of the means that -tabstat- calculated, and -display- does not display matrices.

      If you run -matrix list e(mean)- you will see the entire matrix of means. When you look at that matrix, the header row will show you to identify the rows and columns by name, and then you can pull out individual means into local macros. For example -local mean_foreign_empend = e(mean)["mean", "Foreign:empend"].

      It is possible to round these numbers, but I recommend against doing that. Calculations done with rounded numbers quickly start to accumulate errors. When you create your local macros, it is best to take the numbers as they are. When it comes time to -display- those numbers, you can have -display- round them by using a desired display format. For example:

      Code:
      display %2.1f `mean_foreign_empend'
      will display the value of local macro mean foreign empend, rounded to 1 decimal place. If you are not familiar with display formats, read -help format-.

      Added: Crossed with #2.

      Comment


      • #4
        Thanks for this, it's really helpful!

        Comment


        • #5
          Yes, I only want to display them with a certain number of decimal places, this does the trick. Thanks!

          Comment

          Working...
          X