First of all, thank you for creating such a powerful toolbox. To improve it, I'd like to point out a bug in the historical decomposition functions. I am using BVAR option with sign restrictions and HD. But I believe the issue will be present with any model as long as HD computation scripts are used.
When there are more than 1 exogenous variable, the variable "contributors" in the hd-related scripts includes the number of exogenous variables. However when it comes to calculating and plotting HD, it uses only the total contribution from the exogenous variables altogether, not individually. Thus the code gives an error since there need more contributors than computed.
For example this the error message:
Index in position 1 exceeds array bounds (must not exceed 11).
Error in bear.hdecomp_inc_exo (line 78)
hd_record{kk,ll}(ii,:) = HDstorage{ii,1}{kk,ll}(2,:);
Error in BEARmain (line 1071)
[hd_record,favar]=bear.hdecomp_inc_exo(beta_gibbs,D_record,opts.It,opts.Bu,Y,X,n,m,p,k,T,data_exo,exo,endo,const,IRFt,strctident,favar);
To fix this, one might simply change the following command
Thanks for reporting that, could check if in your models you where using a constant? i.e. opts.const? I believe a similar error occurs when there is 1 exovar + constant
Hello,
First of all, thank you for creating such a powerful toolbox. To improve it, I'd like to point out a bug in the historical decomposition functions. I am using BVAR option with sign restrictions and HD. But I believe the issue will be present with any model as long as HD computation scripts are used.
When there are more than 1 exogenous variable, the variable "contributors" in the hd-related scripts includes the number of exogenous variables. However when it comes to calculating and plotting HD, it uses only the total contribution from the exogenous variables altogether, not individually. Thus the code gives an error since there need more contributors than computed.
For example this the error message:
To fix this, one might simply change the following command
contributors = n + 1 + length(exo) + 1; %variables + constant + exogenous + initial conditions
to
contributors = n + 1 + double(length(exo)>0) + 1; %variables + constant + exogenous + initial conditions
orcontributors = n + 1 + double(~isempty(exo)) + 1; %variables + constant + exogenous + initial conditions
I verified that the new command fixes the bug. But the change has to be made consistently in each hd-related script.
I hope this helps.
Cheers, K.