var models in stata

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

description

describes using stata

Transcript of var models in stata

  • VAR-models in Stata

    Anton ParlowLab 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. Imagineyou have two series and want to explain these two with own past realizations and pastrealizations 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 theregressive terms)

    yt = c1 + 11yt1 + 12yt2 + 13dst1 + 14dst2 + 1t

    dt = c2 + 21dst1 + 22dst2 + 23yt1 + 24yt2 + 2t

    where yt = log of real GDP and dst = log of defense spending

    In general a VAR(p)-process would be:

    yt = c + 1yt1 + 2yt2 . . . pytp + t where t iid N(0,)

    where p is the lag length, c a vector of constants, the variance-covariance matrix of the errorterm 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 defensespending and real GDP from 1947 to 2008 shows us a non-stationary time series having a trendalready.

    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 containingreal GDP.

    The easiest way is copying both files to Excel to have it in one file. Use the first row for thenames 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 yourcomputer

    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 lengthhas 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 optionsand 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-lengthusing 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 explainingyour dependent variables. Remember Stata use L for lag e.g flrgdpL1 is the first lag of realGDP.

    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 theoptimal 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 beminimized, 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 pastrealizations of defense spendings and real GDP and real GDP is explained by past realizations ofreal 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 notthe magnitude. Or we just describe these two series. The magnitudes would get more meaningin 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 afterthe estimation using following command:

    varstable

    gives you a table with the eigenvalues for the estimated VAR. All lie inside the unit circle andthats good.

    If you use the option varstable, graph you get graph of the unit circle additional to theoutput table.

    What else could be done. We could test for remaining autocorrelation in the error-terms (thereshould be none) but most of the time nobody is really doing this anymore. I guess its not toobig of a problem. So let us do a simple dynamic out of sample forecast (apparently the only onebuilt 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 defensespending and real GDP. You will find the forecast for defense spending as a new variablem1_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 usingfcast 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 to2008. 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

    Introduction to VARImporting data into StataUnit root testsFirst differencingVar estimationIntroductionOptimal lag lengthVAR estimation continuedStabilityForecasting

    Exercises