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

. use grilic.dta,clear

.
. qui reg lnw s expr tenure smsa rns

.
. estat ovtest

Ramsey RESET test for omitted variables
Omitted: Powers of fitted values of lnw

H0: Model has no omitted variables

F(3, 749)   = 1.51
Prob > F   = 0.2114

.
. estat ovtest,rhs

Ramsey RESET test for omitted variables
Omitted: Powers of independent variables

H0: Model has no omitted variables

F(9, 743)   = 2.03
Prob > F   = 0.0336

.
. gen expr2 = expr^2

.
. reg lnw s expr expr2 tenure smsa rns

      Source |       SS           df       MS      Number of obs   =       758
-------------+----------------------------------   F(6, 751)       =     69.65
       Model |  49.7985818         6  8.29976364   Prob > F        =    0.0000
    Residual |   89.487568       751   .11915788   R-squared       =    0.3575
-------------+----------------------------------   Adj R-squared   =    0.3524
       Total |   139.28615       757  .183997556   Root MSE        =    .34519

-------------+----------------------------------------------------------------
          lnw | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           s |    .1029839    .0058299     17.66    0.000      .0915391     .1144287
        expr |    .0018351    .0157708      0.12    0.907     -.0291249     .0327951
       expr2 |    .0051819    .0020645      2.51    0.012       .001129     .0092348
      tenure |     .037085    .0077374      4.79    0.000      .0218954     .0522746
        smsa |    .1419045    .0279979      5.07    0.000       .086941     .1968679
         rns |   -.0843448    .0286965     -2.94    0.003     -.1406797    -.0280098
       _cons |    4.119327    .0850277     48.45    0.000      3.952407     4.286247
-------------+----------------------------------------------------------------

.
. twoway function VIF =1/(1-x),xtitle(R2) xline(0.9,lp(dash)) yline(10,lp(dash)) xlabel(0.1(0.1)1) ylabel(10 100 200 300)

.
. use grilic.dta,clear

.
. qui reg lnw s expr tenure smsa rns

.
. estat vif

    Variable |       VIF       1/VIF
-------------+----------------------
        expr |      1.12    0.893267
           s |      1.07    0.930295
      tenure |      1.06    0.944083
        smsa |      1.04    0.964256
         rns |      1.03    0.970508
-------------+----------------------
    Mean VIF |      1.06

.
. gen s2 = s^2

.
. reg lnw s s2 e expr tenure smsa rns


note: expr omitted because of collinearity.


      Source |       SS           df       MS      Number of obs   =       758
-------------+----------------------------------   F(6, 751)       =     68.26
       Model |  49.1549871         6  8.19249785   Prob > F        =    0.0000
    Residual |  90.1311627       751  .120014864   R-squared       =    0.3529
-------------+----------------------------------   Adj R-squared   =    0.3477
       Total |   139.28615       757  .183997556   Root MSE        =    .34643

-------------+----------------------------------------------------------------
          lnw | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           s |    .0339768    .0729216      0.47    0.641     -.1091776     .1771312
          s2 |    .0024636    .0026079      0.94    0.345      -.002656     .0075832
        expr |    .0375502    .0063558      5.91    0.000      .0250729     .0500275
        expr |           0   (omitted)
      tenure |    .0356461     .007743      4.60    0.000      .0204456     .0508466
        smsa |    .1390585    .0280915      4.95    0.000      .0839113     .1942058
         rns |   -.0864204    .0289057     -2.99    0.003      -.143166    -.0296747
       _cons |     4.57118    .5021415      9.10    0.000      3.585412     5.556948
-------------+----------------------------------------------------------------

.
. sum s

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
           s |        758    13.40501    2.231828          9         18

.
. gen sd=(s-r(mean))/r(sd)

.
. gen sd2 =sd^2

.
. reg lnw sd sd2 expr tenure smsa rns

      Source |       SS           df       MS      Number of obs   =       758
-------------+----------------------------------   F(6, 751)       =     68.26
       Model |   49.154987         6  8.19249783   Prob > F        =    0.0000
    Residual |  90.1311629       751  .120014864   R-squared       =    0.3529
-------------+----------------------------------   Adj R-squared   =    0.3477
       Total |   139.28615       757  .183997556   Root MSE        =    .34643

-------------+----------------------------------------------------------------
          lnw | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
          sd |    .2232421     .014444     15.46    0.000      .1948866     .2515975
         sd2 |    .0122714    .0129899      0.94    0.345     -.0132294     .0377723
        expr |    .0375502    .0063558      5.91    0.000      .0250729     .0500275
      tenure |    .0356461     .007743      4.60    0.000      .0204456     .0508466
        smsa |    .1390585    .0280915      4.95    0.000      .0839113     .1942058
         rns |   -.0864204    .0289057     -2.99    0.003      -.143166    -.0296747
       _cons |    5.469338    .0319719    171.07    0.000      5.406574     5.532103
-------------+----------------------------------------------------------------

.
. estat vif

    Variable |       VIF       1/VIF
-------------+----------------------
          sd |      1.32    0.759911
         sd2 |      1.23    0.811990
        expr |      1.13    0.885254
      tenure |      1.06    0.944065
         rns |      1.04    0.963378
        smsa |      1.04    0.963750
-------------+----------------------
    Mean VIF |      1.14

.
. reg sd2 sd

      Source |       SS           df       MS      Number of obs   =       758
-------------+----------------------------------   F(1, 756)       =    159.77
       Model |  152.821515         1  152.821515   Prob > F        =    0.0000
    Residual |  723.111439       756  .956496612   R-squared       =    0.1745
-------------+----------------------------------   Adj R-squared   =    0.1734
       Total |  875.932954       757   1.1571109   Root MSE        =    .97801

-------------+----------------------------------------------------------------
          sd2 | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
          sd |    .4493082    .0355462     12.64    0.000      .3795271     .5190892
       _cons |    .9986808    .0355228     28.11    0.000      .9289457     1.068416
-------------+----------------------------------------------------------------

.
. reg lnw sd expr tenure smsa rns

      Source |       SS           df       MS      Number of obs   =       758
-------------+----------------------------------   F(5, 752)       =     81.75
       Model |  49.0478812         5  9.80957624   Prob > F        =    0.0000
    Residual |  90.2382686       752  .119997698   R-squared       =    0.3521
-------------+----------------------------------   Adj R-squared   =    0.3478
       Total |   139.28615       757  .183997556   Root MSE        =    .34641

-------------+----------------------------------------------------------------
          lnw | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
          sd |    .2290816    .0130535     17.55    0.000      .2034559     .2547073
        expr |    .0381189    .0063268      6.02    0.000      .0256986     .0505392
      tenure |    .0356146    .0077424      4.60    0.000      .0204153     .0508138
        smsa |    .1396666    .0280821      4.97    0.000      .0845379     .1947954
         rns |   -.0840797    .0287973     -2.92    0.004     -.1406124    -.0275471
       _cons |    5.479606    .0300656    182.26    0.000      5.420584     5.538629
-------------+----------------------------------------------------------------

.
. reg lnw s expr tenure smsa rns

      Source |       SS           df       MS      Number of obs   =       758
-------------+----------------------------------   F(5, 752)       =     81.75
       Model |  49.0478814         5  9.80957628   Prob > F        =    0.0000
    Residual |  90.2382684       752  .119997697   R-squared       =    0.3521
-------------+----------------------------------   Adj R-squared   =    0.3478
       Total |   139.28615       757  .183997556   Root MSE        =    .34641

-------------+----------------------------------------------------------------
          lnw | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           s |     .102643    .0058488     17.55    0.000      .0911611      .114125
        expr |    .0381189    .0063268      6.02    0.000      .0256986     .0505392
      tenure |    .0356146    .0077424      4.60    0.000      .0204153     .0508138
        smsa |    .1396666    .0280821      4.97    0.000      .0845379     .1947954
         rns |   -.0840797    .0287973     -2.92    0.004     -.1406124    -.0275471
       _cons |    4.103675     .085097     48.22    0.000      3.936619     4.270731
-------------+----------------------------------------------------------------

.
. use nerlove.dta,clear
(Nerlove 1963 paper)

.
. reg lntc lnq lnpl lnpk lnpf

      Source |       SS           df       MS      Number of obs   =       145
-------------+----------------------------------   F(4, 140)       =    437.90
       Model |  269.524728         4  67.3811819   Prob > F        =    0.0000
    Residual |  21.5420958       140  .153872113   R-squared       =    0.9260
-------------+----------------------------------   Adj R-squared   =    0.9239
       Total |  291.066823       144  2.02129738   Root MSE        =    .39227

-------------+----------------------------------------------------------------
         lntc | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
         lnq |    .7209135    .0174337     41.35    0.000      .6864462     .7553808
        lnpl |    .4559645     .299802      1.52    0.131     -.1367602     1.048689
        lnpk |   -.2151476    .3398295     -0.63    0.528     -.8870089     .4567136
        lnpf |    .4258137    .1003218      4.24    0.000      .2274721     .6241554
       _cons |   -3.566513    1.779383     -2.00    0.047     -7.084448    -.0485779
-------------+----------------------------------------------------------------

.
. replace lnq=lnq*100 if _n==1
(1 real change made)

.
. reg lntc lnq lnpl lnpk lnpf

      Source |       SS           df       MS      Number of obs   =       145
-------------+----------------------------------   F(4, 140)       =      0.92
       Model |   7.4424142         4  1.86060355   Prob > F        =    0.4551
    Residual |  283.624409       140  2.02588864   R-squared       =    0.0256
-------------+----------------------------------   Adj R-squared   =   -0.0023
       Total |  291.066823       144  2.02129738   Root MSE        =    1.4233

-------------+----------------------------------------------------------------
         lntc | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
         lnq |    .0156026    .0218326      0.71    0.476     -.0275616     .0587668
        lnpl |    1.214014    1.093264      1.11    0.269     -.9474289     3.375456
        lnpk |   -1.096614    1.233079     -0.89    0.375     -3.534477     1.341248
        lnpf |   -.2427032    .3641193     -0.67    0.506     -.9625867     .4771803
       _cons |    7.230075    6.388544      1.13    0.260     -5.400419     19.86057
-------------+----------------------------------------------------------------

.
. reg lntc lnq lnpl lnpk lnpf if _n > 1

      Source |       SS           df       MS      Number of obs   =       144
-------------+----------------------------------   F(4, 139)       =    406.10
       Model |  251.560166         4  62.8900416   Prob > F        =    0.0000
    Residual |  21.5261194       139  .154864168   R-squared       =    0.9212
-------------+----------------------------------   Adj R-squared   =    0.9189
       Total |  273.086286       143  1.90969431   Root MSE        =    .39353

-------------+----------------------------------------------------------------
         lntc | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
         lnq |    .7225462    .0182135     39.67    0.000      .6865348     .7585576
        lnpl |    .4445846    .3028466      1.47    0.144     -.1541969     1.043366
        lnpk |   -.2219834    .3415869     -0.65    0.517     -.8973614     .4533947
        lnpf |    .4311295    .1019964      4.23    0.000      .2294645     .6327944
       _cons |    -3.55227     1.78566     -1.99    0.049     -7.082837    -.0217022
-------------+----------------------------------------------------------------

.
. use nerlove.dta,clear
(Nerlove 1963 paper)

.
. qui reg lntc lnq lnpl lnpk lnpf

.
. predict lev,leverage

.
. sum lev

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
         lev |        145    .0344828    .0202164    .009924   .1177335

.
. dis r(max)/r(mean)
3.4142728

.
. gsort -lev

.
. list lev in 1/3

     +----------+
     |      lev |
     +----------+
  1. | .1177335 |
  2. | .1001472 |
  3. | .0983759 |
     +----------+

.
. replace lnq=lnq*100 if _n==1
(1 real change made)

.
. qui reg lntc lnq lnpl lnpk lnpf

.
. predict lev1,lev

.
. sum lev1

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        lev1 |        145    .0344828    .0807897   .0083048   .9801415

.
. dis r(max)/r(mean)
28.424102

.
. use consumption.dta,clear

.
. twoway connect c y year, msymbol(circle) msymbol(triangle)

.
. twoway connect c y year, msymbol(circle) msymbol(triangle) xlabel(1980(10)2010) xline(1992)

.
. reg c y

      Source |       SS           df       MS      Number of obs   =        36
-------------+----------------------------------   F(1, 34)        =   7139.56
       Model |   617812224         1   617812224   Prob > F        =    0.0000
    Residual |  2942143.12        34  86533.6213   R-squared       =    0.9953
-------------+----------------------------------   Adj R-squared   =    0.9951
       Total |   620754367        35  17735839.1   Root MSE        =    294.17

-------------+----------------------------------------------------------------
            c | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           y |    .3572642    .0042282     84.50    0.000      .3486715     .3658569
       _cons |    339.0701    63.83305      5.31    0.000      209.3458     468.7945
-------------+----------------------------------------------------------------

.
. scalar ssr=e(rss)

.
. reg c y if year < 1992

      Source |       SS           df       MS      Number of obs   =        14
-------------+----------------------------------   F(1, 12)        =   4344.64
       Model |  829125.648         1  829125.648   Prob > F        =    0.0000
    Residual |  2290.06599        12  190.838833   R-squared       =    0.9972
-------------+----------------------------------   Adj R-squared   =    0.9970
       Total |  831415.714        13  63955.0549   Root MSE        =    13.814

-------------+----------------------------------------------------------------
            c | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           y |    .4996452    .0075803     65.91    0.000      .4831292     .5161612
       _cons |    12.89123    7.908212      1.63    0.129     -4.339283     30.12174
-------------+----------------------------------------------------------------

.
. scalar ssr1=e(rss)

.
. reg c y if year >= 1992

      Source |       SS           df       MS      Number of obs   =        22
-------------+----------------------------------   F(1, 20)        =   4889.80
       Model |   366038781         1   366038781   Prob > F        =    0.0000
    Residual |     1497151        20  74857.5501   R-squared       =    0.9959
-------------+----------------------------------   Adj R-squared   =    0.9957
       Total |   367535932        21    17501711   Root MSE        =     273.6

-------------+----------------------------------------------------------------
            c | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           y |    .3444589     .004926     69.93    0.000      .3341836     .3547343
       _cons |    658.1088    95.04293      6.92    0.000      459.8527     856.3648
-------------+----------------------------------------------------------------

.
. scalar ssr2=e(rss)

.
. di((ssr-ssr1-ssr2)/2)/((ssr1+ssr2)/32)
15.394558

.
. gen d=(year>1991)

.
. gen yd=y*d

.
. reg c y d yd

      Source |       SS           df       MS      Number of obs   =        36
-------------+----------------------------------   F(3, 32)        =   4405.23
       Model |   619254926         3   206418309   Prob > F        =    0.0000
    Residual |  1499441.07        32  46857.5333   R-squared       =    0.9976
-------------+----------------------------------   Adj R-squared   =    0.9974
       Total |   620754367        35  17735839.1   Root MSE        =    216.47

-------------+----------------------------------------------------------------
            c | Coefficient   Std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           y |    .4996452    .1187794      4.21    0.000      .2576994      .741591
           d |    645.2175    144.9484      4.45    0.000      349.9673     940.4678
          yd |   -.1551863    .1188434     -1.31    0.201     -.3972623     .0868897
       _cons |    12.89123    123.9181      0.10    0.918     -239.5216     265.3041
-------------+----------------------------------------------------------------

.
. test d yd


 ( 1)  d = 0


 ( 2)  yd = 0


       F(  2,    32) =   15.39
            Prob > F =    0.0000

.
. qui reg c y

.
. estat imtest,white

White's test
H0: Homoskedasticity
Ha: Unrestricted heteroskedasticity

chi2(2)   = 6.31
Prob > chi2   = 0.0427

Cameron & Trivedi's decomposition of IM-test

---------------------+----------------------------
Source   |       chi2     df         p
---------------------+----------------------------
Heteroskedasticity   |       6.31      2    0.0427
Skewness   |       4.11      1    0.0425
Kurtosis   |       4.76      1    0.0291
---------------------+----------------------------
Total   |      15.19      4    0.0043
---------------------+----------------------------

.
. tsset year


Time variable: year, 1978   to 2013


        Delta: 1 unit

.
. estat bgodfrey

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

.
. dis 36^(1/4)
2.4494897

.
. newey c y d yd,lag(3)

Regression with Newey–West standard errors      Number of obs     =         36
Maximum lag = 3                                 F(  3,        32) =    2455.09
                                                Prob > F          =     0.0000

-------------+----------------------------------------------------------------
             |             Newey–West
            c | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
           y |    .4996452    .0099228     50.35    0.000      .4794332     .5198573
           d |    645.2175     139.943      4.61    0.000      360.1629     930.2721
          yd |   -.1551863     .013774    -11.27    0.000     -.1832431    -.1271295
       _cons |    12.89123    10.16563      1.27    0.214     -7.815475     33.59793
-------------+----------------------------------------------------------------

.
. test d yd


 ( 1)  d = 0


 ( 2)  yd = 0


       F(  2,    32) =   73.05
            Prob > F =    0.0000

.
. use consumption.dta,clear

.
. gen y1=y

.
. replace y1 =. if year==1980|year ==1990|year==2000|year==2010
(4 real changes made, 4 to missing)

.
. ipolate y1 year,gen(y2)

.
. gen lny1=log(y1)
(4 missing values generated)

.
. ipolate lny1 year,gen(lny3)

.
. gen y3=exp(lny3)

.
. list year y y2 y3 if year==1980|year==1990|year==2000|year==2010

     +---------------------------------------+
     | year         y          y2         y3 |
     +---------------------------------------+
  3. | 1980    463.25     455.705   454.2445 |
 13. | 1990      1644     1705.88   1695.613 |
 23. | 2000   7857.68    7890.105   7856.112 |
 33. | 2010   30015.1   30402.659   30022.13 |
     +---------------------------------------+

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