-------------
      name:  <unnamed>
       log:  E:\【计量经济学及stata】\陈强计量经济学及stata应用(网课+PPT+Data)\《计量经济学及Stata应用》Data-Finished-本科计量\自相关.smcl
  log type:  smcl
 opened on:  19 Jan 2024, 19:23:01

. use icecream.dta,clear

. tsset time


Time variable: time, 1   to 30


        Delta: 1 unit

. twoway connect consumption time, msymbol(circle) yaxis(1) || connect temp time, msymbol(triangle) yaxis(2)

. reg consumption temp price income

      Source |       SS           df       MS      Number of obs   =        30
-------------+----------------------------------   F(3, 26)        =     22.17
       Model |  .090250523         3  .030083508   Prob > F        =    0.0000
    Residual |  .035272835        26  .001356647   R-squared       =    0.7190
-------------+----------------------------------   Adj R-squared   =    0.6866
       Total |  .125523358        29  .004328392   Root MSE        =    .03683

-------------+----------------------------------------------------------------
  consumption | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        temp |    .0034584    .0004455      7.76    0.000      .0025426     .0043743
       price |   -1.044413     .834357     -1.25    0.222     -2.759458     .6706322
      income |    .0033078    .0011714      2.82    0.009      .0008999     .0057156
       _cons |    .1973149    .2702161      0.73    0.472     -.3581223      .752752
-------------+----------------------------------------------------------------

. predict e1,r

. twoway scatter e1 L.e1 || lfit e1 L.e1

. twoway scatter e1 L2.e1 || lfit e1 L2.e1

. ac e1

. estat bgodfrey

Breusch–Godfrey LM test for autocorrelation
-------------+-------------------------------------------------------------
    lags(p)  |          chi2               df                 Prob > chi2
-------------+-------------------------------------------------------------
       1     |          4.237               1                   0.0396
-------------+-------------------------------------------------------------
                        H0: no serial correlation

. estat bgodfrey,nomiss0

Breusch–Godfrey LM test for autocorrelation
-------------+-------------------------------------------------------------
    lags(p)  |          chi2               df                 Prob > chi2
-------------+-------------------------------------------------------------
       1     |          4.704               1                   0.0301
-------------+-------------------------------------------------------------
                        H0: no serial correlation

. wntestq e1

Portmanteau test for white noise
---------------------------------------
 Portmanteau (Q) statistic =    26.1974
 Prob > chi2(13)           =     0.0160

. corrgram e1

                                          -1       0       1 -1       0       1
 LAG       AC       PAC      Q     Prob>Q  [Autocorrelation]  [Partial autocor]
-------------------------------------------------------------------------------
1        0.3298   0.3969      3.6  0.0578          +--                +---
2        0.0362  -0.1681    3.645  0.1616          |                 -+
3        0.0111   0.0767   3.6494  0.3019          |                  |
4       -0.0934  -0.1483   3.9715  0.4099          |                 -+
5       -0.3186  -0.3565   7.8703  0.1635        --+                --+
6       -0.2058   0.0011   9.5645  0.1442         -+                  |
7       -0.2582  -0.4237   12.346  0.0897        --+               ---+
8       -0.1373  -0.0721   13.169  0.1062         -+                  |
9       -0.1035  -0.3300   13.658  0.1350          |                --+
10      -0.2378  -0.8928   16.372  0.0895         -+           -------+
11      -0.1193  -0.5017   17.091  0.1052          |              ----+
12       0.1923  -0.4590   19.064  0.0870          +-              ---+
13       0.3554   0.0493   26.197  0.0160          +--                |

. estat dwatson

Durbin–Watson d-statistic(  4,    30) =  1.021169

. newey consumption temp price income,lag(3)

Regression with Newey–West standard errors      Number of obs     =         30
Maximum lag = 3                                 F(  3,        26) =      27.63
                                                Prob > F          =     0.0000

-------------+----------------------------------------------------------------
             |             Newey–West
  consumption | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        temp |    .0034584    .0004002      8.64    0.000      .0026357     .0042811
       price |   -1.044413    .9772494     -1.07    0.295     -3.053178     .9643518
      income |    .0033078    .0013278      2.49    0.019      .0005783     .0060372
       _cons |    .1973149    .3378109      0.58    0.564     -.4970655     .8916952
-------------+----------------------------------------------------------------

. newey consumption temp price income,lag(6)

Regression with Newey–West standard errors      Number of obs     =         30
Maximum lag = 6                                 F(  3,        26) =      52.97
                                                Prob > F          =     0.0000

