From 8ac3f4b22bbe57f4d7096e572d1faa13cdf368d6 Mon Sep 17 00:00:00 2001
From: Marco Ratto <marco.ratto@ec.europa.eu>
Date: Thu, 6 Jan 2022 14:59:33 +0100
Subject: [PATCH] fixed bugs in initialization of heteroskedastic shocks and
 first_obs>1 and nobs< full dimension of dataset

---
 matlab/dynare_estimation_init.m | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m
index 3cdd4c097e..5f0af2dbdf 100644
--- a/matlab/dynare_estimation_init.m
+++ b/matlab/dynare_estimation_init.m
@@ -671,12 +671,14 @@ if options_.heteroskedastic_filter
 
     for k=1:length(M_.heteroskedastic_shocks.Qvalue_orig)
         v = M_.heteroskedastic_shocks.Qvalue_orig(k);
-        temp_periods=v.periods(v.periods<=options_.nobs+options_.first_obs);
+        temp_periods=v.periods(v.periods<options_.nobs+options_.first_obs);
+        temp_periods=temp_periods(temp_periods>=options_.first_obs);
         M_.heteroskedastic_shocks.Qvalue(v.exo_id, temp_periods-(options_.first_obs-1)) = v.value^2;
     end
     for k=1:length(M_.heteroskedastic_shocks.Qscale_orig)
         v = M_.heteroskedastic_shocks.Qscale_orig(k);
-        temp_periods=v.periods(v.periods<=options_.nobs+options_.first_obs);
+        temp_periods=v.periods(v.periods<options_.nobs+options_.first_obs);
+        temp_periods=temp_periods(temp_periods>=options_.first_obs);
         M_.heteroskedastic_shocks.Qscale(v.exo_id, temp_periods-(options_.first_obs-1)) = v.scale^2;
     end
 
-- 
GitLab