Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
241 views

Var Models in Stata

This document provides an overview of vector autoregressive (VAR) models and how to estimate them in Stata. It discusses importing data, testing for stationarity using unit root tests, first differencing non-stationary data, estimating VAR models with optimal lag lengths, checking stability of the VAR, and producing forecasts. The document uses an example of estimating a bivariate VAR model for log real GDP and log defense spending data. Exercises are suggested to estimate the VAR model over different subsample periods.

Uploaded by

Natia Tsikvadze
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
241 views

Var Models in Stata

This document provides an overview of vector autoregressive (VAR) models and how to estimate them in Stata. It discusses importing data, testing for stationarity using unit root tests, first differencing non-stationary data, estimating VAR models with optimal lag lengths, checking stability of the VAR, and producing forecasts. The document uses an example of estimating a bivariate VAR model for log real GDP and log defense spending data. Exercises are suggested to estimate the VAR model over different subsample periods.

Uploaded by

Natia Tsikvadze
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

VAR-models in Stata

Anton Parlow
Lab session Econ710
UWM Econ Department

03/12/2010

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

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

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

2 / 13

Introduction to VAR models


A vector-autoregressive (VAR) model is a multi-variate way of modeling time series. Imagine
you have two series and want to explain these two with own past realizations and past
realizations of the other series
e.g. GDP and defense spending help explaining each others current values
Let a simple bivariate VAR(2)-process be the following (meaning two series and two lags of the
regressive terms)
yt = c1 + 11 yt1 + 12 yt2 + 13 dst1 + 14 dst2 + 1t
dt = c2 + 21 dst1 + 22 dst2 + 23 yt1 + 24 yt2 + 2t
where yt = log of real GDP and dst = log of defense spending
In general a VAR(p)-process would be:
yt = c + 1 yt1 + 2 yt2 . . . p ytp + t where t iid N(0, )
where p is the lag length, c a vector of constants, the variance-covariance matrix of the error
term and yt a vector containing the different time series.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

3 / 13

Introduction to VAR models continued


To estimate a VAR-model properly, we need stationary data. Taking a look at quarterly defense
spending and real GDP from 1947 to 2008 shows us a non-stationary time series having a trend
already.

As usual a series of unit-root test will help us confirming it but first let us import some data.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

4 / 13

Importing data into Stata


Imagine someone gives you a txt-file containing defense spending and another txt-file containing
real GDP.
The easiest way is copying both files to Excel to have it in one file. Use the first row for the
names of the variables.
Then save it as csv and let it be comma-separated.
Go to Stata:
1. File Import Ascii Data created by a spreadsheet browse for the csv-file on your
computer
2. Ignore the options and let Stata determine which format (automatically determine delimiter,
works most of the time) and click okay
3. You should see 2 new variables and have a data-set in the data-browser
4. Save it as var.dta
5. start a log-file: File Log Begin save it as .log

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

5 / 13

Unit root tests


We know the Dickey Fuller test is sensible to different options, as well the Philips Perron test and of course the proper lag length
has to be chosen!
Furthermore for a VAR-model both series have to be stationary.
This implies following testing strategy and imagine Schwerts rule of thumb tells you 15 lags have to be included:
dfuller lds, lags(15)
dfuller lds, lags(15) noconstant
dfuller lds, lags(15) trend
for defense spendings and for real GDP
dfuller lrgdp, lags(15)
dfuller lrgdp, lags(15) noconstant
dfuller lrgdp, lags(15) trend
and similarly you can do the same 6 tests for the Philips Perron test
pperron lrgdp, lags(15)
and so on
If we are lucky most of them tell us, these two series are non-stationary. And we get a very nice table for a term paper. Now
imagine you split the sample e.g. Cold war vs. entire period because then you have to the tests again (and another table!)

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

6 / 13

First differencing a time series

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

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

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.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

8 / 13

Var and optimal lag-length

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.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

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.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

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.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in 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.

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

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

Anton Parlow Lab session Econ710 UWM Econ Department


VAR-models
() in Stata

03/12/2010

13 / 13

You might also like