Econ 508

Econometrics Group

Home | Faculty | Students | Alumni | Courses | Research | Reproducibility | Lab | Seminars | Economics | Statistics | Fame

Applied Econometrics
Econ 508 - Fall 2007

e-Tutorial 4: Introduction to Dynamic Models

Welcome to the fourth issue of e-Tutorial, the on-line help to Econ 508. This issue provides an introduction to dynamic models in Econometrics, and draws on Prof. Koenker's Lecture Note 3. The adopted philosophy is "learn by doing": the material is intended to help you to solve the problem set 2 and to enhance your understanding of the topics. 

Data Set:
The data set used in this tutorial was borrowed from Johnston and DiNardo's Econometric Methods (1997, 4th ed), but slightly adjusted for your needs. It is called AUTO2 and it is already in STATA format. You can download the data by clicking here or simply visiting the Econ 508 web site (Data). As you will see, this adapted data set contains five series, namely: 

quarter Quarter of the observation (from 1959.1 to 1990.4)
gas     Log of per capita real expenditure on gasoline and oil
price   Log of the real price of gasoline and oil
income  Log of per capita real disposable income
miles   Log of miles per gallon

Summarizing the data
A useful recommendation for practitioners of Econometrics is to summarize the data set you are going to work with. This provides a “big picture” of the variables and what you can expect from them. You can do that by as follows:

summarize

Variable |     Obs        Mean   Std. Dev.       Min        Max
---------+-----------------------------------------------------
 quarter |     128     1974.75   9.270052     1959.1     1990.4 
     gas |     128   -7.763027   .1201866  -8.019878  -7.606151 
   price |     128    4.723974   .1658683   4.488154   5.176053 
  income |     128    -4.19457    .153558   -4.50524  -3.969884 
   miles |     128    2.712568   .1348134   2.583997   3.035914 

Even better, you can ask for the details of each variable:

summarize, detail

                 Quarter of the observation
-------------------------------------------------------------
      Percentiles      Smallest
 1%       1959.2         1959.1
 5%       1960.3         1959.2
10%       1962.1         1959.3       Obs                 128
25%      1966.75         1959.4       Sum of Wgt.         128

50%      1974.75                      Mean            1974.75
                        Largest       Std. Dev.      9.270052
75%      1982.75         1990.1
90%       1987.4         1990.2       Variance       85.93386
95%       1989.2         1990.3       Skewness       1.81e-17
99%       1990.3         1990.4       Kurtosis       1.798007

     Log of per capita real expenditure on gasoline and
                             oil
-------------------------------------------------------------
      Percentiles      Smallest
 1%    -8.016769      -8.019878
 5%    -8.005725      -8.016769
10%    -7.974048      -8.015248       Obs                 128
25%    -7.836869      -8.012581       Sum of Wgt.         128

50%    -7.719422                      Mean          -7.763027
                        Largest       Std. Dev.      .1201866
75%    -7.671802      -7.628435
90%     -7.64901      -7.625179       Variance       .0144448
95%    -7.636929      -7.620612       Skewness      -.9293219
99%    -7.620612      -7.606151       Kurtosis       2.503103

          Log of the real price of gasoline and oil
-------------------------------------------------------------
      Percentiles      Smallest
 1%     4.500299       4.488154
 5%     4.531126       4.500299
10%     4.557322       4.515703       Obs                 128
25%     4.621168        4.51949       Sum of Wgt.         128

50%     4.675815                      Mean           4.723974
                        Largest       Std. Dev.      .1658683
75%     4.767021       5.130968
90%     5.016708       5.149823       Variance       .0275123
95%     5.121161       5.162098       Skewness       1.180383
99%     5.162098       5.176053       Kurtosis       3.591608

          Log of per capita real disposable income
-------------------------------------------------------------
      Percentiles      Smallest
 1%    -4.498873       -4.50524
 5%    -4.490103      -4.498873
10%    -4.446543      -4.496271       Obs                 128
25%    -4.284298      -4.492739       Sum of Wgt.         128

