Thanks for your kind reply. When I have a stoch_simul-command in the mod-file, which is put right before the maximization code, the results are a little different. The first is that the running time is much less when I have the stoch_simul-command. In your tested code, Dynare runs about 10 minutes in my computer. However, if I have stoch_simul-command right before the maximization code in the mod-file, Dynare just runs about several seconds. Why is the running time so different?
Another difference is that the welfare values which is stored in “fhat”, is exactly the same with or without the stoch-simul command. But the optimal parameter values are very different. In your tested code, the two parameter values which is stored in “x_opt_hat”, are 1.1583 and 7.6269, but 1.3077 and 86.8614 if having the stoch-simul command in the mod-file. Which result should I trust and why?
Besides, could you please show me how to write a loop to do the grid search? Is the code just inside the mod-file, or I have to write a separate m-file about the loop?
Sorry about that I have asked so many questions. I understand that it must spend you much time in answering my questions. Thank you very much. I am looking forward to your reply.