The vector autoregressive model (VAR) is actually simpler to estimate than the VEC model.

It is used when there is no cointegration among the variables and it is estimated using time series that have been transformed to their stationary values. In the example from your book, we have macroeconomic data log of real personal disposable income (denoted as Y) and log of real personal consumption expenditure (denoted as C) for the U.S. economy over the period 1960:1 to 2009:4 that are found in the fred.dta dataset. As in the previous example, the first step is to determine whether the variables are stationary. If they are not, then difference them, checking to make sure that the differences are stationary (i.e., the levels are integrated). Next, test for cointegration. If they are cointegrated, estimate the VEC model. If not, use the differences and lagged differences to estimate a VAR. model. Load the data. In this exercise we’ll be using the fred.dta data.
use fred, clear

Estimating a VAR

The data are quarterly and begin in 1960q1 and extend to 2009q4. Just as we did in the example above, sequences of quarterly dates:
gen date = q(1960q1) + _n - 1 format %tq date tsset date

The first step is to plot the series in order to identify whether constants or trends should be included in the tests of nonstationarity. Both the levels and differences are plotted.
tsline lc ly, legend(lab (1 "ln(RPCE)") lab(2 "ln(RPDI)")) /// name(l1, replace) tsline, legend(lab (1 "ln(RPCE)") lab(2 "ln(RPDI)")) /// name(d1, replace)
9.5 7.5





1980q1 date ln(RPCE)


2000q1 ln(RPDI)


lags(1 2 3) The test results for the last two regressions appear L(1/2) estat bgodfrey. lags(1 2 3) qui reg D. but the mean of the series appears to be greater than estat bgodfrey. If this strategy is pursued in Stata.D.04 1960q1 1970q1 1980q1 date ln(RPCE) 1990q1 2000q1 ln(RPDI) 2010q1 The other decision that needs to be made is the number of lagged differences to include in the augmented Dickey-Fuller L.06 estat L. The regressions for the ADF tests are qui reg D. the estat bgodfrey command will not be based on the proper regression if issued after L(1/1). then the ADF regressions will have to be explicitly estimated. suggesting that a constant be included in the ADF regressions. So. The principle to follow is to include just enough so that the residuals of the ADF regression are not autocorrelated. start out with a basic regression that contains no lags. The differences show no obvious trend. estimate the DF regression.02 . Add enough lags to eliminate the autocorrelation among L. then use the LM test discussed earlier to determine whether the residuals are autocorrelated. . lags(1 2 3) qui reg D.The levels series appear to be trending L(1/3).02 0 . .

