/* We conduct an out-of-sample forecasting test of the efficiency of a simulated VAR in Differences with lag length equal to 2 (p=2). Its competitors are a Levels VAR which, as the sample size goes to infinity, will converge to the differenced VAR but estimation (and thus forecasting) will be inefficient given that the restrictions implied by the unit roots are ignored. In addition, we examine the forecasting efficiency of a Bayesian VAR with a pretty tight Minnesota (Random Walk) prior imposed. Of course, the Bayesian VAR is misspecified in that no second order differencing is imposed and the second order term has a prior mean of zero which is inconsistent with the VAR in differences of the second order. However, the Bayesian VAR, despite its misspecifications, could possibly perform better than the Levels VAR in finite samples. Here we set the forecast horizon at h = 3. The specification we are going to consider here is the following: (1) y(t,1) = phi(0,1) + 0.7y(t-1,1) + 0.3y(t-2,1) + 0.6y(t-1,2) - 0.6y(t-2,2) + error (2) y(t,2) = phi(0,2) + 0.6y(t-1,1) - 0.6y(t-2,1) + 0.7y(t-1,2) + 0.3y(t-2,2) + error Without loss of generality we set phi(0,1)=phi(0,2)=0 as they only affect the means of the two series. Using the Phi matrix notation for the prior mean in the Proc Varmax documentation we have Phi = [ 0.7 0.6 0.3 -0.6 ] [ 0.6 0.7 -0.6 0.3 ] which is a 2 x 4 matrix and the Phi1 and Phi2 matrices are arranged horizontally. In the Varmasim subroutine the Phi matrix is defined differently. It is defined as Phi = [ 0.7 0.6 ] [ 0.6 0.7 ] [ 0.3 -0.6 ] [ -0.6 0.3 ] and the Phi1 and Phi2 matrices are stacked vertically. */ /* Here we are taking the sample size to be 500. */ Options nodate; %macro main(rseed); proc iml; sig = 100*i(2); phi = {0.7 0.6, 0.6 0.7, 0.3 -0.6, -0.6 0.3}; call varmasim(y,phi) sigma = sig n = 500 initial = 0 seed = &rseed; cn = {'y1' 'y2'}; create simul2 from y[colname=cn]; append from y; quit; data simul2; set simul2; t+1; %macro difvar(num); proc varmax data=simul2(obs=&num) noprint; model y1 y2 / p=2 noint dify=(1); output out=result1 lead=3 back=0; run; data result1; set result1; difvarf1 = for1; difvarf2 = for2; if _n_ = &num + 3; keep difvarf1 difvarf2; proc append base=collect1 data=result1; %mend; %macro doit; %do ii=400 %to 497; %difvar(&ii); %end; %mend; %doit; /* Roll the levels VAR through the hold-out sample data (observations 401 - 500) forecasting three periods ahead each time. */ %macro levelsvar(num); proc varmax data=simul2(obs=&num) noprint; model y1 y2 / p=2 noint; output out=result2 lead=3 back=0; run; data result2; set result2; levelsvarf1 = for1; levelsvarf2 = for2; if _n_ = &num + 3; keep levelsvarf1 levelsvarf2; proc append base=collect2 data=result2; %mend; %macro doit2; %do ii=400 %to 497; %levelsvar(&ii); %end; %mend; %doit2; /* Roll the Bayesian VAR with Minnesota Priors through the hold-out sample data (observations 401 - 500) forecasting three periods ahead each time. In the prior mean vector we specify that the AR(2) coefficients for each equation add to one, recognizing that their is a unit root but specifying zero mean priors otherwise. For lack of anything else we specify theta and lambda at their default values. */ %macro Bayesvar(num); proc varmax data=simul2(obs=&num) noprint; model y1 y2 / p=2 noint prior=( mean=(0.7 0 0.3 0 0 0.7 0 0.3) theta=0.1 lambda=1.0); output out=result3 lead=3 back=0 noprint; run; data result3; set result3; bayesvarf1 = for1; bayesvarf2 = for2; if _n_ = &num + 3; keep bayesvarf1 bayesvarf2; proc append base=collect3 data=result3; %mend; %macro doit3; %do ii=400 %to 497; %Bayesvar(&ii); %end; %mend; %doit3; data actual; set simul2; if 402 < _n_; actualy1 = y1; actualy2 = y2; keep actualy1 actualy2; data compare; merge actual collect1 collect2 collect3; keep actualy1 actualy2 difvarf1 difvarf2 levelsvarf1 levelsvarf2 bayesvarf1 bayesvarf2; data errors; set compare; difvare1 = actualy1 - difvarf1; difvare2 = actualy2 - difvarf2; levelsvare1 = actualy1 - levelsvarf1; levelsvare2 = actualy2 - levelsvarf2; bayesvare1 = actualy1 - bayesvarf1; bayesvare2 = actualy2 - bayesvarf2; absdifvare1 = abs(difvare1); absdifvare2 = abs(difvare2); abslevelsvare1 = abs(levelsvare1); abslevelsvare2 = abs(levelsvare2); absbayesvare1 = abs(bayesvare1); absbayesvare2 = abs(bayesvare2); difvare12 = difvare1**2.0; difvare22 = difvare2**2.0; levelsvare12 = levelsvare1**2.0; levelsvare22 = levelsvare2**2.0; bayesvare12 = bayesvare1**2.0; bayesvare22 = bayesvare2**2.0; /* Calculate the MAEs and MSEs of the Competing Models. */ proc univariate data=errors noprint; var absdifvare1 abslevelsvare1 absbayesvare1 absdifvare2 abslevelsvare2 absbayesvare2 difvare12 levelsvare12 bayesvare12 difvare22 levelsvare22 bayesvare22; output mean = maedifvar1 maelevelsvar1 maebayesvar1 maedifvar2 maelevelsvar2 maebayesvar2 msedifvar1 mselevelsvar1 msebayesvar1 msedifvar2 mselevelsvar2 msebayesvar2 out = results; run; proc append base=collect4 data=results; run; /* delete DATA SETS collect1, collect 2, and collect3 */ proc datasets lib=work mt=data nolist; delete collect1 collect2 collect3; run; %mend; /* end of main macro */ %macro doit4; %do i=1 %to 10; %main(654701+&i); %end; %mend; %doit4; /* Print the Forecasting Accuracies of the the Competing Methods */ proc print data=collect4; var maedifvar1 maelevelsvar1 maebayesvar1 maedifvar2 maelevelsvar2 maebayesvar2 msedifvar1 mselevelsvar1 msebayesvar1 msedifvar2 mselevelsvar2 msebayesvar2; title 'Forecasting Accuracy Measures of Competing Methods'; title2 'Forecast Horizon = 3'; run; data count; set collect4; if maedifvar1 < maelevelsvar1 and maedifvar1 < maebayesvar1 then maedifvar1c = 1; else maedifvar1c = 0; if maelevelsvar1 < maedifvar1 and maelevelsvar1 < maebayesvar1 then maelevelsvar1c = 1; else maelevelsvar1c = 0; if maebayesvar1 < maedifvar1 and maebayesvar1 < maelevelsvar1 then maebayesvar1c = 1; else maebayesvar1c = 0; if msedifvar1 < mselevelsvar1 and msedifvar1 < msebayesvar1 then msedifvar1c = 1; else msedifvar1c = 0; if mselevelsvar1 < msedifvar1 and mselevelsvar1 < msebayesvar1 then mselevelsvar1c = 1; else mselevelsvar1c = 0; if msebayesvar1 < msedifvar1 and msebayesvar1 < mselevelsvar1 then msebayesvar1c = 1; else msebayesvar1c = 0; if maedifvar2 < maelevelsvar2 and maedifvar2 < maebayesvar2 then maedifvar2c = 1; else maedifvar2c = 0; if maelevelsvar2 < maedifvar2 and maelevelsvar2 < maebayesvar2 then maelevelsvar2c = 1; else maelevelsvar2c = 0; if maebayesvar2 < maedifvar2 and maebayesvar2 < maelevelsvar2 then maebayesvar2c = 1; else maebayesvar2c = 0; if msedifvar2 < mselevelsvar2 and msedifvar2 < msebayesvar2 then msedifvar2c = 1; else msedifvar2c = 0; if mselevelsvar2 < msedifvar2 and mselevelsvar2 < msebayesvar2 then mselevelsvar2c = 1; else mselevelsvar2c = 0; if msebayesvar2 < msedifvar2 and msebayesvar2 < mselevelsvar2 then msebayesvar2c = 1; else msebayesvar2c = 0; proc print data = count; run; /* Calculate the average performances of the Competing Models. */ proc univariate data=count noprint; var maedifvar1c maelevelsvar1c maebayesvar1c msedifvar1c mselevelsvar1c msebayesvar1c maedifvar2c maelevelsvar2c maebayesvar2c msedifvar2c mselevelsvar2c msebayesvar2c; output mean = maedifvar1p maelevelsvar1p maebayesvar1p msedifvar1p mselevelsvar1p msebayesvar1p maedifvar2p maelevelsvar2p maebayesvar2p msedifvar2p mselevelsvar2p msebayesvar2p out = results; run; title 'Proportion of Wins for each method and given variable and measure'; title2 'Forecast Horizon = 3'; proc print data = results; run;