Announcement

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

  • How to save the "drift" parameter of a Dickey-Fuller unit-root test (dfuller)?

    I would like to save the "drift" parameter of a Dickey-Fuller unit-root test, in order to export it with the help of "putexcel". With "drift parameter" I mean the regression constant of the estimated model.

    As far as I see, it is not available under the "stored results" of "dfuller". It can however be displayed using the option "regress" in "dfuller". It is then displayed in a table and has the name "_cons". However "_cons" cannot be saved or exported.

    Is there any possibility to save the "drift" parameter or would I have to manipulate the source code of "dfuller"?

    Thanks for help!

  • #2
    I think this can start you in a useful direction. The key insight is that along with the results returned by dfuller that are listed by
    Code:
    return list
    the estimates produced by the regression are still available as shown by
    Code:
    ereturn list
    Example:
    Code:
    webuse air2, clear
    dfuller air, regress
    ereturn list
    matrix b = e(b)
    scalar drift = b["y1","_cons"]
    display drift
    Code:
    . dfuller air, regress
    
    Dickey-Fuller test for unit root                   Number of obs   =       143
    
                                   ---------- Interpolated Dickey-Fuller ---------
                      Test         1% Critical       5% Critical      10% Critical
                   Statistic           Value             Value             Value
    ------------------------------------------------------------------------------
     Z(t)             -1.748            -3.496            -2.887            -2.577
    ------------------------------------------------------------------------------
    MacKinnon approximate p-value for Z(t) = 0.4065
    
    ------------------------------------------------------------------------------
           D.air |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             air |
             L1. |   -.041068    .023493    -1.75   0.083    -.0875122    .0053761
                 |
           _cons |    13.7055   7.133673     1.92   0.057    -.3972781    27.80829
    ------------------------------------------------------------------------------
    
    . ereturn list
    
    scalars:
                   e(rank) =  2
                   e(ll_0) =  -705.6387933373031
                     e(ll) =  -704.1057594990987
                   e(r2_a) =  .0142710546604324
                    e(rss) =  158355.9401162112
                    e(mss) =  3431.975967704871
                   e(rmse) =  33.51256143409272
                     e(r2) =  .0212128077966266
                      e(F) =  3.055828604163919
                   e(df_r) =  141
                   e(df_m) =  1
                      e(N) =  143
    
    macros:
                e(cmdline) : "regress D.air L1.air"
                  e(title) : "Linear regression"
              e(marginsok) : "XB default"
                    e(vce) : "ols"
                 e(depvar) : "D.air"
                    e(cmd) : "regress"
             e(properties) : "b V"
                e(predict) : "regres_p"
                  e(model) : "ols"
              e(estat_cmd) : "regress_estat"
    
    matrices:
                      e(b) :  1 x 2
                      e(V) :  2 x 2
    
    . matrix b = e(b)
    
    . scalar drift = b["y1","_cons"]
    
    . display drift
    13.705505
    Last edited by William Lisowski; 19 Jan 2020, 09:19.

    Comment


    • #3
      Thanks William! I receive the following error message using your code:
      Code:
      . dfuller air, regress
      Dickey-Fuller test for unit root                   Number of obs   =       143
      
                                     ---------- Interpolated Dickey-Fuller ---------
                        Test         1% Critical       5% Critical      10% Critical
                     Statistic           Value             Value             Value
      ------------------------------------------------------------------------------
       Z(t)             -1.748            -3.496            -2.887            -2.577
      ------------------------------------------------------------------------------
      MacKinnon approximate p-value for Z(t) = 0.4065
      
      ------------------------------------------------------------------------------
             D.air |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               air |
               L1. |   -.041068    .023493    -1.75   0.083    -.0875122    .0053761
                   |
             _cons |    13.7055   7.133673     1.92   0.057    -.3972781    27.80829
      ------------------------------------------------------------------------------
      
      .
      . ereturn list
      
      .
      . matrix b = e(b)
      last estimates not found
      r(301);
      
      .
      . scalar drift = b["y1","_cons"]
      b not found
      r(111);
      
      .
      . display drift
      drift not found
      r(111);
      [/QUOTE]

      What problem do I have?

      Comment


      • #4
        The problem you have is an oversight rather than insight on my part. It wasn't dfuller that left the regression results in memory - they were there from a previous regress I had run.

        However, having done
        Code:
        viewsource dfuller.ado
        I find an undocumented "certify" option that leaves the regression results intact as I had misled myself into believing they were. So with one change
        Code:
        webuse air2, clear
        dfuller air, regress certify
        matrix b = e(b)
        scalar drift = b["y1","_cons"]
        display drift
        the code should now work for you.
        Last edited by William Lisowski; 19 Jan 2020, 11:52.

        Comment


        • #5
          The output is now:

          Code:
          . dfuller air, regress certify
          
          Dickey-Fuller test for unit root                   Number of obs   =       143
          
                                         ---------- Interpolated Dickey-Fuller ---------
                            Test         1% Critical       5% Critical      10% Critical
                         Statistic           Value             Value             Value
          ------------------------------------------------------------------------------
           Z(t)             -1.748            -3.496            -2.887            -2.577
          ------------------------------------------------------------------------------
          MacKinnon approximate p-value for Z(t) = 0.4065
          
          ------------------------------------------------------------------------------
                 D.air |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   air |
                   L1. |   -.041068    .023493    -1.75   0.083    -.0875122    .0053761
                       |
                 _cons |    13.7055   7.133673     1.92   0.057    -.3972781    27.80829
          ------------------------------------------------------------------------------
          
          . 
          . matrix b = e(b)
          
          . 
          . scalar drift = b["y1","_cons"]
          matrix operators that return matrices not allowed in this context
          r(509);
          
          . 
          . display drift
          drift not found
          r(111);
          Should I perhaps use a Mata export to get the matrix value of the drift parameter?

          Comment


          • #6
            The matrices from ereturn and return are standard Stata matrices, not Mata matrices. See help matrix to understand them.

            I guess you're using a version earlier than Stata 16. Try the classic subscripting with column names (and dfuller only fits a single equation, a row number of 1 instead of a row name will do)
            Code:
            webuse air2, clear
            dfuller air, regress certify
            matrix b = e(b)
            scalar drift = b[1,colnumb(b,"_cons")]
            display drift
            For what it's worth to anyone else reading this, Stata 16 not only expanded the applicability of column name and row name subscripts, but also allows subscripts to be applied to e() and r() matrices. So on Stata 16, the following works, to my surprise and joy.
            Code:
            webuse air2, clear
            dfuller air, regress certify
            scalar drift = e(b)[1,"_cons"]
            display drift

            Comment


            • #7
              Indeed, I'm using Stata 15 and should update. Your code for Stata 15 works perfectly!

              Thanks a lot!
              Rene

              Comment

              Working...
              X