I am trying to find the optimal variables of monetary policy that maximize welfare. I have taken codes
(i.e., commands at the end of mod file after stoch_simul, and welfare_objective.m) from the forum. They work with some other mod files provided in different topics in this forum. However, when I run the code with my mod file it gives me the following error:

Unable to perform assignment because the left and right sides have a different number of elements.
Error in dyn_first_order_solver (line 227)
info(2) = temp’*temp;
Error in stochastic_solvers (line 262)
[dr,info] = dyn_first_order_solver(jacobia_,M_,dr,options_,task);
Error in resol (line 120)
[dr,info] = stochastic_solvers(dr,check_flag,M,options,oo);
Error in welfare_objective (line 17)
[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); %get decision rules
Error in csminwel (line 62)
f0 = fcn(x0,varargin{:});
Error in codenew.driver (line 436)
[fhat,x_opt_hat] = csminwel(@welfare_objective,x_start,H0,[],crit,nit,x_opt_name);
Error in dynare (line 293)
evalin(‘base’,[fname ‘.driver’])

I do not understand where the problem comes from. I will be thankful if someone can help me with this issue. I have attached the mod file and the welfare function. Two other files compute the steady state values.

It works fine now. However, whenever I change the initial values in x_start, I get different optimized parameters (i.e., in x_opt_hat). Moreover, when I set the same initial value for the parameters, I always get the same optimized values for the parameters. Does this imply a problem in the code?

I cannot understand which variable indicates the value of the objective function equal to 1e6.

I have tried the same code with a simpler mod file. The simulated version works without any error; however, I still face the same values for optimized parameters. I still get the same results even when I change the value that is supposed to be optimized inside the welfare_objective_1.m. So the results are the same no matter what I change inside welfare_objective_1.m.

I have another question too, do I need to make the parameters I am searching for equal to zero in the parameters block?

Thank you. It is working with these starting values-just one more questions: I get a very large value for the parameter responding to inflation in the monetary rule, e.g., 500 or so. Does it make any sense theoretically?

Thank you again. I have some follow-up questions regarding conditional and unconditional welfare. As far as I know and have read throughout the forum, unconditional welfare is the mean of a simulated series of welfare. Is this right?

Second, is the welfare maximized by welfare_objective.m (mentioned in the previous comments), conditional or unconditional?

I am also confused about the sign of welfare because the value given by fhat from this function is always positive when I use it in my code. However, the mean simulated welfare that I suppose to be unconditional is always negative. If I plot the value of welfare when a parameter changes using the following loop:

clear all
dynare giowithouttax
% get position of welfare in the variable list.
W_pos=strmatch('welf',M_.endo_names,'exact');
%% rho_r
grid = 0.0:0.1:0.9;
% mean of welfare
mean.W=zeros(length(grid),1);
% matrix for parameters values and correspondoing welfare values
results=zeros(2,length(grid));
first_time = 1;
for i = 1:length(grid)
if first_time
dynare giowithouttax noclearall;
first_time = 0;
else
set_param_value('rho_r',grid(i));
[info, oo_] = stoch_simul(M_, options_, oo_, var_list_);
if info
disp(['Computation fails for rho_r = ' num2str(rho_r)]);
else
mean.W(i)=oo_.mean(W_pos);
results(:,i)=[grid(i);mean.W(i)];
end
end
end

The values of parameters maximizing the welfare are more or less similar to those given by x_opt_hat, but the welfare value is always negative. Is there any problem in the code or maybe in my understanding?

Searching for the parameters maximizing welfare is sensitive to the size of shocks, and the values of the optimized parameters change every time I change the shock size. How should I know the true value of shocks? For the first-order, I choose 1. Does using 0.01 as the standard error of the Taylor rule’s shock make sense for the second-order approximation and welfare analysis?

Moreover, if I have a log utility function and two different (optimal) policies, can I simply take the mean of unconditional welfare from each policy and calculate consumption equivalence based on the following equation?

CE = exp ((1-BETA) * (mean.W(alternative) - mean.W(benchmark))) - 1

If this method is valid for unconditional welfare, are these results equivalent to those we might get from conditional welfare?

I mean, can I take fhat from welfare_objective of two different optimized policies and calculate CE based on the equation above?

Yes, shock sizes matter for welfare. You need to find a realistic calibration. 1 is almost always wrong as it implies 100 percent, which is a problem with higher order approximations.

Yes, with log utility that should work.

No, conditional and unconditional welfare are different concepts. You can compute the consumption equivalent with the same formula by plugging in the respective numbers, but you cannot infer one from the other.