Optimal policy parameters in a non-linear model

If you are not adjusting the underlying objective function, which requires x_opt_name as an input, you need to leave it exactly as defined for csminwel. In addition, you need to set the bounds to the same value as in cmaesOptions

Dear prof. Pfeifer,

how can I tell Dynare to use the optimal parameters derived in this way to run the simulations (as the osr command would do)?

(P.S. I need to: loop over a parameter–> find conditional optimal parameters --> run simulated data (2nd order) with this set of parameters (the looped one and the conditionally optimal ones))

You can use the set_param_value-command for that. Search the forum

Dear Prof,

I am trying to do this and I am using the same codes for maximising the objective function. As far as I have understood I first need to run the .m file but when I try to do so I get this error:

welfare_objective(x_opt, x_opt_name)
Undefined function or variable ‘x_opt’.

How can I solve this? I guess I missed one step.

Hi AITANAgf,

Drawing extensively on @jpfeifer’s code provided at Discounting under Optimal Monetary Policy, you can place the attached files in your folder and run

dynare fixednew_camilo

fixednew_camilo.mod (7.0 KB)
get_minus_welfare_objective.m (1.7 KB).

Advice 1: explore the sensitivity of your results by using several starting values for the parameters you are optimizing over.
Advice 2: try and impose sensible parameter bounds.

3 Likes

Camilo,

This is great. Thank you so much. i tried with different initial values and bounds and my results now seem to be sensible to different combinations.

Hi, I also managed to adapt my codes to find optimal parameters using your codes. I found optimal taxation on external borrowing. Now I want to graph tax rate and corresponding welfare level. Are these values saved? If so where can I reach them?

Hi lanfear,

Optimal parameter values are stored in x_opt_hat and the corresponding value of welfare is stored in fhat:slightly_smiling_face: .

Thank you for your very quick answer cmarch, actually I want to graph when tau= 0.1 welfare= xx. Not the optimal values. X axis for tau values and Y axis for corresponding welfare values. Is it possible ?

Sure, that’s possible. Try with

  % Run .mod file.
  dynare yourmodfile 
  % Remember to add       options_.noprint=1;     
  % just below your call to the solver in your .mod file
  % E.g.
 % stoch_simul(...)
 % options_.noprint=1; 


  % get position of welfare in variable list.
  W_pos=strmatch('W',M_.endo_names,'exact');

  % grid of values.
  TAU_grid = 0:0.05:1; 
  % pre-allocate.
  mean.W=zeros(length(TAU_grid),1);
  mat_loop_MP=zeros(2,length(TAU_grid));

  n=0; % start counter.
  
  for ii = 1:length(TAU_grid)
 
     set_param_value('TAU',TAU_grid(ii));

         info=stoch_simul(var_list_); % loop over stoch_simul.

         if info ==0
            % Read out mean of welfare.
            mean.W(ii)=oo_.mean(W_pos);
         else 
            fprintf('Here there is an error with this value of TAU!\n');
            % assign NAN to problematic value.
            mean.W(ii)=NaN;
         end    
   n=n+1;  % Next iteration.
   % Store.
   mat_loop_MP(:,n)=[TAU_grid(ii);mean.W(ii)];
   
  end % loop end.
  
% Plot.
x=mat_loop_MP(1,:);
y=mat_loop_MP(2,:);
plot(x,y)

:slightly_smiling_face:

thank you very much it worked like a charm but I got this graph. I think this is an indicator there is something wrong. What do you think?

optimaltax.eps (16.0 KB)

Do you have a reason to think it is not correct?:slightly_smiling_face:

This is a proportionate tax. I would expect a hump shaped response. Optimizer seems to push tax rate to the boundary. But that would mean approximately 45% tax on foreign borrowing. It just seemed too much to me.

Try search the maximum manually: since you just have one parameter you are optimizing over, it does not get much computationally intensive to run the loop and search for the max manually, so it is a cheap check in this case. How large is the \tau that maximizes welfare when searching like this?

   n=n+1;  % Next iteration.
   % Store.
   mat_loop_MP(:,n)=[TAU_grid(ii);mean.W(ii)];
   
  end % loop end.
  
% Search the matrix to find the maximum
 maxValue_MP = max(mat_loop_MP(size(mat_loop_MP,1),:));
 [row, column] = find(mat_loop_MP == maxValue_MP);
 optim_W_MP=mat_loop_MP(:,column);
 x_opt=optim_W_MP(1,:);
 y_opt=optim_W_MP(2,:);

x=mat_loop_MP(1,:);
y=mat_loop_MP(2,:);
plot(x,y)
hold on 
plot(x_opt,y_opt,'r*')

For illustration, I have applied the exact same code I wrote for you to a model of mine in which I just optimize over the feedback coefficient on output in the Taylor rule. See attachment.
As to why the hump-shape does not show up in your model, it maybe has to do with your model.
EXAMPLE_camilo.pdf (2.3 KB)

manual.eps (16.0 KB) adjusting the code according to your suggestions yield me this.

To be more specific, I am trying to extend this paper and I am trying to produce figure 3, 4 and 5.
https://www.sciencedirect.com/science/article/pii/S0164070411000553

To my understanding paper graphs welfare benefits rather than welfare level? Can this explain the difference between paper results and my findings?

If you look at Fig. 1 in the paper (“Unconditional welfare levels-varying \tau, no operational cost (\psi = 0)”), it is not hump-shaped: The higher \tau, the lower the unconditional welfare. Looking at optimaltax.eps you uploaded a couple of answers ago, you can see that the shape there is similar to Fig. 1 in the paper, but is flipped in the wrong direction: the higher \tau, the higher the unconditional welfare.
Consequently, if you now computed the \lambda in the paper using the formula, you would see the hump-shape of Fig. 3 with the hump flipped in the opposite direction of that shown the paper.

So your findings and the findings of the paper cannot be reconciled by plotting \lambda instead of the unconditional welfare. You need to look at your equations and find out why you have that as \tau grows larger, welfare grows.

Yes, but in Figure I banking sector is frictionless. That’s why introducing tax is distortionary. In my case there exist banking costs as in figure 3. So taxes are beneficial in this case.

Ok, so you can compute \lambda, plot it, and see :slightly_smiling_face:.

how can I do that? I guess I should specify a W0 that is welfare under no tax scenario. And I should plot W/W0 ? My question is how to define W0 ?

You should plot \lambda\cdot100.
Have a look at Consumption Equivalence_Welfare analysis :slightly_smiling_face: