From 7d854cec94df6deb6f1f9d02e8e28d6b76c79776 Mon Sep 17 00:00:00 2001
From: michel <michel@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Tue, 24 Mar 2009 13:28:45 +0000
Subject: [PATCH] 4.1: fixed problem in AIM implementation when some lagged
 variables are present in the model but with zero coefficient.

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2516 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 matlab/AIM/dynAIMsolver1.m | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/matlab/AIM/dynAIMsolver1.m b/matlab/AIM/dynAIMsolver1.m
index e6970dadaa..a1b25183d9 100644
--- a/matlab/AIM/dynAIMsolver1.m
+++ b/matlab/AIM/dynAIMsolver1.m
@@ -100,7 +100,15 @@ if aimcode==1 %if OK
         col_order=[((i-1)*neq)+dr.order_var' col_order];
     end
     bb_ord= bb(dr.order_var,col_order); % derive ordered gy
-    dr.ghx= bb_ord(:,find(any(bb_ord,1))); % get non-zero columns only
+    
+    % variables are present in the state space at the lag at which they
+    % appear and at all smaller lags. The are ordered from smaller to
+    % higher lag (reversed order of M_.lead_lag_incidence rows for lagged
+    % variables)
+    i_lagged_vars = flipud(cumsum(M_.lead_lag_incidence(1:M_.maximum_lag,dr.order_var),1))';
+
+    dr.ghx= bb_ord(:,find(i_lagged_vars(:))); % get columns reported in
+                                              % Dynare solution
     if M_.exo_nbr % if there are exogenous shocks then derive gu for the shocks:
     %   get H0 and H+1=HM
     %    theH0= theAIM_H (:,M_.maximum_endo_lag*neq+1: (M_.maximum_endo_lag+1)*neq);
-- 
GitLab