-------------
      name:  <unnamed>
       log:  E:\【计量经济学及stata】\陈强计量经济学及stata应用(网课+PPT+Data)\《计量经济学及Stata应用》Data-Finished-本科计量\第14章.smcl
  log type:  smcl
 opened on:  26 Jan 2024, 00:54:43

. program randwalk,rclass
  1.
. drop _all
  2.
. set obs 1000
  3.
. gen eps=rnormal()
  4.
. gen y=sum(eps)
  5.
. gen t=_n
  6.
. tsset t
  7.
. reg y L.y
  8.
. return scalar b1=_b[L.y]
  9.
. end

.
. simulate beta=r(b1),seed(10101) reps(1000):randwalk


Command:  randwalk


beta:  r(b1)


Simulations (1,000): .........10.........20.........30.........40.........50.........60.........70.........80.........90.........100.........110.........120.........130.........140.........150.........160.........170.........180.........190.........200.........210.........220.........230.........240.........250.........260.........270.........280.........290.........300.........310.........320.........330.........340.........350.........360.........370.........380.........390.........400.........410.........420.........430.........440.........450.........460.........470.........480.........490.........500.........510.........520.........530.........540.........550.........560.........570.........580.........590.........600.........610.........620.........630.........640.........650.........660.........670.........680.........690.........700.........710.........720.........730.........740.........750.........760.........770.........780.........790.........800.........810.........820.........830.........840.........850.........860.........870.........880.........890.........900.........910.........920.........930.........940.........950.........960.........970.........980.........990.........1,000 done

.
. kdensity beta

.
. clear

.
. drop _all

.
. set obs 10000


Number of observations (_N) was 0,
now 10,000.


.
. set seed 1234

.
. gen u=rnormal()

.
. gen y=sum(u)

.
. set seed 12345

.
. gen v=rnormal()

.
. gen x=sum(v)

.
. reg y x

      Source |       SS           df       MS      Number of obs   =    10,000
-------------+----------------------------------   F(1, 9998)      =    866.95
       Model |  2406934.55         1  2406934.55   Prob > F        =    0.0000
    Residual |  27757621.9     9,998  2776.31745   R-squared       =    0.0798
-------------+----------------------------------   Adj R-squared   =    0.0797
       Total |  30164556.4     9,999  3016.75732   Root MSE        =    52.691

-------------+----------------------------------------------------------------
            y | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           x |   -.4000392    .0135864    -29.44    0.000     -.4266713    -.3734071
       _cons |   -55.43203    1.104488    -50.19    0.000     -57.59705    -53.26701
-------------+----------------------------------------------------------------

.
. reg u v

      Source |       SS           df       MS      Number of obs   =    10,000
-------------+----------------------------------   F(1, 9998)      =      0.49
       Model |  .500659016         1  .500659016   Prob > F        =    0.4819
    Residual |  10121.5297     9,998  1.01235544   R-squared       =    0.0000
-------------+----------------------------------   Adj R-squared   =   -0.0001
       Total |  10122.0304     9,999  1.01230427   Root MSE        =    1.0062

-------------+----------------------------------------------------------------
            u | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           v |   -.0070983    .0100937     -0.70    0.482     -.0268841     .0126874
       _cons |    -.009079    .0100624     -0.90    0.367     -.0288033     .0106452
-------------+----------------------------------------------------------------

.
. gen t=_n

.
. line y x t,lpattern(dash)

.
. use nelson_plosser.dta,clear

.
. tsline lrgnp lun if year>=1890,lp(dash) xlabel(1890(10)1970)

.
. dfuller lrgnp,trend

Dickey–Fuller test for unit root           Number of obs  = 61
Variable: lrgnp                            Number of lags = 0

H0: Random walk with or without drift

                                       Dickey–Fuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)            -2.026       -4.126       -3.489       -3.173
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.5871.

.
. di 12*(62/100)^(1/4)
10.648273

.
. dfuller lrgnp,lags(9) trend reg

Augmented Dickey–Fuller test for unit root

Variable: lrgnp                            Number of obs  = 52
                                           Number of lags = 9

H0: Random walk with or without drift

                                       Dickey–Fuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)            -2.308       -4.146       -3.498       -3.179
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.4296.