-------------+----------------------------------------------------------------
             |             Newey–West
  consumption | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        temp |    .0034584    .0003504      9.87    0.000      .0027382     .0041787
       price |   -1.044413    .9821798     -1.06    0.297     -3.063313     .9744864
      income |    .0033078      .00132      2.51    0.019      .0005945      .006021
       _cons |    .1973149    .3299533      0.60    0.555     -.4809139     .8755437
-------------+----------------------------------------------------------------

. prais consumption temp price income,corc

Iteration 0:  rho = 0.0000
Iteration 1:  rho = 0.4006
Iteration 2:  rho = 0.4008
Iteration 3:  rho = 0.4009
Iteration 4:  rho = 0.4009
Iteration 5:  rho = 0.4009
Iteration 6:  rho = 0.4009
Iteration 7:  rho = 0.4009

Cochrane–Orcutt AR(1) regression with iterated estimates

      Source |       SS           df       MS      Number of obs   =        29
-------------+----------------------------------   F(3, 25)        =     15.40
       Model |  .047040596         3  .015680199   Prob > F        =    0.0000
    Residual |  .025451894        25  .001018076   R-squared       =    0.6489
-------------+----------------------------------   Adj R-squared   =    0.6068
       Total |  .072492491        28  .002589018   Root MSE        =    .03191

-------------+----------------------------------------------------------------
  consumption | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        temp |    .0035584    .0005547      6.42    0.000       .002416     .0047008
       price |   -.8923963    .8108501     -1.10    0.282     -2.562373     .7775807
      income |    .0032027    .0015461      2.07    0.049      .0000186     .0063869
       _cons |    .1571479    .2896292      0.54    0.592     -.4393546     .7536504
-------------+----------------------------------------------------------------
         rho |   .4009256
-------------+----------------------------------------------------------------
Durbin–Watson statistic (original)    = 1.021169
Durbin–Watson statistic (transformed) = 1.548837

. prais consumption temp price income,nolog


Prais–Winsten AR(1) regression with iterated estimates

      Source |       SS           df       MS      Number of obs   =        30
-------------+----------------------------------   F(3, 26)        =     14.35
       Model |   .04494596         3  .014981987   Prob > F        =    0.0000
    Residual |  .027154354        26  .001044398   R-squared       =    0.6234
-------------+----------------------------------   Adj R-squared   =    0.5799
       Total |  .072100315        29  .002486218   Root MSE        =    .03232

-------------+----------------------------------------------------------------
  consumption | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        temp |    .0029541    .0007109      4.16    0.000      .0014929     .0044152
       price |   -1.048854     .759751     -1.38    0.179     -2.610545     .5128361
      income |   -.0008022    .0020458     -0.39    0.698     -.0050074     .0034029
       _cons |    .5870049    .2952699      1.99    0.057     -.0199311     1.193941
-------------+----------------------------------------------------------------
         rho |   .8002264
-------------+----------------------------------------------------------------
Durbin–Watson statistic (original)    = 1.021169
Durbin–Watson statistic (transformed) = 1.846795

. reg consumption temp L.temp price income

      Source |       SS           df       MS      Number of obs   =        29
-------------+----------------------------------   F(4, 24)        =     28.98
       Model |  .103387183         4  .025846796   Prob > F        =    0.0000
    Residual |  .021406049        24  .000891919   R-squared       =    0.8285
-------------+----------------------------------   Adj R-squared   =    0.7999
       Total |  .124793232        28  .004456901   Root MSE        =    .02987

-------------+----------------------------------------------------------------
  consumption | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        temp |
         --. |    .0053321    .0006704      7.95    0.000      .0039484     .0067158
         L1. |   -.0022039    .0007307     -3.02    0.006     -.0037119    -.0006959
             |
       price |   -.8383021    .6880205     -1.22    0.235     -2.258307     .5817025
      income |    .0028673    .0010533      2.72    0.012      .0006934     .0050413
       _cons |    .1894822    .2323169      0.82    0.423     -.2899963     .6689607
-------------+----------------------------------------------------------------

. estat bgodfrey

Breusch–Godfrey LM test for autocorrelation
-------------+-------------------------------------------------------------
    lags(p)  |          chi2               df                 Prob > chi2
-------------+-------------------------------------------------------------
       1     |          0.120               1                   0.7292
-------------+-------------------------------------------------------------
                        H0: no serial correlation

. estat dwatson

Durbin–Watson d-statistic(  5,    29) =  1.582166

. log close
      name:  <unnamed>
       log:  E:\【计量经济学及stata】\陈强计量经济学及stata应用(网课+PPT+Data)\《计量经济学及Stata应用》Data-Finished-本科计量\自相关.smcl
  log type:  smcl
 closed on:  19 Jan 2024, 19:26:44
-------------