Announcement

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

  • Outreg2 Example 9. Adding r( ) e( ) scalars

    Hi Everyone,

    I am looking for some clarification with -help outreg2-.
    1. In the examples provided with -help outreg2-, (specifically, reg price mpg rep78 head) is it possible to export Adj R-squared and Root MSE? How I can store Adj R-squared and Root MSE as macros?
    1. In the next step (lincom mpg + rep), tstat and pval are calculated and stored as local macros. But, those values are already available after -lincom-. Is it possible to export t and P>|t| without doing the extra step of r(estimate)/r(se)?
    1. I know that e() includes everything in the ereturn list. What can be included with r()?
    I would be truly grateful for a response from someone who has worked with outreg2.


  • #2
    In the examples provided with -help outreg2-, (specifically, reg price mpg rep78 head) is it possible to export Adj R-squared and Root MSE? How I can store Adj R-squared and Root MSE as macros
    You can refer to stats in ereturn directly, e.g.,

    Code:
    outreg2..., addstat(e(r2_a), Adjusted R-squared)
    or store as a local

    Code:
    local r2_a= e(r2_a)
    outreg2..., addstat(`r2_a', Adjusted R-squared)
    In the next step (lincom mpg + rep), tstat and pval are calculated and stored as local macros. But, those values are already available after -lincom-. Is it possible to export t and P>|t| without doing the extra step of r(estimate)/r(se)?
    See previous reply.

    I know that e() includes everything in the ereturn list. What can be included with r()?
    Have a look at

    Code:
    return list
    to see what is stored.

    Comment


    • #3
      Hi Prof. Musau,

      Your response helps a lot! Thank you!

      I noticed that t values and p values are not stored either in r() or e(). So, if we want to export any of them, do we always have to pass these commands?

      local tstat=r(estimate)/r(se)
      local pval = tprob(r(df), abs(`tstat'))

      The p value associated with the regression F test is also not stored in r() or e(). How I export that to an excel file?

      --Sunita

      Comment


      • #4
        Do you mean the results from lincom? I would switch to margins with the -post- option for this. In this way, I can pick all the displayed results from matrix r(table) in return list. Otherwise, for regressions, the results are always stored in r(table).

        Code:
        sysuse auto, clear
        qui reg price mpg rep78 head
        lincom mpg + rep
        *GET LINCOM RESULTS USING MARGINS AND POST
        margins, expression(_b[mpg] + _b[rep78]) post
        *DISPLAY MATRIX R(TABLE)
        mat l r(table)
        *EXTRACT, FOR EXAMPLE, P-VALUE
        local pvalue= r(table)[rownumb(r(table),"pvalue"),1]
        di "`pvalue'"
        Res.:

        Code:
        . lincom mpg + rep
        
         ( 1)  mpg + rep78 = 0
        
        ------------------------------------------------------------------------------
               price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 (1) |   381.5509   325.0422     1.17   0.245    -267.6032    1030.705
        ------------------------------------------------------------------------------
        
        .
        . *GET LINCOM RESULTS USING MARGINS AND POST
        
        .
        . margins, expression(_b[mpg] + _b[rep78]) post
        Warning: expression() does not contain predict() or xb().
        Warning: prediction constant over observations.
        
        Predictive margins                              Number of obs     =         69
        Model VCE    : OLS
        
        Expression   : _b[mpg] + _b[rep78]
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
               _cons |   381.5509   325.0422     1.17   0.240    -255.5202    1018.622
        ------------------------------------------------------------------------------
        
        .
        . *DISPLAY MATRIX R(TABLE)
        
        .
        . mat l r(table)
        
        r(table)[9,1]
                     _cons
             b    381.5509
            se   325.04223
             z   1.1738503
        pvalue     .240455
            ll  -255.52015
            ul    1018.622
            df           .
          crit    1.959964
         eform           0
        
        .
        . *EXTRACT, FOR EXAMPLE, P-VALUE
        
        .
        . local pvalue= r(table)[rownumb(r(table),"pvalue"),1]
        
        .
        . di "`pvalue'"
        .2404550043009015

        Comment


        • #5
          The p value associated with the regression F test is also not stored in r() or e().
          Code:
          sysuse auto
          reg price mpg rep78 head
          testparm *
          local pvalF= r(p)
          di "`pvalF'"
          Res.:

          Code:
          . sysuse auto
          (1978 Automobile Data)
          
          . 
          . reg price mpg rep78 head
          
                Source |       SS           df       MS      Number of obs   =        69
          -------------+----------------------------------   F(3, 65)        =      7.51
                 Model |   148497605         3  49499201.8   Prob > F        =    0.0002
              Residual |   428299354        65  6589220.82   R-squared       =    0.2575
          -------------+----------------------------------   Adj R-squared   =    0.2232
                 Total |   576796959        68  8482308.22   Root MSE        =    2566.9
          
          ------------------------------------------------------------------------------
                 price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   mpg |  -289.3462   62.53921    -4.63   0.000    -414.2456   -164.4467
                 rep78 |   670.8971   343.5213     1.95   0.055    -15.16242    1356.957
              headroom |  -300.0293   398.0516    -0.75   0.454    -1094.993    494.9346
                 _cons |   10921.33   2153.003     5.07   0.000     6621.487    15221.17
          ------------------------------------------------------------------------------
          
          . 
          . testparm *
          
           ( 1)  mpg = 0
           ( 2)  rep78 = 0
           ( 3)  headroom = 0
          
                 F(  3,    65) =    7.51
                      Prob > F =    0.0002
          
          . 
          . local pvalF= r(p)
          
          . 
          . di "`pvalF'"
          .0002162129073811

          Comment


          • #6
            Hi again Prof. Musau,

            I appreciate your kindness and attention to detail so much!

            I certainly learned a lot today! Thank you!

            --Sunita

            Comment

            Working...
            X