% Matlab program file to accompany
% Christoffersen and Diebold (1997),
% "Cointegration and Long-Horizon Forecasting"
% Generate Example data 
% y1 is a randow walk
% y2= lam*y1 +noise

function [y,dy]=exar(Ti,Te,Tp,lam,sig2e,sig2v);

T=Ti+Te+Tp;

vnoise=[sig2e 0 ; 0 sig2v];
epsi=(vnoise)^(.5)*randn(2,T);
y=zeros(2,T);
dy=zeros(2,T);
y(:,1)=epsi(:,1);

for t=2:T;
    y(1,t)=y(1,t-1) + epsi(1,t);
    y(2,t)=lam*y(1,t) + epsi(2,t);
    dy(:,t)=y(:,t)-y(:,t-1);
end;
% Transpose and cut off initial sequence
y=y(:,Ti+1:T)'; 
dy=dy(:,Ti+1:T)';      