Resources

Details Example for PROC VARMAX

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: vardt.sas
 Description: Example program from SAS/ETS User's Guide,
              The VARMAX Procedure
       Title: Details Example for PROC VARMAX
     Product: SAS/ETS Software
        Keys: Vector AutoRegressive Moving-Average
              processes with eXogenous regressors
        PROC: VARMAX
       Notes:

--------------------------------------------------------------*/

proc iml;
   sig = {1.0  0.5, 0.5 1.25};
   phi = {1.2 -0.5, 0.6 0.3};
   /* simulate the vector time series */
   call varmasim(y,phi) sigma = sig n = 100 seed = 34657;
   cn = {'y1' 'y2'};
   create simul1 from y[colname=cn];
   append from y;
quit;

data simul1;
   set simul1;
   date = intnx( 'year', '01jan1900'd, _n_-1 );
   format date year4.;
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint print=(dynamic);
run;

data grunfeld;
   input year y1 y2 y3 x1 x2 x3;
   label y1='Gross Investment GE'
         y2='Capital Stock Lagged GE'
         y3='Value of Outstanding Shares GE Lagged'
         x1='Gross Investment W'
         x2='Capital Stock Lagged W'
         x3='Value of Outstanding Shares Lagged W';
datalines;
1935  33.1 1170.6  97.8 12.93  191.5   1.8
1936  45.0 2015.8 104.4 25.90  516.0    .8
1937  77.2 2803.3 118.0 35.05  729.0   7.4
1938  44.6 2039.7 156.2 22.89  560.4  18.1
1939  48.1 2256.2 172.6 18.84  519.9  23.5
1940  74.4 2132.2 186.6 28.57  628.5  26.5
1941 113.0 1834.1 220.9 48.51  537.1  36.2
1942  91.9 1588.0 287.8 43.34  561.2  60.8
1943  61.3 1749.4 319.9 37.02  617.2  84.4
1944  56.8 1687.2 321.3 37.81  626.7  91.2
1945  93.6 2007.7 319.6 39.27  737.2  92.4
1946 159.9 2208.3 346.0 53.46  760.5  86.0
1947 147.2 1656.7 456.4 55.56  581.4 111.1
1948 146.3 1604.4 543.4 49.56  662.3 130.6
1949  98.3 1431.8 618.3 32.04  583.8 141.8
1950  93.5 1610.5 647.4 32.24  635.2 136.7
1951 135.2 1819.4 671.3 54.38  723.8 129.7
1952 157.3 2079.7 726.1 71.78  864.1 145.5
1953 179.5 2371.6 800.3 90.08 1193.5 174.8
1954 189.6 2759.9 888.9 68.60 1188.9 213.5
;


proc varmax data=grunfeld plot=impulse;
   model y1-y3 = x1 x2 / p=1 lagmax=5
                         printform=univariate
                         print=(impulsx=(all) estimates);
run;

proc varmax data=simul1 plot=impulse;
   model y1 y2 / p=1 noint lagmax=5
                 print=(impulse=(all))
                 printform=univariate;
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint lagmax=5
                 printform=both
                 print=(decompose(5) impulse=(all) covpe(5));
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint print=(decompose(15))
                 printform=univariate;
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint lagmax=3 print=(corry)
                 printform=univariate;
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint lagmax=3
                 printform=univariate
                print=(corry parcoef pcorr
                       pcancorr roots);
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint lagmax=3
                 print=(pcorr)
                 printform=univariate;
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint lagmax=3 print=(pcancorr);
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint minic=(p=3 q=3);
run;

proc varmax data=simul1;
   model y1 y2 / p=1 noint print=(roots);
run;

proc varmax data=grunfeld;
   model y1 = x1, y2 = x2, y3 / p=1 print=(estimates);
run;

data One;
   format date date9.;
   do obs = 1 to 100;
      date=intnx('quarter','01Jan1990'd,obs-1);
      y1 = normal(1); y2 = normal(1); x = normal(1);
      output;
   end;
run;

proc varmax data=One;
   model y1 y2 = x / nseason=4 xlag=2 p=1 trend=quad;
run;

data Two;
   set one;
   y1lag1 = lag(y1); y2lag1 = lag(y2);
   xlag1 = lag(x); xlag2 = lag2(x);
   if (obs>2) then do;
      ltrend = obs - 2;
      qtrend = ltrend * ltrend;
      const = 1;
      if (mod(ltrend-2,4)=0) then sd1 = 1;
      else sd1 = 0;
      if (mod(ltrend-3,4)=0) then sd2 = 1;
      else sd2 = 0;
      if (mod(ltrend-4,4)=0) then sd3 = 1;
      else sd3 = 0;
   end;
run;

proc reg data=Two(firstobs=3);
   model y1 = const sd1 sd2 sd3 ltrend qtrend
              x xlag1 xlag2 y1lag1 y2lag1 / noint;
   model y2 = const sd1 sd2 sd3 ltrend qtrend
              x xlag1 xlag2 y1lag1 y2lag1 / noint;
