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

.
. use gdp_china.dta,clear

.
. tsset year


Time variable: year, 1978   to 2013


        Delta: 1 unit

.
. tsline y,xlabel(1980(10)2010)

.
. gen lny=log(y)
variable lny already defined
r(110);

.
. tsline lny,xlabel(1980(10)2010)

.
. gen dlny=d.lny
variable dlny already defined
r(110);

.
. tsline dlny,xlabel(1980(10)2010)

.
. gen g=(y-l.y)/l.y
(1 missing value generated)

.
. tsline dlny g,xlabel(1980(10)2010) lpattern(dash)

.
. corrgram dlny

                                          -1       0       1 -1       0       1
 LAG       AC       PAC      Q     Prob>Q  [Autocorrelation]  [Partial autocor]
-------------------------------------------------------------------------------
1        0.5360   0.5454   10.943  0.0009          +----              +----
2       -0.0298  -0.4515   10.978  0.0041          |               ---+
3       -0.2579   0.0205   13.669  0.0034        --+                  |
4       -0.3405  -0.3311   18.514  0.0010        --+                --+
5       -0.4687  -0.3671   27.998  0.0000       ---+                --+
6       -0.4371  -0.3092   36.531  0.0000       ---+                --+
7       -0.1425  -0.0790    37.47  0.0000         -+                  |
8        0.1774  -0.0418    38.98  0.0000          +-                 |
9        0.3220  -0.1600   44.143  0.0000          +--               -+
10       0.2768  -0.0670   48.113  0.0000          +--                |
11       0.1179  -0.1722   48.863  0.0000          |                 -+
12       0.0341  -0.0569   48.928  0.0000          |                  |
13      -0.0123  -0.2000   48.937  0.0000          |                 -+
14      -0.0322  -0.0378   49.001  0.0000          |                  |
15      -0.0743  -0.0851   49.359  0.0000          |                  |

.
. ac dlny,lags(20)

.
. reg dlny l.dlny if year<2013,r

Linear regression                               Number of obs     =         33
                                                F(1, 31)          =      12.99
                                                Prob > F          =     0.0011
                                                R-squared         =     0.2879
                                                Root MSE          =     .02147

-------------+----------------------------------------------------------------
             |               Robust
         dlny | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dlny |
         L1. |    .5362727    .1487888      3.60    0.001      .2328159     .8397295
             |
       _cons |    .0437698    .0144049      3.04    0.005      .0143908     .0731488
-------------+----------------------------------------------------------------

.
. predict dlny1
(option xb assumed; fitted values)
(2 missing values generated)

.
. list dlny1 if year==2013

     +---------+
     |   dlny1 |
     +---------+
 36. | .083309 |
     +---------+

.
. dis exp(lny[35]+dlny1[36])
95985.114

.
. quietly reg dlny l.dlny if year<2013,r

.
. estat ic

Akaike's information criterion and Bayesian information criterion

-------------+---------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
.            |         33   75.35938   80.96115       2  -157.9223  -154.9293
-------------+---------------------------------------------------------------


Note: BIC uses N = number of observations. See [R] IC note  .


.
. reg dlny l(1/2).dlny if year<2013,r

Linear regression                               Number of obs     =         32
                                                F(2, 29)          =      17.51
                                                Prob > F          =     0.0000
                                                R-squared         =     0.4234
                                                Root MSE          =     .01979

-------------+----------------------------------------------------------------
             |               Robust
         dlny | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dlny |
         L1. |    .7711595    .1304462      5.91    0.000      .5043671     1.037952
         L2. |   -.4487175    .1530057     -2.93    0.007     -.7616494    -.1357857
             |
       _cons |    .0641134    .0128498      4.99    0.000      .0378326     .0903943
-------------+----------------------------------------------------------------

.
. estat ic

Akaike's information criterion and Bayesian information criterion

-------------+---------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
.            |         32   72.88943   81.69936       3  -157.3987  -153.0015
-------------+---------------------------------------------------------------


Note: BIC uses N = number of observations. See [R] IC note  .


.
. reg dlny l(1/3).dlny if year<2013,r

Linear regression                               Number of obs     =         31
                                                F(3, 27)          =      12.82
                                                Prob > F          =     0.0000
                                                R-squared         =     0.4459
                                                Root MSE          =     .01907

-------------+----------------------------------------------------------------
             |               Robust
         dlny | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        dlny |
         L1. |    .7557034    .1261359      5.99    0.000      .4968939     1.014513
         L2. |   -.4943798    .1785691     -2.77    0.010     -.8607733    -.1279864
         L3. |    .0204783    .1711994      0.12    0.906     -.3307938     .3717504
             |
       _cons |    .0692315    .0154137      4.49    0.000      .0376052     .1008579
-------------+----------------------------------------------------------------

.
. estat ic

Akaike's information criterion and Bayesian information criterion

-------------+---------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
.            |         31   71.75641   80.90811       4  -153.8162  -148.0803
-------------+---------------------------------------------------------------


Note: BIC uses N = number of observations. See [R] IC note  .


.
. quietly reg dlny l(1/2).dlny if year<2013,r

.
. predict dlny2
(option xb assumed; fitted values)
(3 missing values generated)

.
. dis exp(lny[35]+dlny2[36])
95769.998

.
. dis y[36]-exp(lny[35]+dlny2[36])
-680.78688

.
. use border.dta, clear

.
. tsset decade


Time variable: decade, -22   to 190


        Delta: 1 unit

.
. reg border l(1/2).border l.drought diff age rival wall unified,r

Linear regression                               Number of obs     =        211
                                                F(8, 202)         =    2040.71
                                                Prob > F          =     0.0000
                                                R-squared         =     0.9854
                                                Root MSE          =     1.0889

-------------+----------------------------------------------------------------
             |               Robust
       border | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
      border |
         L1. |    1.518284     .133108     11.41    0.000      1.255825     1.780744
         L2. |   -.5586965    .1278243     -4.37    0.000     -.8107376    -.3066555
             |
     drought |
         L1. |   -.6333046    .3009855     -2.10    0.037     -1.226781    -.0398281
             |
        diff |   -.0069699    .0028159     -2.48    0.014     -.0125222    -.0014175
         age |   -.0264399    .0123658     -2.14    0.034     -.0508224    -.0020573
       rival |      .34148    .1455019      2.35    0.020      .0545827     .6283772
        wall |    .7339998    .2203202      3.33    0.001      .2995774     1.168422
     unified |    .4078538    .2230656      1.83    0.069     -.0319819     .8476894
       _cons |    .8189595     .472603      1.73    0.085     -.1129085     1.750827
-------------+----------------------------------------------------------------

.
. dis -.6333046/(1-1.518284+.5586965)
-15.671008

.
. use gdp_china.dta,clear

.
. varbasic dlny if year<2013,lags(1) irf

Vector autoregression

 Sample: 1980 thru 2012                         Number of obs     =         33
Log likelihood =   80.96115                     AIC               =  -4.785524
FPE            =   .0004889                     HQIC              =  -4.755008
Det(Sigma_ml)  =   .0004331                     SBIC              =  -4.694827

 Equation           Parms      RMSE     R-sq      chi2     P>chi2
 ----------------------------------------------------------------
 dlny                  2    .021471   0.2879   13.34017   0.0003
 ----------------------------------------------------------------

-------------+----------------------------------------------------------------
         dlny | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
dlny         |
        dlny |
         L1. |    .5362727    .1468267      3.65    0.000      .2484976     .8240478
             |
       _cons |    .0437698    .0143197      3.06    0.002      .0157037      .071836
-------------+----------------------------------------------------------------

.
. varbasic dlny if year<2013,irf

Vector autoregression

 Sample: 1981 thru 2012                         Number of obs     =         32
