Prof. Jpfeifer,
I understand that. My question is: is the mean of my defined welfare function the mean of the approximated theoretical moments? If not, it is the mean of the empirical moments based on simulation?
Prof. Jpfeifer,
I understand that. My question is: is the mean of my defined welfare function the mean of the approximated theoretical moments? If not, it is the mean of the empirical moments based on simulation?
Dear Prof. Jpferifer,
I have replace the code in welfare_objective.m with the conditional welfare codes at https://github.com/JohannesPfeifer/DSGE_mod/blob/master/Born_Pfeifer_2018/Welfare/get_consumption_equivalent_conditional_welfare.m. Now my code can run well.
However, there seems to be some problems. The code seems to just simulate 1 time, rather than 1000 times as I set in the mod-file. It just runs about 1 second and can show the results. The value stored in “fhat” which represents the welfare value “v” in my case, is very different from the mean of approximated theoretical moments of “v” shown in the command window. And the values of the parameters which I want to optimize, are just the same as the calibrated ones, which seems not to be optimized. Could you please help me check what the problem is and how to fix it?
Thank you very much. Here attached my code. conditional_welfare_objective.m (1.1 KB)
housing.mod (8.5 KB)
y_sim
is a matrix, so you need to select the correct element/column as you simulate more than 1 period for some reasonvar_list_
with resol
. It should beoutvalue=y_sim(strmatch('v',M_.endo_names,'exact'),1); %extract Welfare
Prof. Jpfeifer,
Thanks for your reply.
As your posted code, I set nit = 1000; %Number of iterations in the mod-file. And when I do unconditional welfare computation, it simulates many times. So I think I also need to do a large number of times simulation in the conditional scenario. What I want to do is to find out the the optimal value of rho_r, rho_pi, and rho_y that get the highest welfare value “v”, given a three-dimensional grid of the parameters. And the welfare value is conditional upon the initial state of the economy being the nonstochastic steady state as Schmitt-Grohe & Uribe, 2004. So I need to do the simulation for a large number of times. Could you please help me with it in Dynare?
I think the reason that why a change in the parameters does not affect the conditional welfare measure I am reading out of the model, is because I just simulate 1 time, thus Dynare just use the calibrated parameter value to compute the welfare measure. It indeed does’t do the optimization. But I do use the code “nit = 1000; %Number of iterations” in the mod-file. So I am confused about it.
I am looking forward to your reply. conditional_welfare_objective.m (1.1 KB)
housing.mod (8.5 KB)
You are confusing something. nit=1000
is the upper bound for the Newton steps/iterations for the csminwel
-solver. It has nothing to do with the simulation of the model.
Prof. Jpfeifer,
I have set periods=0
, and Dynare should report the theoretical moments. However, the “fhat” value is different from the mean of approximated theoretical moment of the welfare variable “v” in my case. Why is it?
Could you please explain me with outvalue=y_sim(strmatch('v',M_.endo_names,'exact'),1); %extract Welfare
? What does “1” mean here? When I change it to 2, the results are different. Also in the code shock_matrix = zeros(5,M_.exo_nbr); %create shock matrix with number of time periods in columns
. I input “5” here because there are 5 shocks in my model. Am I right?
Thank you very much! conditional_welfare_objective.m (1.1 KB)
housing.mod (8.5 KB)
v
is the unconditional oneM_.exo_nbr
is the number of shocks. The point where you put the 5 is the number of time periods for the simulation, which you should have left at 1.Prof. Jpfeifer,
Thanks for your reply. It’s really helpful. Now I understand that the theoretical mean of v is the unconditional one, however, I also want to know whether the empirical mean of v is the conditional one?
Moreover, where can I find the moments of other variables when the welfare variable “v” is maximized?
stoch_simul
again after you have found the optimal policy rule parameters with those parameter values.Prof. Jpfeifer,
Thanks for your reply. I notice some small points.
In your code about computation of conditional welfare, it is written as
Recursive_natural_welfare_equivalent=y_sim(strmatch(‘Recursive_natural_welfare_equivalent’,M_.endo_names,‘exact’),2);
But you post that my code should be
outvalue=y_sim(strmatch(‘v’,M_.endo_names,‘exact’),1); %extract Welfare
What’s the difference between the figure 2 and 1? I think it is the dimensional scalar of the matrix y_sim. If I am right, why should I put 1 but you put 2?
Also, you replied that the M_.exo_nbr is the number of shocks. The point where you put the 5 is the number of time periods for the simulation, which you should have left at 1
. However, in your conditional welfare code of “Born_Pfeifer_2018”, it is shock_matrix = zeros(2,M_.exo_nbr); %create shock matrix with number of time periods in columns. Why should I put 1 but you put 2?
In the code of unconditional welfare, you posted
outvalue=-oo_.mean(strmatch(‘v’,var_list_,‘exact’)); %extract Welfare
However, in the code of conditional welfare, there is NO negative sign in front of y_sim(strmatch(‘v’,M_.endo_names,‘exact’),1); %extract Welfare
I think that because csminwel runs a minimizer algorithm, but I want to maximize the welfare, so I should put a negative sign in front of y_sim(strmatch(‘v’,M_.endo_names,‘exact’),1); %extract Welfare. Am I right?
here attached both the codes of unconditional and conditional welfare, and the mod-file.welfare_objective.m (713 Bytes)
housing.mod (8.5 KB)
conditional_welfare_objective.m (1.1 KB)
2
. The reason is simult_
is returning the initial condition in the first column, so the first simulated point you want to read out is 2
.shock_matrix = zeros(1,M_.exo_nbr); %create shock matrix with number of time periods in rows
Prof. Jpfeifer,
I set period=0
in my code, so the mean of my defined welfare function should be the theoretical one, which is the value of fhat
in my code. However, the value of fhat
is different from the mean of “v” shown in the approximated theoretical moments. “v” is just the welfare variable defined in my code. Even the absolute values of the two are different. Could you please help me explain why it is? I think the two values should be same. Is there a problem?
Also, you replied me that I should use theoretical moments for welfare evaluation. My understanding is that I should use the mean of “v” in the approximated theoretical moments, rather than the value of fhat
. If I am right, what’s the difference between the two?
I am looking forward to your reply. Here attached my code. conditional_welfare_objective.m (1.1 KB)
housing.mod (8.7 KB)
The mean welfare is, as the name indicates the UNconditional mean of the welfare function. But the objective function you are using is the CONDITIONAL one. That explains the difference.
Prof. Jpfeifer,
Thanks for your reply. However, if my understanding is right, the mean of “v” in the approximated theoretical moments is the unconditional mean of the welfare. So if I use the unconditional objective welfare function, the value of fhat
should be the same as the theoretical mean of “v”. However, the two are still different even though I use the unconditional objective function.
Also, which one should I use for welfare evaluation? the value of fhat
or the theoretical mean of “v”?
And I also want to see the value of other variables when the conditional welfare is maximized. I know that I need to run stoch_simul
again after I have found the optimal policy rule parameters with those parameter values. But I don’t know how to find the simulated values of other variables. How should I find the conditional mean of other variables after I run stoch_simul
again?
I am looking forward to your reply. Here attached the unconditional objective function code and the mod-file. housing.mod (8.7 KB)
welfare_objective.m (713 Bytes)
fhat
is minus the unconditional welfare (as we are using a minimizer). When I run your code,fhat = -6.9770
When I run
options_.noprint=0;
info = stoch_simul(var_list_);
I get
APPROXIMATED THEORETICAL MOMENTS
VARIABLE MEAN STD. DEV. VARIANCE
y 1.1225 0.0018 0.0000
...
v 6.9770 0.0016 0.0000
So the value of v
and fhat
are consistent.
2. The values of the mean are displayed if you reset the noprint
option (as shown in point 1). They are stored in oo_.mean
Prof. Jpfeifer,
Thanks for your feedback. It’s very helpful.
I still have one question: After I find the optimal policy rule and the corresponding parameter values, I also want to know the moments of other variables when the welfare variable “v” is maximized. In your previous post, you indicated that I need to run stoch_simul
again after I have found the optimal policy rule with those parameter values. But how many periods do I need to run the simulation? I think it should be the same as I compute the condition welfare, which seems to be 1 in your code file. But if I set stoch_simul(order=2,irf=0,periods=1)
, dynare couldn’t do the simulation. So, how should I get the simulated moments of other variables when the welfare is maximized?
Here attached my code. I look forward to your reply. conditional_welfare_objective.m (1.1 KB)
housing.mod (9.0 KB)
You need to use
set_param_value('rho_pi',x_opt_hat(1));
set_param_value('rho_y',x_opt_hat(2));
to set the parameters to the optimal ones after optimization and then run stoch_simul
. Regarding moments, it is very unusual to compute conditional second moments even if you find the rule that maximizes conditional welfare. People usually work with unconditional moments. which you would get with periods=0
Prof Jpfeifer,
Thanks for your reply. I understand that I need to set the policy parameter values equal to the optimized ones, and run stoch_simul
. But this way I just get the theoretical moments, which refer to the unconditional moments. Because there are two types of households in my model, I want to find the individual welfare values respectively when the social welfare is maximized. Since I compute the maximized conditional social welfare, I think I should also find the conditional individual welfare values. That’s why I want to know the conditional moments. So could you please help me with it?
I look forward to your reply.