Hi All
Here is a follow-up to my previous post
The following code will print output in the command window, to be pasted in the estimated_param_init block and the calibration (of deep parameters) section that follows after the parameter names are first declared.
When I code, the order in which I declare the parameters is preserved in all sections (initial declaration, calibration, priors, initial values, bounds).
The code below is written to suit that style, and has not been tested for cases when the order of declaration is different from time to time. I am not sure if order of declaration matters for the order in which the names of shocks and parameters are save in the oo_ structure.
Cheers
Reuben
% Make initialisation and calibration values for next DYNARE estimation
firstestimparastr='alpha'; % Define the name of first structural parameter that is estimated
%Create vector of IRIS parameter and shock names
estimnames4dynare = [fieldnames(oo_.posterior_mode.shocks_std); fieldnames(oo_.posterior_mode.parameters)] ;
% Concatenate tables
mergetables4dynare = [struct2table(oo_.posterior_mode.shocks_std), struct2table(oo_.posterior_mode.parameters) ];
posteriormode4dynare=table2struct(mergetables4dynare);
posteriormodevals4dynare=structfun(@(xeval) xeval(:), posteriormode4dynare);
exoestim=cell(M_.exo_nbr,1);
shockstdnames=fieldnames(oo_.posterior_mode.shocks_std);
for ii=1:M_.exo_nbr
exoestim(ii,:)= cellstr(['stderr ' shockstdnames{ii}]);
end
bayestopt_.name(1:M_.exo_nbr,:)=exoestim; % Replace the shock names in the vector with 'stderr shocknames'
a= bayestopt_.name ;
b =repmat(',',numel(bayestopt_.name),1); % Dynare uses ',' for the estimated_parameters_init section
b1 =repmat('=',numel(bayestopt_.name),1); % Dynare uses '=' for the calibration section
c = num2str(posteriormodevals4dynare,'%.10f') ; % Convert parameter value to string, and control number of digits
d=repmat(';',numel(bayestopt_.name),1); % Dynare syntax
e=repmat(' % ',numel(bayestopt_.name),1); % For comment that defines longname of parameter
estpara1=find(ismember(cellstr(M_.param_names),firstestimparastr));
estimparalongnames=cellstr(M_.param_names_long(estpara1:end,:)); % Can be avoided if we do not desire to use long names
shocklongnames=cellstr(M_.exo_names_long);% Can be avoided if we do not desire to use long names
f=[shocklongnames;estimparalongnames];% Can be avoided if we do not desire to use long names
disp('=====================================================================')
disp('Paste into estimated_parameters_init block for next dynare estimation')
disp('=====================================================================')
disp(char(strcat(a,b,c,d,e,f)))% e and f can be avoided if we do not desire to use long names
disp('=====================================================================')
gg=strcat(a,b1,c,d,e,f); % Concatenate all , % e and f can be avoided if we do not desire to use long names
gg=gg(M_.exo_nbr+1:end, :) % Start from first estimated structural parameter that appears after the shock std devs.
disp('==============================')
disp('Paste into calibration section')
disp('==============================')
disp(char(gg))