Var Models in Stata
Var Models in Stata
Anton Parlow
Lab session Econ710
UWM Econ Department
03/12/2010
03/12/2010
1 / 13
Our plan
Introduction to VAR
How to import data into Stata
Unit root tests
First differencing a time series
VAR-estimation
VAR and optimal lag length
VAR again
VAR stability
VAR forecasting
Exercises
03/12/2010
2 / 13
03/12/2010
3 / 13
As usual a series of unit-root test will help us confirming it but first let us import some data.
03/12/2010
4 / 13
03/12/2010
5 / 13
03/12/2010
6 / 13
To generate a first differenced version of defense spending and real GDP, do the following:
gen flds=D.lds
gen flrgp=D.lrgdp
and save the data-set
Now its time for a VAR-estimation. We will use the standard command without any options
and determine the lag-length after the estimation
03/12/2010
7 / 13
Var estimation
The command is
var variable1 variable2
in our example it will be
var flrgdp flds
and Stata assume two lags without any option. Now we can determine the optimal lag-length
using information criteria like AIC, BIC and SIC. Stata will do it for us.
You can find the output attached! You should care about the significance of the lags explaining
your dependent variables. Remember Stata use L for lag e.g flrgdpL1 is the first lag of real
GDP.
We will use varsoc for determining the lag-length.
03/12/2010
8 / 13
After estimating the bivariate VAR(2) we can use following command for figuring out the
optimal lag-length. Let us include 10 lags for testing it
varsoc, lags(10)
See output. Maybe 2 or 5 lags. The stars tell us what lag-length is picked by the criteria
If we do the same test for 5 lags
varsoc, lags(5)
Most of the stars point at 5 lags for our VAR-model. Note: Information criteria have to be
minimized, thats the reason why you see the stars at certain values.
03/12/2010
9 / 13
Var-estimation continued
We will estimate the bivariate VAR for 5 lags (suggested by lag-length criteria)
var flrgdp flds, lag(1 2 3 4 5)
or
var flrgdp flds, lag(1/5)
A very nice table including 5 lags for each variable e.g. defense spending are explained by past
realizations of defense spendings and real GDP and real GDP is explained by past realizations of
real GDP and defense spendings.
Look at the significance and the sign of the lags. Its more important than the actual magnitude
(doesnt tell too much in a VAR). Because the story is more about the lag and the sign but not
the magnitude. Or we just describe these two series. The magnitudes would get more meaning
in a structural VAR.
03/12/2010
10 / 13
VAR stability
For a stable VAR-model we want to eigenvalues to be less than one. This can be tested after
the estimation using following command:
varstable
gives you a table with the eigenvalues for the estimated VAR. All lie inside the unit circle and
thats good.
If you use the option varstable, graph you get graph of the unit circle additional to the
output table.
What else could be done. We could test for remaining autocorrelation in the error-terms (there
should be none) but most of the time nobody is really doing this anymore. I guess its not too
big of a problem. So let us do a simple dynamic out of sample forecast (apparently the only one
built in in Stata 10..). Eviews is still more flexible and powerful in forecasting than Stata.
03/12/2010
11 / 13
VAR forecasting
Stata uses two commands for forecasting after a VAR, SVAR and ECM estimation.
First you need to compute the forecast:
fcast compute m1_, step(24)
fcast compute is the command, m1_ gives a suffix to the auxiliary estimations for defense
spending and real GDP. You will find the forecast for defense spending as a new variable
m1_flds for example. step(24) is an option telling Stata to forecast 24 quarters out of sample.
Second you can graph the dynamic forecast for defense spending and real GDP using
fcast graph
e.g.
fcast graph m1_flrgdp m1_flds
and you get kind of nice forecast graphs.
03/12/2010
12 / 13
Exercises
Do the same as above but for different sub samples. We did it for the entire period 1947 to
2008. Try the Cold war period from 1947 to 1991
Just use the command for specifying the time span:
var flrgdp flds tin(1947q1,1991q4)
for the VAR-system without any lags.
And one example of a unit-root test:
dfuller lrgdp if tin(1947q1,1991q4)
Very nice command tin
03/12/2010
13 / 13