Log likelihood =   81.69936                     AIC               =   -4.91871
FPE            =   .0004282                     HQIC              =  -4.873162
Det(Sigma_ml)  =   .0003548                     SBIC              =  -4.781298

 Equation           Parms      RMSE     R-sq      chi2     P>chi2
 ----------------------------------------------------------------
 dlny                  3    .019785   0.4234   23.49854   0.0000
 ----------------------------------------------------------------

-------------+----------------------------------------------------------------
         dlny | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
dlny         |
        dlny |
         L1. |    .7711595    .1593746      4.84    0.000       .458791     1.083528
         L2. |   -.4487175     .157661     -2.85    0.004     -.7577275    -.1397076
             |
       _cons |    .0641134    .0148348      4.32    0.000      .0350377     .0931892
-------------+----------------------------------------------------------------

.
. use macro_swatson.dta,clear

.
. tsline dinf unem,lpattern(solid dash)

.
. varsoc dinf unem

Lag-order selection criteria

   Sample: 1961q4 thru 2002q1                              Number of obs = 162
  +-----+---------------------------------------------------------------------+
  | Lag |    LL      LR      df    p     FPE       AIC      HQIC      SBIC    |
  +-----+---------------------------------------------------------------------+
  |   0 |  881.581                     6.6e-08   -10.859  -10.8435  -10.8209  |
  |   1 |   1141.4   519.63    4  0.000  2.8e-09  -14.0172  -13.9708  -13.9029 |
  |   2 |  1213.86   144.93 *    4  0.000  1.2e-09 *  -14.8625 *  -14.7851 *  -14.6719 * |
  |   3 |  1217.32   6.9224    4  0.140  1.2e-09  -14.8558  -14.7475   -14.589 |
  |   4 |  1219.45   4.2537    4  0.373  1.2e-09  -14.8327  -14.6934  -14.4896 |
  +-----+---------------------------------------------------------------------+
   * optimal lag
   Endogenous: dinf unem
    Exogenous: _cons

.
. var dinf unem,lags(1/2)

Vector autoregression

 Sample: 1961q2 thru 2002q1                     Number of obs     =        164
Log likelihood =   1224.456                     AIC               =  -14.81044
FPE            =   1.27e-09                     HQIC              =  -14.73371
Det(Sigma_ml)  =   1.12e-09                     SBIC              =  -14.62143

 Equation           Parms      RMSE     R-sq      chi2     P>chi2
 ----------------------------------------------------------------
 dinf                  5    .013815   0.3621   93.11047   0.0000
 unem                  5    .002508   0.9731   5926.554   0.0000
 ----------------------------------------------------------------

-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
dinf         |
        dinf |
         L1. |   -.4709436    .0676118     -6.97    0.000     -.6034603     -.338427
         L2. |    -.401031    .0654944     -6.12    0.000     -.5293976    -.2726644
             |
        unem |
         L1. |    -2.24205    .3371897     -6.65    0.000      -2.90293     -1.58117
         L2. |     2.03417    .3356694      6.06    0.000       1.37627      2.69207
             |
       _cons |    .0123764    .0045265      2.73    0.006      .0035047     .0212482
-------------+----------------------------------------------------------------
unem         |
        dinf |
         L1. |    .0305223    .0122746      2.49    0.013      .0064645       .05458
         L2. |   -.0113172    .0118902     -0.95    0.341     -.0346216     .0119871
             |
        unem |
         L1. |    1.638031    .0612152     26.76    0.000      1.518051      1.75801
         L2. |   -.6725807    .0609392    -11.04    0.000     -.7920194    -.5531421
             |
       _cons |    .0020139    .0008218      2.45    0.014      .0004032     .0036245
-------------+----------------------------------------------------------------

.
. varwle

   Equation: dinf
  +-----+------------------------------+
  | lag |    chi2      df  Prob > chi2 |
  +-----+------------------------------+
  |   1 |  72.72164     2     0.000    |
  |   2 |   72.9294     2     0.000    |
  +-----+------------------------------+

   Equation: unem
  +-----+------------------------------+
  | lag |    chi2      df  Prob > chi2 |
  +-----+------------------------------+
  |   1 |  741.8916     2     0.000    |
  |   2 |  123.1287     2     0.000    |
  +-----+------------------------------+

   Equation: All
  +-----+------------------------------+
  | lag |    chi2      df  Prob > chi2 |
  +-----+------------------------------+
  |   1 |  796.2418     4     0.000    |
  |   2 |  187.9991     4     0.000    |
  +-----+------------------------------+

.
. varlmar

   Lagrange-multiplier test
  +------+-------------------------------+
  | lag  |      chi2    df   Prob > chi2 |
  +------+-------------------------------+
  |   1  |    7.3130     4     0.12024   |
  |   2  |    5.0645     4     0.28074   |
  +------+-------------------------------+
   H0: no autocorrelation at lag order

.
. varstable,graph

   Eigenvalue stability condition
  +--------------------------+-------------+
  |        Eigenvalue        |   Modulus   |
  +--------------------------+-------------+
  |     .82182               |    .82182   |
  |   .7970223               |   .797022   |
  |  -.2258777 +  .6292178i  |   .668533   |
  |  -.2258777 -  .6292178i  |   .668533   |
  +--------------------------+-------------+
   All the eigenvalues lie inside the unit circle.
   VAR satisfies stability condition.

.
. vargranger

   Granger causality Wald tests
  +--------------------------------------+---------------------------+
  |          Equation           Excluded |   chi2     df Prob > chi2 |
  +--------------------------------------+---------------------------+
  |              dinf               unem |  48.123     2    0.000    |
  |              dinf                ALL |  48.123     2    0.000    |
  +--------------------------------------+---------------------------+
  |              unem               dinf |   9.009     2    0.011    |
  |              unem                ALL |   9.009     2    0.011    |
  +--------------------------------------+---------------------------+

.
. irf create iu, set(macro)
(file macro.irf created)
(file macro.irf now active)
(file macro.irf updated)

.
. irf graph oirf,yline(0)

.
. irf create ui, order(unem dinf)
(file macro.irf updated)

.
. irf graph oirf,i(unem) r(dinf) yline(0)

.
. irf graph oirf,i(dinf) r(unem) yline(0)

.
. varbasic dinf unem if quarter<tq(1999q1),lags(1/2) nograph

Vector autoregression

 Sample: 1961q2 thru 1998q4                     Number of obs     =        151
Log likelihood =   1118.534                     AIC               =  -14.68256
FPE            =   1.44e-09                     HQIC              =  -14.60139
Det(Sigma_ml)  =   1.26e-09                     SBIC              =  -14.48274

 Equation           Parms      RMSE     R-sq      chi2     P>chi2
 ----------------------------------------------------------------
 dinf                  5    .014258   0.3673   87.65165   0.0000
 unem                  5    .002585   0.9705   4971.522   0.0000
 ----------------------------------------------------------------

-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
dinf         |
        dinf |
         L1. |   -.4718995    .0702018     -6.72    0.000     -.6094925    -.3343064
         L2. |   -.4066509    .0682215     -5.96    0.000     -.5403626    -.2729393
             |
        unem |
         L1. |   -2.279801    .3502631     -6.51    0.000     -2.966304    -1.593298
         L2. |    2.050438    .3471149      5.91    0.000      1.370105     2.730771
             |
       _cons |    .0139506     .005028      2.77    0.006      .0040959     .0238053
-------------+----------------------------------------------------------------
unem         |
        dinf |
         L1. |    .0302607     .012728      2.38    0.017      .0053143     .0552072
         L2. |   -.0120022     .012369     -0.97    0.332     -.0362449     .0122405
             |
        unem |
         L1. |    1.636296    .0635048     25.77    0.000      1.511829     1.760763
         L2. |   -.6760615     .062934    -10.74    0.000     -.7994099    -.5527131
             |
       _cons |    .0023965    .0009116      2.63    0.009      .0006098     .0041832
-------------+----------------------------------------------------------------

.
. fcast compute f_,step(10)

.
. fcast graph f_dinf f_unem,observed lpattern(dash)

.
. clear

.
. set obs 100


Number of observations (_N) was 0,
now 100.


.
. gen t=_n

.
. gen t2=t^2

.
. corr t t2
(obs=100)

             |        t       t2
-------------+------------------
           t |   1.0000
          t2 |   0.9689   1.0000


.
. use gdp_china.dta,clear

.
. gen t=_n

.
. reg lny l(1/2).lny t if year<2013,r

Linear regression                               Number of obs     =         33
                                                F(3, 29)          =   38047.85
                                                Prob > F          =     0.0000
                                                R-squared         =     0.9997
                                                Root MSE          =     .01627

-------------+----------------------------------------------------------------
             |               Robust
          lny | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
         lny |
         L1. |    1.302829    .1150665     11.32    0.000      1.067491     1.538166
         L2. |   -.7357654    .0967217     -7.61    0.000     -.9335835    -.5379473
             |
           t |    .0411649    .0092175      4.47    0.000       .022313     .0600168
       _cons |    3.473641    .7552359      4.60    0.000      1.929011     5.018272
-------------+----------------------------------------------------------------

.
. predict lny3
(option xb assumed; fitted values)
(2 missing values generated)

.
. dis exp(lny3[36])
95597.887

.
. dis y[36]-exp(lny3[36])
-508.67625

.
. use airpassengers.dta,clear

.
. tsset time


Time variable: time, 1949m1   to 1960m12


        Delta: 1 month

.
. tsline airpassengers

.
. gen month=month((dofm(time)))

.
. tab month,gen(m)

      month |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |         12        8.33        8.33
          2 |         12        8.33       16.67
          3 |         12        8.33       25.00
          4 |         12        8.33       33.33
          5 |         12        8.33       41.67
          6 |         12        8.33       50.00
          7 |         12        8.33       58.33
          8 |         12        8.33       66.67
          9 |         12        8.33       75.00
         10 |         12        8.33       83.33
         11 |         12        8.33       91.67
         12 |         12        8.33      100.00
------------+-----------------------------------
      Total |        144      100.00

.
. reg airpassengers m2-m12

      Source |       SS           df       MS      Number of obs   =       144
-------------+----------------------------------   F(11, 132)      =      1.42
       Model |  218382.243        11  19852.9312   Prob > F        =    0.1690
    Residual |  1839661.92       132  13936.8327   R-squared       =    0.1061
-------------+----------------------------------   Adj R-squared   =    0.0316
       Total |  2058044.16       143  14391.9172   Root MSE        =    118.05

-------------+----------------------------------------------------------------
 airpasseng~s | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
          m2 |       -6.75    48.19549     -0.14    0.889     -102.0854     88.58545
          m3 |    28.41667    48.19549      0.59    0.556     -66.91878     123.7521
          m4 |    25.33333    48.19549      0.53    0.600     -70.00211     120.6688
          m5 |    30.08333    48.19549      0.62    0.534     -65.25211     125.4188
          m6 |    69.91667    48.19549      1.45    0.149     -25.41878     165.2521
          m7 |    109.5833    48.19549      2.27    0.025      14.24789     204.9188
          m8 |    109.3333    48.19549      2.27    0.025      13.99789     204.6688
          m9 |    60.66667    48.19549      1.26    0.210     -34.66878     156.0021
         m10 |    24.83333    48.19549      0.52    0.607     -70.50211     120.1688
         m11 |   -8.916667    48.19549     -0.19    0.854     -104.2521     86.41878
         m12 |    20.08333    48.19549      0.42    0.678     -75.25211     115.4188
       _cons |      241.75    34.07936      7.09    0.000      174.3377     309.1623
-------------+----------------------------------------------------------------

.
. predict air_sa,r

.
. sum airpassengers

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
airpasseng~s |        144    280.2986    119.9663        104        622

.
. gen airpassengers_sa = air_sa+r(mean)

.
. tsline airpassengers_sa airpassengers,lpattern(dash)

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