Announcement

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

  • What is the syntax to retrieve r-class stored results in multiple equation models, like bivariate poisson, var, or sure?

    I can retrieve coefficient estimates by:
    gen Cf = [equationname]_b[varname]
    ,no problem!
    But I am having trouble retrieving r-class results. I tried gen Cf = [equationname]_r[mean], Cf = [equationname]_mean, gen Cf = _r(mean1) but none of them worked.
    Also, if not the same, what is the syntax to retrieve e-class stored results in multiple equation models?
    Thanks

  • #2
    You need to be specific about the names of the commands and state the source if these are user-written commands. To access the return results stored in r(), type

    Code:
    return list
    For estimation results:

    Code:
    ereturn list

    Comment


    • #3
      OK. How do you get the mean of the sample for the first equation (or equation named "FirstVariable") in a vector auto regression which is not user-written. When I type "return list" i see them but how do I retrieve them as a scalar or as a variable? When I say "gen samplemean1 = ?" what do I write in where "?" appears ? I I could not find any documentation on the syntax for multiple equation models.
      Last edited by Oscar Ozfidan; 09 Jan 2019, 12:46.

      Comment


      • #4
        Can you copy and paste the output of -return list- and point to what you want?

        Comment


        • #5
          What -r(table)- contains is the same as those coefficients and standard errors that you know how to refer to, except that there are some more derived statistics like p-values.

          So either refer to the coefficients, or just refer to the element of the matrix that you need.

          Comment


          • #6
            Code:
            . webuse lutkepohl2, clear
            (Quarterly SA West German macro data, Bil DM, from Lutkepohl 1993 Table E.1)
            
            . var dln_inv dln_consump
            
            Vector autoregression
            
            Sample:  1960q4 - 1982q4                        Number of obs     =         89
            Log likelihood =   439.6021                     AIC               =   -9.65398
            FPE            =   2.20e-07                     HQIC              =  -9.541273
            Det(Sigma_ml)  =   1.76e-07                     SBIC              =  -9.374358
            
            Equation           Parms      RMSE     R-sq      chi2     P>chi2
            ----------------------------------------------------------------
            dln_inv               5     .043901   0.0995   9.837951   0.0432
            dln_consump           5     .010679   0.1010   9.996723   0.0405
            ----------------------------------------------------------------
            
            ------------------------------------------------------------------------------
                         |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
            dln_inv      |
                 dln_inv |
                     L1. |  -.2783987   .1093257    -2.55   0.011    -.4926731   -.0641243
                     L2. |  -.1251467   .1080765    -1.16   0.247    -.3369727    .0866794
                         |
             dln_consump |
                     L1. |   .8989791   .4343833     2.07   0.038     .0476034    1.750355
                     L2. |   .7896433   .4455018     1.77   0.076    -.0835241    1.662811
                         |
                   _cons |  -.0080688   .0123968    -0.65   0.515    -.0323662    .0162285
            -------------+----------------------------------------------------------------
            dln_consump  |
                 dln_inv |
                     L1. |  -.0017619   .0265929    -0.07   0.947     -.053883    .0503591
                     L2. |   .0545457    .026289     2.07   0.038     .0030202    .1060712
                         |
             dln_consump |
                     L1. |   -.017519   .1056614    -0.17   0.868    -.2246114    .1895735
                     L2. |   .1657664   .1083659     1.53   0.126    -.0466268    .3781596
                         |
                   _cons |   .0148851   .0030155     4.94   0.000     .0089749    .0207953
            ------------------------------------------------------------------------------
            
            . return list
            
            scalars:
                          r(level) =  95
            
            matrices:
                          r(table) :  9 x 10
            
            . mat Rtable = r(table)
            
            . sca Brtable = Rtable[1,1]
            
            . sca Bcoeff = [dln_inv]_b[l.dln_inv]
            
            . sca list
                Bcoeff = -.27839867
               Brtable = -.27839867

            Comment


            • #7
              Figured it out. "gen rmse1= e(rmse_1)" works. Regardless of the equation name rmse of the first equation is referred to as rmse_1 and second as as rmse_2.

              . ereturn list

              scalars:
              e(N) = 66
              e(df_eq) = 5
              e(k) = 10
              e(obs_1) = 66
              e(k_1) = 5
              e(rmse_1) = 50.45066250639565
              e(r2_1) = .9916945830794686
              e(ll_1) = -349.8359022135093
              e(df_m1) = 4
              e(obs_2) = 66
              e(k_2) = 5
              e(rmse_2) = .7366700545715245
              e(r2_2) = .1508585972749652
              e(ll_2) = -70.87957272626753
              e(df_m2) = 4
              e(chi2_1) = 7880.6209380514
              e(chi2_2) = 11.72557054478299
              e(ll) = -420.0144702859178
              e(rank) = 10
              e(sbic) = 13.36250739381969
              e(hqic) = 13.16183798747264
              e(aic) = 13.03074152381569
              e(fpe) = 1564.887340845201
              e(mlag) = 2
              e(tmax) = 1343
              e(tmin) = 1278
              e(N_gaps) = 0
              e(k_dv) = 2
              e(k_eq) = 2
              e(detsig) = 1155.117198033127
              e(detsig_ml) = 1155.117198033127

              macros:
              e(cmd) : "var"
              e(cmdline) : "var Sira Res"
              e(predict) : "var_p"
              e(marginsdefault) : "predict(xb equation(Sira)) predict(xb equation(Res))"
              e(marginsnotok) : "stdp Residuals"
              e(marginsok) : "xb default"
              e(lags) : "1 2"
              e(endog) : "Sira Res"
              e(timevar) : "order1"
              e(tsfmt) : "%9.0g"
              e(title) : "Vector autoregression"
              e(eqnames) : "Sira Res "
              e(depvar) : "Sira Res"
              e(properties) : "b V"

              matrices:
              e(b) : 1 x 10
              e(V) : 10 x 10
              e(bf) : 1 x 10
              e(G) : 5 x 5
              e(Sigma) : 2 x 2

              functions:
              e(sample)

              Comment


              • #8
                Good that you figured it out, two remarks from the pedants' corner:

                1. What you called "the mean of the sample" in #3, such a concept does not exist in statistics/econometrics. Further the root mean squared error is hard to be imagined to be mean of the sample, but is rather what the name says. The square root, of the mean of the squared error.

                3. Assigning a scalar (the root mean squared error is a scalar quantity) to a whole variable (=whole data vector of repeated same value) is a bit of a wasteful practice. I dont know what you are about to do with this next, but probably it is better if you assign the root mean scared error to a scalar, rather than a variable.

                Comment


                • #9
                  Joro, I am new to Stata did not know dep var means not stored that way.
                  Last edited by Oscar Ozfidan; 09 Jan 2019, 20:16.

                  Comment


                  • #10
                    Originally posted by Oscar Ozfidan View Post
                    Joro, I am new to Stata did not know dep var means not stored that way.
                    If you need the mean of the dependent variable calculated over the estimation sample, this quantity is not in e(rmse).

                    To get the mean of the dependent variable over the sample you do:

                    summ y if e(sample)

                    and then you retrieve the r(mean) from the return list.

                    Like this:

                    Code:
                    . sysuse auto, clear
                    (1978 Automobile Data)
                    
                    . reg price mpg headroom
                    
                          Source |       SS           df       MS      Number of obs   =        74
                    -------------+----------------------------------   F(2, 71)        =     10.44
                           Model |   144280501         2  72140250.4   Prob > F        =    0.0001
                        Residual |   490784895        71  6912463.32   R-squared       =    0.2272
                    -------------+----------------------------------   Adj R-squared   =    0.2054
                           Total |   635065396        73  8699525.97   Root MSE        =    2629.2
                    
                    ------------------------------------------------------------------------------
                           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                             mpg |  -259.1057   58.42485    -4.43   0.000    -375.6015   -142.6098
                        headroom |  -334.0215   399.5499    -0.84   0.406    -1130.701    462.6585
                           _cons |   12683.31   2074.497     6.11   0.000     8546.885    16819.74
                    ------------------------------------------------------------------------------
                    
                    . summ price if e(sample)
                    
                        Variable |        Obs        Mean    Std. Dev.       Min        Max
                    -------------+---------------------------------------------------------
                           price |         74    6165.257    2949.496       3291      15906
                    
                    . return list
                    
                    scalars:
                                      r(N) =  74
                                  r(sum_w) =  74
                                   r(mean) =  6165.256756756757
                                    r(Var) =  8699525.974268788
                                     r(sd) =  2949.495884768919
                                    r(min) =  3291
                                    r(max) =  15906
                                    r(sum) =  456229
                    
                    . sca MeanPrice = r(mean)
                    
                    
                    . sca list MeanPrice
                     MeanPrice =  6165.2568

                    Comment

                    Working...
                    X