run;

proc print data=Two(obs=11);
   var date const sd1 sd2 sd3 ltrend qtrend;
run;

proc iml;
   sig = {1.0  0.5, 0.5 1.25};
   phi = {1.2 -0.5, 0.6 0.3};
   theta = {0.5 -0.2, 0.1 0.3};
   /* to simulate the vector time series */
   call varmasim(y,phi,theta) sigma=sig n=100 seed=34657;
   cn = {'y1' 'y2'};
   create simul3 from y[colname=cn];
   append from y;
run;

proc varmax data=simul3;
   nloptions tech=qn;
   model y1 y2 / p=1 q=1 noint print=(estimates);
run;

proc iml;
   sig = 100*i(2);
   phi = {-0.2 0.1, 0.5 0.2, 0.8 0.7, -0.4 0.6};
   call varmasim(y,phi) sigma=sig n=100 initial=0
                        seed=45876;
   cn = {'y1' 'y2'};
   create simul2 from y[colname=cn];
   append from y;
quit;

data simul2;
   set simul2;
   date = intnx( 'year', '01jan1900'd, _n_-1 );
   format date year4. ;
run;

proc varmax data=simul2;
   model y1 y2 / p=2 cointtest=(sw);
run;

proc varmax data=simul2;
   model y1 y2 / p=2 cointtest=(johansen=(normalize=y1));
run;

proc varmax data=simul2;
   model y1 y2 / p=2 print=(estimates);
   cointeg rank=1 normalize=y1 ectrend;
run;

proc varmax data=simul2;
   model y1 y2 / p=2 print=(estimates);
   cointeg rank=1 normalize=y1;
run;

proc varmax data=simul2;
   model y1 y2 / p=2;
   cointeg rank=1 h=(1,-2) normalize=y1;
run;

proc varmax data=simul2;
   model y1 y2 / p=2;
   cointeg rank=1 exogeneity normalize=y1;
run;

proc iml;
   alpha  = { 1, 1};    * alphaOrthogonal = { 1, -1};
   beta   = { 1, -0.5}; * betaOrthogonal  = { 1, 2};
   * alphaOrthogonal' * phiStar * betaOrthogonal = 0;
   phiStar = { 1 0, 0 0.5};
   A1 = 2 * I(2) + alpha * beta` - phiStar;
   A2 = phiStar - I(2);
   phi = A1 // A2;
   sig = I(2);
   /* to simulate the vector time series */
   call varmasim(y,phi) sigma=sig n=200 seed=2;
   cn = {'y1' 'y2'};
   create simul4 from y[colname=cn];
   append from y;
   close;
quit;

proc varmax data=simul4;
   model y1 y2 /noint p=2 cointtest=(johansen=(iorder=2));
run;

data garch;
   retain seed 16587;
   esq1 = 0; esq2 = 0;
   ly1 = 0;  ly2 = 0;
   do i = 1 to 1000;
      ht = 6.25 + 0.5*esq1;
      call rannor(seed,ehat);
      e1 = sqrt(ht)*ehat;
      ht = 1.25 + 0.7*esq2;
      call rannor(seed,ehat);
      e2 = sqrt(ht)*ehat;
      y1 = 2 + 1.2*ly1 - 0.5*ly2 + e1;
      y2 = 4 + 0.6*ly1 + 0.3*ly2 + e2;
      if i>500 then output;
      esq1 = e1*e1; esq2 = e2*e2;
      ly1 = y1;  ly2 = y2;
   end;
   keep y1 y2;
run;

proc varmax data=garch;
   model y1 y2 / p=1
         print=(roots estimates diagnose);
   garch q=1;
   nloptions tech=qn;
run;

proc varmax data=simul1 noprint;
   id date interval=year;
   model y1 y2 / p=1 noint;
   output out=out lead=5;
run;

proc print data=out(firstobs=98);
run;

proc varmax data=simul2 outest=est;
   model y1 y2 / p=2 noint noprint;
   cointeg rank=1 normalize=y1;
run;

proc print data=est;
run;

data garch;
   set garch;
   date = intnx( 'month', '01may1972'd, _n_-1 );
   format date yymms.;
run;

proc varmax data=garch;
   id date interval=month;
   model y1 y2 / p=1;
   garch q=1 outht=ht;
   output out=og lead=6;
run;

proc print data=og(obs=8);
   var date y1 for1 std1 lci1 uci1 y2 for2 std2 lci2 uci2;
run;

proc print data=ht(obs=8);
run;

proc print data=og(firstobs=499);
   var date y1 for1 std1 lci1 uci1 y2 for2 std2 lci2 uci2;
run;

proc print data=ht(firstobs=499);
run;

proc varmax data=simul2 outstat=stat;
   model y1 y2 / p=2 noint noprint
                 cointtest=(johansen=(iorder=2));
   cointeg rank=1 normalize=y1;
run;

proc print data=stat;
run;