In my yesterday message on this subject, my understanding of the initialization of persistent variable 'penaly' in dsge_likelihood.m and dsge_likelihood_hh.m was wrong. I reverted my addition of explicit initialization and added the following comment in both functions. I also added a call to dsge_likelihood_hh() in initial_estimation_check.m to make sure that penalty was correctly iniitialized in this function as well. In the present case, the difficulty with persistent variables is compounded by the fact that penalty is not used in all contexts, only when dsge_likelihood() or dsge_likelihood_hh() is called by an optimizer.
Comment added: % Persistent variable 'penalty' is used to compute an endogenous penalty to % the value 'fval' when various conditions are encountered. These conditions % set also 'exit_flag' equal to 0 instead of 1. It is only when % dsge_likelihood() is called by an optimizer called by % dynare_estimation_1() that 'exit_flag' is ignored and penalized 'fval' is % actually used. % In that case, 'penalty' is properly initialized, at the very end of the % present function, by a call to dsge_likelihood() made in % initial_estimation_checks(). If a condition triggers exit_flag == % 0, initial_estimation_checks() triggers an error. % In summary, an initial call to the present function, without triggering % any condition, guarantees that 'penalty' is properly initialized when needed.
Best
Michel