Welfare Surface

Dear Dynare users,

I’m trying to do a surface analysis of the loss function of a DSGE model.
I have tried several ways, but I cannot find the solution, I would like to make a graphic similar to the one attached below.
in my case the surface should be made up of the inflation coefficient, the output gap coefficient and the loss function.
I hope you give me some hints.

lfa.mod (13.9 KB)

Hi MrDSGE,

Some tricks:

  1. you need mesh command, but be careful of your order, that is,
    if L(phiP, phiX) is taken from Ls(phiPs, phiXs), then you should type

mesh(phiXs,phiPs,Ls);

instead of

 mesh(phiPs,phiXs,Ls);
  1. The other error dynare reports is BK condition violated, if you temporarily erase noprint in your stoch_simul. You need to quantify your phiP greater than 1. Here I set phiPs to start from 1.1

So I add and modify some codes as follows:

phiPs    = 1.1:0.5:3.1;
phiXs    = 0:0.5:3;
Ls       = -Inf*ones(length(phiPs),length(phiXs));
for ii   = 1:length(phiPs)
    phiP = phiPs(ii);
for jj   = 1:length(phiXs)
    phiX = phiXs(jj);
stoch_simul(order=1, nograph, noprint) 
x y bl piD pi pD p ti er Der i il rR M a g iS pS;

Then I slightly rearrange some parts of your codes, to let Dynare compute moments in each iteration. Your original codes may not work very well for the mission of “looping over parameters”.

Finally, I close the loop and attach figures via:

Ls(ii,jj)=L;
end;
end;

figure(1);
mesh(phiXs,phiPs,Ls);
figure(2);
contourf(phiXs,phiPs,Ls);

Figures look like

lfa_figure1

lfa_figure2

lfa_welfsurf2.mod (13.3 KB)

Enjoy!! :beer: :beer: :beer:

2 Likes

Dear HelloDynare,

I’m very grateful for your explanation. It is just what I was looking for !
I will enjoy writing my paper with these graphics.

Thanks a lot !! :beers: :beers: :beers:

Hello Dear,
Could you please clarify me why you have added

%Función de pérdida
L=(1-par.alfa)*0.5*(((1+par.fi)/(1-par.alfaM))*variance.x+par.epsilon/par.lambda*variance.piD)/100; 

in your code as it is not a variable in your model. Why we cannot equate our model variable to the Ls(ii,jj)=L, instead of L.

Thanks.

Because welfare is a second order property that cannot be computed within a first simulation. Hence, you need to recover the variances outside of the model block.

Dear Sir,

Thank your for the clarifation. Can we have a code that include the model variable (not L as above), so that we can develop a mesh plot with two paramteres varying in the loop. I want to replace L with the model variable from the model, but I am unable to do so.

Thanks

No, you cannot loop within the model, only outside of it. However, in such a loop you can access all objects defined within the model.

Thank you sir.

That is okay sir. My point is considering the above mod file and the code. If I want to examine the response of x (which is a variable in the model), due to any of the shocks as mentioned in the model, when the paramters sigma and delta are changing in some interval, say like sigma = start value:0.1:end value; delta = start value:0.1:end value; How can I do that through the loop and generate the Ls(ii,jj)=x;. So that I can develop the mesh plot as mesh(sigma,delta,x). Sorry, If I could not pose my question rightly. Can you please refer to some code.

There are numerous examples in the forum for using loops to produce desired output. Which object are you interested in? The impact IRF?

Dear Sir,

Thank you for your response.
I am interested in IRF when two parameters vary at the same time for the above example. Can you please share some code or refer to some loop.

Thanks.

Can you provide the mod-file you are trying to run explain what you are trying to do exactly.

Dear Sir,
From the attached mode file, I want to create a mesh plot, after examining the impact of monetary policy shock (epsR in the mod file) on interest rate (MP rule) when psi1 and psi3 ranges between (0:0.1:1.5) and (0:0.1:1) at a time. In the contour plot, I want my x-axis as psi1; y-axis as psi3 and the final effect on interest rate as z-axis like the one in this thread above.
CA_LS07_s.mod (2.8 KB).
Hope for your assistance.

thanks