50%    -4.158388                      Mean           -4.19457
                        Largest       Std. Dev.       .153558
75%    -4.105482      -3.978981
90%    -4.006467      -3.971754       Variance       .0235801
95%    -3.985354      -3.971611       Skewness        -.55278
99%    -3.971611      -3.969884       Kurtosis       2.312228

                   Log of miles per gallon
-------------------------------------------------------------
      Percentiles      Smallest
 1%     2.585882       2.583997
 5%     2.590767       2.585882
10%     2.596746       2.586259       Obs                 128
25%     2.613006       2.587764       Sum of Wgt.         128

50%      2.64715                      Mean           2.712568
                        Largest       Std. Dev.      .1348134
75%     2.812479       3.013695
90%     2.950735       3.021156       Variance       .0181746
95%     2.995482       3.028562       Skewness       1.069017
99%     3.028562       3.035914       Kurtosis        2.68393
 

Generating Lags, Leads, and Differences:
The next step is to create the variables you will need to run dynamic models. Here you have two strategies: 
(i)  generate lags and differences using the command gen (explained in class) 
(ii)  convert your data set in time series, using the command tsset 

Usually the strategy (ii) saves you time during the model selection process. Hence, following (ii), you need to generate a variable corresponding to the time period of each observation (which can not be “quarter” because it contains non-integer values):

gen t=_n
label variable t "Integer time period"

Next you "tsset" your data using the created variable:
tsset t
        time variable:  t, 1 to 128

Now you are ready to work with time series. The main operators you will need are: 
 

1-period lag:

y(t-1)

type

L.y

2-period lag:

y(t-2)

type

L2.y

… 

 

 

 

1-period lead: 

y(t+1)

type

F.y

2-period lead:

y(t+2)

type

F2.y

… 

 

 

 

Difference:

y(t)-y(t-1)

type

D.y

Difference of difference:

[y(t) - y(t-1)] – [y(t-1) - y(t-2)]

type

D2.y

… 

 

 

 

Seasonal difference:

y(t)-y(t-1)

type

S.y

Lag-2 Seasonal difference:

y(t)-y(t-2)

type

S2.y

… 

 

 

 

The remaining lags/leads/differences can be generated using combination of the operators above.
 

Graphing Time Series:
Next we will try to replicate some of Johnston and DiNardo’s (1997, p. 267) graphical results: 

graph   gas quarter, c(l) s(.) sort ylabel xlabel(1960.1 (5) 1990.1)

 

graph   price  quarter, c(l) s(.) sort ylabel xlabel(1960.1 (5) 1990.1)

 

graph   income  quarter, c(l) s(.) sort ylabel xlabel(1960.1 (5) 1990.1)

 

Running Dynamic Models:

Next let’s run a typical dynamic model (Johnston and DiNardo, 1997, p. 269, Table 8.5):

regress  gas  price L.price L2.price L3.price L4.price L5.price  income L.income L2.income L3.income L4.income L5.income  L.gas L2.gas L3.gas L4.gas L5.gas
 

  Source |       SS       df       MS                  Number of obs =     123
---------+------------------------------               F( 17,   105) =  383.71
   Model |  1.47998066    17  .087057686               Prob > F      =  0.0000
Residual |  .023823131   105  .000226887               R-squared     =  0.9842
---------+------------------------------               Adj R-squared =  0.9816
   Total |  1.50380379   122  .012326261               Root MSE      =  .01506

------------------------------------------------------------------------------
gas      |      Coef.   Std. Err.       t     P>|t|       [95% Conf. Interval]
---------+--------------------------------------------------------------------
price    |
      -- |  -.2676449   .0378744     -7.067   0.000      -.3427428    -.192547
      L1 |   .2628672   .0692914      3.794   0.000       .1254751    .4002592
      L2 |  -.0174063   .0754139     -0.231   0.818      -.1669381    .1321256
      L3 |  -.0720921   .0773891     -0.932   0.354      -.2255404    .0813562
      L4 |   .0143968   .0772103      0.186   0.852      -.1386968    .1674905
      L5 |   .0582077   .0463403      1.256   0.212      -.0336765    .1500919