Regression table
-------------+----------------------------------------------------------------
      D.lrgnp | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
       lrgnp |
         L1. |   -.2431874    .1053744     -2.31    0.026      -.456157    -.0302179
         LD. |    .4268154    .1533028      2.78    0.008      .1169789      .736652
        L2D. |    .1299825    .1591474      0.82    0.419     -.1916663     .4516314
        L3D. |    .0148792    .1601745      0.09    0.926     -.3088455     .3386039
        L4D. |    .0074853    .1591925      0.05    0.963     -.3142547     .3292252
        L5D. |   -.0628515    .1517327     -0.41    0.681     -.3695147     .2438117
        L6D. |    .1135881    .1488912      0.76    0.450     -.1873321     .4145084
        L7D. |    .1157849    .1470971      0.79    0.436     -.1815095     .4130792
        L8D. |   -.0360994    .1474121     -0.24    0.808     -.3340302     .2618315
        L9D. |   -.1339387    .1441335     -0.93    0.358     -.4252433      .157366
             |
      _trend |    .0083664     .003355      2.49    0.017      .0015856     .0151471
       _cons |    1.091761    .4663261      2.34    0.024      .1492807     2.034241
-------------+----------------------------------------------------------------

.
. dfuller lrgnp,lags(1) trend reg

Augmented Dickey–Fuller test for unit root

Variable: lrgnp                            Number of obs  = 60
                                           Number of lags = 1

H0: Random walk with or without drift

                                       Dickey–Fuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)            -2.994       -4.128       -3.490       -3.174
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.1338.

Regression table
-------------+----------------------------------------------------------------
      D.lrgnp | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
       lrgnp |
         L1. |   -.1753423    .0585665     -2.99    0.004     -.2926651    -.0580195
         LD. |    .4188865    .1209448      3.46    0.001      .1766048     .6611681
             |
      _trend |    .0056465    .0018615      3.03    0.004      .0019174     .0093757
       _cons |    .8134145    .2679888      3.04    0.004      .2765684     1.350261
-------------+----------------------------------------------------------------

.
. use macro_3e.dta,clear

.
. tsset time


Time variable: time, 1957q1   to 2005q1


        Delta: 1 quarter

.
. tsline fygm3 fygt1,lpattern(dash)

.
. use mpyr.dta,clear

.
. tsline logmr logy r,lpattern(solid dash shortdash) xlabel(1900(10)1990)

.
. varsoc logmr logy r

Lag-order selection criteria

   Sample: 1904 thru 1989                                   Number of obs = 86
  +-----+---------------------------------------------------------------------+
  | Lag |    LL      LR      df    p     FPE       AIC      HQIC      SBIC    |
  +-----+---------------------------------------------------------------------+
  |   0 | -251.056                     .073876   5.90827   5.94272   5.99388  |
  |   1 |  132.578   767.27    9  0.000  .000012  -2.80415  -2.66632  -2.46168 * |
  |   2 |  148.293   31.429    9  0.000   .00001 *  -2.96029 *   -2.7191 *  -2.36098 |
  |   3 |  151.979   7.3723    9  0.598  .000012  -2.83672  -2.49215  -1.98055 |
  |   4 |  162.506   21.054 *    9  0.012  .000011  -2.87222  -2.42429  -1.75921 |
  +-----+---------------------------------------------------------------------+
   * optimal lag
   Endogenous: logmr logy r
    Exogenous: _cons

.
. vecrank logmr logy r,lags(2) trend(trend) max

Johansen tests for cointegration
Trend: Linear                              Number of obs  = 88
Sample: 1902 thru 1989                     Number of lags = 2
--------------------------------------------------------------
                                                      Critical
Maximum                                        Trace     value
   rank  Params           LL  Eigenvalue   statistic        5%
      0      15    138.03791           .     46.3731     34.55
      1      20    153.13651     0.29047     16.1759*    18.17
      2      23    160.58579     0.15575      1.2773      3.74
      3      24    161.22445     0.01441
--------------------------------------------------------------
                                                      Critical
Maximum                        ------Eigenvalue-----     value
   rank  Params           LL                 Maximum        5%
      0      15    138.03791           .     30.1972     23.78
      1      20    153.13651     0.29047     14.8985     16.87
      2      23    160.58579     0.15575      1.2773      3.74
      3      24    161.22445     0.01441
--------------------------------------------------------------
* selected rank

.
. vec logmr logy r,lags(2) rank(1)

Vector error-correction model

 Sample: 1902 thru 1989                         Number of obs     =         88
                                                AIC               =  -3.037506
