1function [nonsing,b] = SPReduced_form(q,qrows,qcols,bcols,neq,condn) 2% [nonsing,b] = SPReduced_form(q,qrows,qcols,bcols,neq,b,condn); 3% 4% Compute reduced-form coefficient matrix, b. 5 6% Original author: Gary Anderson 7% Original file downloaded from: 8% http://www.federalreserve.gov/Pubs/oss/oss4/code.html 9% Adapted for Dynare by Dynare Team. 10% 11% This code is in the public domain and may be used freely. 12% However the authors would appreciate acknowledgement of the source by 13% citation of any of the following papers: 14% 15% Anderson, G. and Moore, G. 16% "A Linear Algebraic Procedure for Solving Linear Perfect Foresight 17% Models." 18% Economics Letters, 17, 1985. 19% 20% Anderson, G. 21% "Solving Linear Rational Expectations Models: A Horse Race" 22% Computational Economics, 2008, vol. 31, issue 2, pages 95-113 23% 24% Anderson, G. 25% "A Reliable and Computationally Efficient Algorithm for Imposing the 26% Saddle Point Property in Dynamic Models" 27% Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3, 28% pages 472-489 29 30b=[]; 31%qs=SPSparse(q); 32qs=sparse(q); 33left = 1:qcols-qrows; 34right = qcols-qrows+1:qcols; 35nonsing = rcond(full(qs(:,right))) > condn; 36if(nonsing) 37 qs(:,left) = -qs(:,right)\qs(:,left); 38 b = qs(1:neq,1:bcols); 39 b = full(b); 40else %rescale by dividing row by maximal qr element 41 %'inverse condition number small, rescaling ' 42 themax=max(abs(qs(:,right)),[],2); 43 oneover = diag(1 ./ themax); 44 nonsing = rcond(full(oneover *qs(:,right))) > condn; 45 if(nonsing) 46 qs(:,left) = -(oneover*qs(:,right))\(oneover*(qs(:,left))); 47 b = qs(1:neq,1:bcols); 48 b = full(b); 49 end 50end 51