Stoch_simul after estimation

Hello everyone

I would have a question: How to conduct stoch_simul after estimation

There are two steps

  1. Step 1: estimating model
  2. Step 2: using the estimated result to conduct the stochastic simulation

So I do step 1 by using the command:
estimation(…);
After estimating, I check that my model converge
So then I would use the estimated variance of shock to conduct the stochastic simulation
For example, my esimated result for variance of technology shock is reported by DYNARE as
SE_epsa 0.076 (post mean)
then to conduct the stochastic simulation, then I have to declare 2 following command blocks:

shocks;
var epsa; stderr 0.076; (I am not sure, assign as 0.076 or square root of 0.076?)
end;

stoch_simul(,period=40); (puting some varibles which is I would to see)

So my job is correct? if not, please correct me

By the way, after estimation, if we want to do stochastic simulation, then in dynare, we have to declare the estimated variance shock manually, like I did in the above example, right?

Thank you so much for that

1 Like

That depends on what you want to do. If you want to run stoch_simul in a different mod-file, then you are right. If you want to run it after estimation in the same file, then you can simply put the stoch_simul-command after estimation. As documented in the manual

After running estimation, the parameters M_.params and the variance matrix M_.Sigma_e of the shocks are set to the mode for maximum likelihood estimation or posterior mode computation without Metropolis iterations.

If you want the posterior mean, you want preface the stoch_simul by

xparam1= get_posterior_parameters('mean');
M_ = set_all_parameters(xparam1,estim_params_,M_);

Dear Prof @jpfeifer

Thank you so much indeed. I got it

I have 2 futher questions. Normally, to conduct impulse response of variables to shocks in the same file, then we use stoch_simul after estimation

However, in my procedure as

Step 1: I use estimation command only. I would make sure that my estimation converge before doing stoch_simul. My estimation converge with 300.000 draws (it takes 4 hours)

Geweke (1992) test indicates that allmost paramters converge at the significant level of 5% and 10%. Only 6 parameters converge at the significant level of 1%. Of course, the higher significant level, the better it is. However, in my case, conclusion of convergene is fine, right? If not, please correct me.

Step 2: if the conclusion of convergence is acceptable, then I would use the estimated results to conduct impulse response function with stoch_simul command. But I do not want to run estimation and MH algorithm again since it takes time. To do that, I simply recall previous mode-file and Metropolist-Hasting Algorithm by using command mode_file and load_mh_file in the estimation block

After that I will use the follwing command

xparam1= get_posterior_parameters(‘mean’);
M_ = set_all_parameters(xparam1,estim_params_,M_);
stoch_simul(…);

So in this case I can conduct the impulse response of variables to shocks at the posterior mean without re-estimating and running MH algorithm again
So my procedure is correct? (in this case, I am using dynare 4.4)

With best regards

Yes, that should be fine.

yes, thank you so much indeed prof. @jpfeifer

Dear professor:

Is there any way to save the estimated results so in another day when launch matlab to do the simulation with the same model file, I won’t need to run estimation again?

Thanks

Can you elaborate? All estimation results are already saved on the disk.

I mean the posterior we get, I know it is saved in my disk. In my disk, it has generated serval folders after estimation. I can only understand the use of first folder named graphs.

I want to know if there is any code to save posterior in another file so I can simply load this file and run simulation without changing my model file. Or maybe this file is indeed saved in my disk, I just didn’t find it.

Because I closed the matlab after estimation last time and I can now only find some graphs and some files whose purpose is unknown to me.
In prior folder, there are a definition file and my_model file, I wonder if these are what I need.

Thanks.

Everything you need should be saved in the _results.mat file. You can use that to read out the posterior mean/mode for another mod-file with the same model. Using a copied version of the mod-file then also makes sure you are not overwriting any generated estimation results.

Thank you sir.

But I finished my estimation before I read your reply at another post where you said the prior is supposed to be independent of the data.
My question is :

  1. What is the data excatly? Is this indicate the observed data or estimated parameters’ true value?

2.My first estimation’s convergence looked very bad so I changed the calibrated persistence parameters until results were fine. Is this correct?

  1. Like the picture showed, is this indicate my calibrated parameters are wrong? I can get the estimated results but what concerns me is this hint means my results won’t work.

So I am not sure I follow the right process to do Bayesian estimation.

Thank you again. Your instruction will be much appreciated.

  1. That data is the observed data used for estimation and entering the likelihood function.
  2. Strictly speaking that is problematic. But most researchers do it that way.
  3. You can most probably ignore the message. But the high posterior density value may signal a problem with the data treatment. That would also explain issues with persistence parameters.

Dear Professor

For your third reply, did you mean the value of the log posterior? I did change my persistence parameters countless time and not once the value of the log posterior is bigger than -12000.And the results show that Log data density (Modified Harmonic Mean) is -354.297767.

Is there a normal range for log data density and the value of the log posterior that I could refer to ?

I think I need to reprocess my observed data may be this is where I get so wrong.

Thanks for your reply. :smile:

Yes, I meant that. There is no hard rule, but usually it’s in the thousands, not ten thousands. That may still be fine but it’s good to check.

Dear Professor
post and priorsPDF.pdf (120.7 KB)

After I reprocessed my observation data, my estimated results seem get convergence but I am not sure. And the parameter rho_g(g stands for government consumption)seems a little too big and the parameter eta shouldn’t be that small.

What else can I do to make parameters converge to the ergodic distribution?

I added the code ‘generate_trace_plots(1,2);’ after the estimation command but the error messages popped up.


Where did I get wrong?

  1. The warning displayed about the timing is a concern.
  2. The command should be
generate_trace_plots([1:2])

Dear professor
Thanks for your reply.
I have corrected the timing problem but the pictures still looked wierd. Could please you give me some advice?
I have already uploaded my model file if you ever need it.

convergencePDF.pdf (124.7 KB)
mode check.pdf (15.1 KB)

mymodel.mod (3.8 KB)
mymodel_paramsinit.m (553 Bytes)
newobdatagrowth11.mat (4.6 KB)

Your observation equations seem to be incorrect. Why are all variables mean 0 but the data is not?

Dear professor
My mistake. I used the wrong data. I read your paper ‘A Guide to Specifying Observation Equations for the Estimation of DSGE Models’. So I used the logarithm of output data, detrended using hp filter and takes out the mean. I did the same for investment and consumption data. As for rate and inflation rate, I detrended the rate and inflation before taking the logarithm and I followed your paper’s instruction that using the logarithm of quarterly rate minus the logarithm of rate detrended using hp filter.


And observation equations which I changed into Y_ob = y.
If I were doing something wrong, please correct me.

But I run estimation using this data file, the results still looked weird. Mode check plots show many red dots and few parameters are not identified.
I want to know if these problems caused by wrong setting of model or prior or parameter calibration error.

Thanks again.

Please provide the most recent version of the files.

Dear professor
These are my files.
I changed the prior of the parameter rho_mu to 0.7 because otherwise the rho_mu would not identified.

mymodel.zip (48.7 KB)