


[a,ia,js] = SPBuild_a(h,qcols,neq)
Build the companion matrix, deleting inessential lags.
Solve for x_{t+nlead} in terms of x_{t+nlag},...,x_{t+nlead-1}.

0001 % [a,ia,js] = SPBuild_a(h,qcols,neq) 0002 % 0003 % Build the companion matrix, deleting inessential lags. 0004 % Solve for x_{t+nlead} in terms of x_{t+nlag},...,x_{t+nlead-1}. 0005 0006 % Original author: Gary Anderson 0007 % Original file downloaded from: 0008 % http://www.federalreserve.gov/Pubs/oss/oss4/code.html 0009 % Adapted for Dynare by Dynare Team. 0010 % 0011 % This code in the public domain and may be used freely. 0012 % However the authors would appreciate acknowledgement of the source by 0013 % citation of any of the following papers: 0014 % 0015 % Anderson, G. and Moore, G. 0016 % "A Linear Algebraic Procedure for Solving Linear Perfect Foresight 0017 % Models." 0018 % Economics Letters, 17, 1985. 0019 % 0020 % Anderson, G. 0021 % "Solving Linear Rational Expectations Models: A Horse Race" 0022 % Computational Economics, 2008, vol. 31, issue 2, pages 95-113 0023 % 0024 % Anderson, G. 0025 % "A Reliable and Computationally Efficient Algorithm for Imposing the 0026 % Saddle Point Property in Dynamic Models" 0027 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3, 0028 % pages 472-489 0029 0030 function [a,ia,js] = SPBuild_a(h,qcols,neq) 0031 0032 left = 1:qcols; 0033 right = qcols+1:qcols+neq; 0034 %hs=SPSparse(h); 0035 hs=sparse(h); 0036 0037 hs(:,left) = -hs(:,right)\hs(:,left); 0038 0039 % Build the big transition matrix. 0040 0041 a = zeros(qcols,qcols); 0042 0043 if(qcols > neq) 0044 eyerows = 1:qcols-neq; 0045 eyecols = neq+1:qcols; 0046 a(eyerows,eyecols) = eye(qcols-neq); 0047 end 0048 hrows = qcols-neq+1:qcols; 0049 a(hrows,:) = hs(:,left); 0050 0051 % Delete inessential lags and build index array js. js indexes the 0052 % columns in the big transition matrix that correspond to the 0053 % essential lags in the model. They are the columns of q that will 0054 % get the unstable left eigenvectors. 0055 0056 js = 1:qcols; 0057 zerocols = sum(abs(a)) == 0; 0058 while( any(zerocols) ) 0059 a(:,zerocols) = []; 0060 a(zerocols,:) = []; 0061 js(zerocols) = []; 0062 zerocols = sum(abs(a)) == 0; 0063 end 0064 ia = length(js);