Log likelihood =  150.6503                      HQIC              =    -2.8447
Det(Sigma_ml)  =  6.54e-06                      SBIC              =   -2.55893

 Equation           Parms      RMSE     R-sq      chi2     P>chi2
 ----------------------------------------------------------------
 D_logmr               5    .050841   0.2758   31.61646   0.0000
 D_logy                5    .056773   0.3483   44.35204   0.0000
 D_r                   5     1.1287   0.2133   22.50845   0.0004
 ----------------------------------------------------------------

-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
D_logmr      |
        _ce1 |
         L1. |   -.0533601    .0410678     -1.30    0.194     -.1338515     .0271314
             |
       logmr |
         LD. |    .2079032    .1107256      1.88    0.060     -.0091149     .4249214
             |
        logy |
         LD. |    .0086587     .101984      0.08    0.932     -.1912263     .2085438
             |
           r |
         LD. |   -.0063968    .0052854     -1.21    0.226     -.0167559     .0039624
             |
       _cons |    .0186333    .0064766      2.88    0.004      .0059393     .0313273
-------------+----------------------------------------------------------------
D_logy       |
        _ce1 |
         L1. |    .0298268    .0458591      0.65    0.515     -.0600554      .119709
             |
       logmr |
         LD. |    .2666361    .1236437      2.16    0.031      .0242989     .5089733
             |
        logy |
         LD. |    .2330244    .1138823      2.05    0.041      .0098191     .4562296
             |
           r |
         LD. |   -.0145323     .005902     -2.46    0.014     -.0261001    -.0029646
             |
       _cons |    .0157173    .0072323      2.17    0.030      .0015424     .0298923
-------------+----------------------------------------------------------------
D_r          |
        _ce1 |
         L1. |   -3.482578    .9117297     -3.82    0.000     -5.269536    -1.695621
             |
       logmr |
         LD. |    2.663613    2.458173      1.08    0.279     -2.154318     7.481544
             |
        logy |
         LD. |    .6533844    2.264106      0.29    0.773     -3.784182      5.09095
             |
           r |
         LD. |     .294868    .1173386      2.51    0.012      .0648885     .5248475
             |
       _cons |   -.0001509    .1437852     -0.00    0.999     -.2819648      .281663
-------------+----------------------------------------------------------------

Cointegrating equations

 Equation           Parms    chi2     P>chi2
 -------------------------------------------
 _ce1                  2  794.1155   0.0000
 -------------------------------------------

Identification:  beta is exactly identified

                 Johansen normalization restriction imposed
-------------+----------------------------------------------------------------
         beta | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
_ce1         |
       logmr |           1           .         .        .             .            .
        logy |   -.9754246    .0346169    -28.18    0.000     -1.043273    -.9075767
           r |    .1124051    .0097191     11.57    0.000       .093356     .1314542
       _cons |    .7299535           .         .        .             .            .
-------------+----------------------------------------------------------------

.
. veclmar

   Lagrange-multiplier test
  +------+-------------------------------+
  | lag  |      chi2    df   Prob > chi2 |
  +------+-------------------------------+
  |   1  |    6.6260     9     0.67599   |
  |   2  |   12.5541     9     0.18384   |
  +------+-------------------------------+
   H0: no autocorrelation at lag order

.
. vecstable,graph

   Eigenvalue stability condition
  +--------------------------+-------------+
  |        Eigenvalue        |   Modulus   |
  +--------------------------+-------------+
  |          1               |         1   |
  |          1               |         1   |
  |   .4092107 +  .4061819i  |   .576574   |
  |   .4092107 -  .4061819i  |   .576574   |
  |   .2217304 + .07266624i  |   .233334   |
  |   .2217304 - .07266624i  |   .233334   |
  +--------------------------+-------------+
   The VECM specification imposes 2 unit moduli.

.
. reg logmr logy r

      Source |       SS           df       MS      Number of obs   =        90
-------------+----------------------------------   F(2, 87)        =   1169.93
       Model |   41.216226         2   20.608113   Prob > F        =    0.0000
    Residual |  1.53248421        87  .017614761   R-squared       =    0.9642
-------------+----------------------------------   Adj R-squared   =    0.9633
       Total |  42.7487102        89  .480322587   Root MSE        =    .13272

-------------+----------------------------------------------------------------
        logmr | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        logy |    .9418376    .0196178     48.01    0.000      .9028451     .9808302
           r |   -.0832229    .0053829    -15.46    0.000     -.0939219    -.0725239
       _cons |   -.7737089    .0426886    -18.12    0.000     -.8585572    -.6888606
-------------+----------------------------------------------------------------

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