income   |
      -- |   .2927731   .1588226      1.843   0.068      -.0221427     .607689
      L1 |  -.1621984    .220227     -0.737   0.463      -.5988679    .2744712
      L2 |  -.0492554   .2143709     -0.230   0.819      -.4743132    .3758024
      L3 |   .0104172   .2131308      0.049   0.961      -.4121817    .4330161
      L4 |    .084901   .2101309      0.404   0.687      -.3317496    .5015517
      L5 |  -.1989616   .1531175     -1.299   0.197      -.5025654    .1046421
gas      |
      L1 |   .6605733    .096063      6.876   0.000       .4700981    .8510485
      L2 |   .0670148   .1145346      0.585   0.560      -.1600861    .2941157
      L3 |  -.0235803   .1170941     -0.201   0.841      -.2557563    .2085957
      L4 |   .1321968    .119014      1.111   0.269       -.103786    .3681797
      L5 |   .1631249   .1013842      1.609   0.111      -.0379011     .364151
_cons    |   .0055429   .1260436      0.044   0.965      -.2443782    .2554639
------------------------------------------------------------------------------
 
 

Long-run Elasticities:

Suppose you wish to compute the long run income and price elasticities. Assuming that in the long-run the variables converge to their respective steady-state values (represented by “e”): 

gas(t)=gas(t-1)=gas(t-2)=...=gas(e) 
price(t)=price(t-1)=price(t-2)=...=price(e) 
income(t)=income(t-1)=income(t-2)=...=income(e),

and recalling that all variables are already in logs, you then just have to apply this steady state condition, reparameterize the model, and calculate the elasticities: 

d (gas(e))/ d (income(e))= long run income elasticity 
d (gas(e)) /d (price(e)) = long run price elasticity 

After that you can compare the long-run elasticities of the (reparameterized) dynamic model with the elasticities provided by the static version of this log-linear regression:

regress  gas price income

  Source |       SS       df       MS                  Number of obs =     128
---------+------------------------------               F(  2,   125) =  218.86
   Model |  1.42698222     2  .713491108               Prob > F      =  0.0000
Residual |  .407508656   125  .003260069               R-squared     =  0.7779
---------+------------------------------               Adj R-squared =  0.7743
   Total |  1.83449087   127   .01444481               Root MSE      =   .0571

------------------------------------------------------------------------------
     gas |      Coef.   Std. Err.       t     P>|t|       [95% Conf. Interval]
---------+--------------------------------------------------------------------
   price |  -.1502843   .0312311     -4.812   0.000      -.2120945   -.0884742
  income |   .7056134   .0337348     20.917   0.000       .6388481    .7723787
   _cons |  -4.093342   .2247555    -18.212   0.000      -4.538161   -3.648523
------------------------------------------------------------------------------
 

I suggest you to provide a little table comparing those results, and write your comments about how the elasticities differ from the static to the dynamic model. 

In the light of the problem set 1, I suggest you to compute not only the point estimate of the elasticities, but also their confidence intervals. In the static model, confidence intervals are obtained directly from the regression output. But for the dynamic model, the elasticities are represented by a non-linear function of the parameters. In that case, you need to find confidence intervals for the elasticities using Delta-method or Bootstrap techniques, which you will see in professor Koenker’s lecture Note 4. 
 

Impulse Response Functions:

Here I recommend to use the best dynamic model (following the Schwarz Information Criterion that you will see in e-Tutorial 5), and to compute impulse response functions using the formula on Prof. Koenker's Lecture Note 3, page 3. 

P.S.: Some authors propose alternative ways to calculate impulse response functions. One of them is to use partial derivatives (e.g., Enders, 1995, p.24), but such method has a drawback: it is quite easy to make a mistake when you have models with many lags and differences.