056 2. The resulting ADF statistic is obtained using: dfuller lc. lags(1 2 3) } As seen earlier in the course.451 5. For the income series.311 3. di "Lags = 3" Lags = 3 . lags(3) Augmented Dickey-Fuller test for unit root Test Statistic Z(t) -1. The unit root hypothesis is not rejected at the 5% level. and p is instructed to increment beginning at 1 and ending at 3.. The default increment size is one. . loops are used to reduce the amount of coding. 2 and 3 as the loop runs. if what’s put in the body of the loop is coded with an error. lags(3) where the indicated number of lags is used.3209 H0: no serial correlation It is clear that the residuals of the ADF(2) are autocorrelated and those of the ADF(3) are not.478 -2. estat bgodfrey. dfuller lc. The first line must end with a left brace {. here is the example for income: forvalues p = 1/3 { qui reg L(0/`p'). Thus p will be set at 1. It starts with forvalues p.995 Number of obs = 196 Interpolated Dickey-Fuller 1% Critical 5% Critical 10% Critical Value Value Value -3.D. then all of your results will be wrong! At any rate. In the body of the loop are the regression.0196 0.499 df 1 2 3 Prob > chi2 di "Lags =" `p' estat L. lags(1 2 3) Breusch-Godfrey LM test for autocorrelation lags(p) 1 2 3 chi2 5.8122 0. lags(1 2 3) Breusch-Godfrey LM test for autocorrelation lags(p) 1 2 3 chi2 0.884 -2. Two side benefits are 1) less output and 2) smaller probability of a coding error.D. qui reg L(0/3).3148 0.2886 Note also that this regression contains a constant and that the test statistic is −1. where p is the counter.795 df 1 2 3 Prob > chi2 0. a display statement to indicate the lag length. Of course.0504 H0: no serial correlation .lc . the loop structure is fairly easy to use.0634 0. estat L.574 MacKinnon approximate p-value for Z(t) = 0.518 7.995. and a call to the post- .

After initializing the counter.0673 The p-value is less than 10% but larger than 5%. dfuller ly. the output is a lot neater looking since none of the commands are echoed to the screen. The loop has to be closed on a separate line using a right brace }.e.542 df 1 2 3 Prob > chi2 0. p.5523 chi2 2.883 -2.6916 0. no lagged differences of ly are included as regressors (i.880 df 1 2 3 Prob > chi2 0. The output is: Lags =1 Breusch-Godfrey LM test for autocorrelation lags(p) 1 2 3 Lags =2 Breusch-Godfrey LM test for autocorrelation lags(p) 1 2 3 Lags =3 Breusch-Godfrey LM test for autocorrelation lags(p) 1 2 3 chi2 0.539 2.271 2.077 2.4105 H0: no serial correlation H0: no serial correlation H0: no serial correlation If nothing else. lags(0) Dickey-Fuller test for unit root Test Statistic Z(t) -2.098 df 1 2 3 Prob > chi2 0.2401 0.5297 0. Recall that the cointegrating relationship can be estimated using least squares. Ct = β1 + β2Yt + vt The residuals from this regression are obtained and their changes are regressed on the lagged value ˆt = γe ˆt −1 + δ∆e ˆt −1 + vt ∆e .1495 0.157 1.estimation command bgodfrey.853 2. The Dickey-Fuller test yields: . the regular Dickey-Fuller regression). This is as it appears in the first two lines of the loop’s body.6487 0.2810 0.477 -2. it must be referred to in single quotes (left ` and right ‘—which as you may recall are different characters on the keyboard). It’s your call as to whether you are convinced that the unit root is rejected.573 MacKinnon approximate p-value for Z(t) = 0..741 Number of obs = 199 Interpolated Dickey-Fuller 1% Critical 5% Critical 10% Critical Value Value Value -3.208 2. For this series.4677 chi2 0.

Also added is the step(12) option.L. which in this case is lag 1 to lag 1.37. lags(1/1) step(12) nograph The syntax lags(1/1) tells Stata to include lags from the first number to the last. If your VAR is longer than 1 lag then you’ll change that here. In this case. The equations are linear and least squares can be used to estimate the parameters.ehat]/_se[L. and hence that the relationship between C (i. The 5% critical value of the test for stationarity in the cointegrating residuals is −3.37.8728997 Note that an intercept term has been included here to capture the component of (log) consumption that is independent of disposable income. estimate the coefficients of the model using a VAR in D. ln(RPCE)) and Y (i. we have no cointegration. ln(RPDI)) is spurious—that is.ehat] -2.ehat D. The easiest route is to use the varbasic command.ehat]/_se[L. The output from this is: .e. In our example.e. You need to specify the variables in the system (∆yt and ∆xt) and the number of lags to include on the right-hand-side of the model. The varbasic command simplifies this. varbasic fits a basic vector autoregressive (VAR) model and graphs the impulse-response functions (IRFs) or the forecast-error variance decompositions (FEVDs). but the differences are stationary.873 is greater than −3.ehat] . This option is useful in generating forecasts. Since the unit root t-value of −2.ehat L.The Stata code for this procedure is: reg lc ly predict ehat. Each difference is a linear function of it own lagged differences and of lagged differences of each of the other variables in the system. only 1 lag is included and the syntax to estimate the VAR is: varbasic D. di _b[L. The basic structure of the VAR is found in the equations below: ∆yt = β11∆yt −1 + β12 ∆xt −1 + vt∆y ∆xt = β21∆yt −1 + β22 ∆xt −1 + vt∆x The variables xt and yt are nonstationary. res reg D.. The VAR is simple to estimate in Stata. a topic covered next.ehat. it indicates that the errors are not stationary.. noconst di _b[L.

Err. and the Hannan and Quinn information criterion (HQIC) lag-order selection statistics for a series of vector autoregressions.2616765 .000 . z P>|z| [95% Conf.5086 5.286122 -.0007516 2.000 .4754276 -.0702164 .008562 R-sq 0. This can be used to find lag lengths for VAR or VEC models of unknown order. D_lc lc LD. Interval] .04957 0.004 0.0060367 . it would probably be a good idea to test the residuals of the VAR for autocorrelation.0041187 . _cons .3609972 ..444 2.0853 = -14.61 7.04496 = -13.6784 df 4 4 Prob > chi2 0. ly LD.0746013 . varlmar Lagrange-multiplier test lag 1 2 chi2 9.0067507 .91 2.92656 P>chi2 0.12459 24. For the example above Stata yields: . of obs AIC HQIC SBIC chi2 27.0741801 .0052776 Std. Schwarz's Bayesian information criterion (SC). The Stata command varlmar issued after varbasic will perform a LM test of the residuals similar to the ones we performed for autocorrelation.91 6. Akaike's information criterion (AIC). In practice.0079547 In light of the fact that longer lags were used in the Dickey-Fuller regressions it is likely that the VAR should also have longer lags.0000 0. ly LD. Stata includes another procedure that makes selecting lag lengths in VAR models very easy.070952 .ly.6647332 -.1493798 .004 0.006575 .0370832 .0000 = 198 = -14. _cons D_ly lc LD.02 D.009 0.17 0.0038046 .2171679 .92 -2. The varsoc command reports the final prediction error (FPE).0009786 4.000 0. .1205 0.1118 No.2156068 . lags(1/1) step(12) nograph Vector autoregression Sample: 1960q3 Log likelihood = FPE = Det(Sigma_ml) = Equation D_lc D_ly 2009q4 1400.98565 Coef.3633839 .62e-09 2.22449 H0: no autocorrelation at lag order There is evidence of autocorrelation in the residuals since the p-value at lag 1 is less than 5%.46e-09 Parms 3 3 RMSE .0965863 .0572953 . varbasic D.

7149 df 4 4 4 4 p 0.9996 -13.8772 195 Endogenous: Exogenous: D.2009q4 lag 0 1 2 3 4 LL D.6e-09 2.0882 HQIC -13.0422* -14. SBIC) chooses 1. maxlag(4) Selection-order criteria Sample: 1961q2 .02 1379.8436 -13.6 LR 48.0948* -14.6e-09 Number of obs AIC -13.0915 -14. varsoc D.6655* 8.129 9.083 -14.6379 6.046 0.9659 = SBIC -13.8636 -14. .152 FPE 3.6e-09* 2.0235 _cons The AIC selects a lag order of 3 while the SC (labeled by Stata.000 0.24 1391.09 1383.8598 -13.2e-09 2..6e-09 2.9237 -13.9823* -13.92 1388.071 D.