Usually it is expected that you account for a reasonable amount of response periods, depending on the structure of your data set. Usually we suggest a minimum of 40 (forty) response periods for quarterly data. Then you plot those responses along the respective time scale (t=0,1,2,3,...,40). This will generate the non-cumulative impulse response function. If you wish a cumulative impulse response function, at each new period t+i (i=1,2,3,...), you should add the effect to the previous shocks.
 

Error Correction Model (ECM):

There is no mystery in doing that. You just have to add and subtract y(t-1) and \beta_{0}*x(t-1) on the model, reparameterize it, and obtain a dynamic equation in which the difference of the response (dependent) variable is decomposed into two parts: (a) direct effects from changes in the explanatory variables, and (b) indirect effects from changes on the response variable during previous periods, while it was out-of-equilibrium. (See, for example, Prof. Koenker’s Lecture Note 3, p. 5.)
 

Using R:

In order to estimate a time series model in R we need to transform the data in “time series” first. We can do that we loagind two libraries, say stats and dyn.

library(stats)

library(dyn)

 

Let’s see the example for the gasoline data. Infile the data:

d.gas<-read.table("http://www.econ.uiuc.edu/~econ472/data/AUTO2.txt",header=T)

attach(d.gas)

gas<-ts(gas,start=1959,frequency=4)

price<-ts(price,start=1959,frequency=4)

income<-ts(income,start=1959,frequency=4)

miles<-ts(miles,start=1959,frequency=4)

 

Now, we are ready to run regressions. One could run, for example:

f<-dyn$lm(gas~lag(gas,-1)+price)

summary(f)

Call:

lm(formula = dyn(gas ~ lag(gas, -1) + price))

 

Residuals:

       Min         1Q     Median         3Q        Max

-0.1070295 -0.0071226  0.0003278  0.0105659  0.0359612

 

Coefficients:

              Estimate Std. Error t value Pr(>|t|)   

(Intercept)  -0.129960   0.115034  -1.130   0.2608   

lag(gas, -1)  0.970998   0.013543  71.697   <2e-16 ***

price        -0.019652   0.009811  -2.003   0.0473 * 

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

 

Residual standard error: 0.01833 on 124 degrees of freedom

Multiple R-Squared: 0.9765,     Adjusted R-squared: 0.9761

F-statistic:  2572 on 2 and 124 DF,  p-value: < 2.2e-16

 

 

In order to do differences, just type

f2<-dyn$lm(gas~lag(gas,-1)+price+lag(diff(gas),-1))

summary(f2)

Call:

lm(formula = dyn(gas ~ lag(gas, -1) + price + lag(diff(gas),

    -1)))

 

Residuals:

       Min         1Q     Median         3Q        Max

-0.1081008 -0.0075195  0.0006098  0.0113212  0.0398956

 

Coefficients:

                   Estimate Std. Error t value Pr(>|t|)   

(Intercept)        -0.12594    0.11686  -1.078   0.2833   

lag(gas, -1)        0.96955    0.01379  70.289   <2e-16 ***

price              -0.02281    0.01007  -2.265   0.0253 * 

lag(diff(gas), -1) -0.12166    0.08928  -1.363   0.1755   

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

 

Residual standard error: 0.01833 on 122 degrees of freedom

Multiple R-Squared: 0.976,      Adjusted R-squared: 0.9754

F-statistic:  1652 on 3 and 122 DF,  p-value: < 2.2e-16

 

If you want to reproduce the dynamic model given by Johnston and DiNardo, 1997, p. 269, Table 8.5, just type

f3<-dyn$lm(gas~price+lag(price,-1)+ lag(price,-2)+ lag(price,-3)+ lag(price,-4)+

lag(price,-5)+income+lag(income,-1)+ lag(income,-2)+ lag(income,-3)+

lag(income,-4)+lag(income,-5)+lag(gas,-1)+ lag(gas,-2)+ lag(gas,-3)+ lag(gas,-4)+

lag(gas,-5))

summary(f3)

 

and you get the same model as described above.

 

 

 

 Last update: Sep. 9, 2008