# Help with writing the model into the codes!

I’m new to Dynare! I derived all the F.O. conditions for my model and I’m confused how to write them in mod file. My aim is to find the optimal monetary policy rule for Small open economy. My understanding is that I need to solve the model first before I find the optimal rules. Also, I need to write the model in non-linear form. I have few question, would appreciate it any help really!

1. Is the following way correct to enter the model in the codes?

This is the F.O. C. with respect to (k t+1 ) - which is the capital with cost adjustment investment.

```psii*((k(+1)/k)-1)+1=betta*(lammbda(+1)/lammbda)*(1+rk(+1)-deltta+((psii/2)*((k(+2)/k(+1))-1))); ```

1. how to write the monetary policy rule ? I have it as following but not sure if it is right.

where v follows AR(1) process.

1. How to write the AR(1) process shocks in the code?
I will give two examples. one is the productivity shock, and the other one is the monetary policy shock.

Please note that I write V in the monetary policy rule as specified above and I write A in the production function as following:

Basically what I did is I copied the F.C C. into the codes but really not sure if that’s the way to do it.

I really appreciate any help !!! Thanks for your time!

1. I think there is a term missing (product rule). Take a look at the AguiarGopinath2007.mod on my homepage. There you would obtain something like:

```uc*(1+phi*(k(+1)/k-1))=beta*uc(+1)*(1-delta+(1-alpha)*y(+1)/k(+1)-phi/2*(2*(k(+2)/k(+1)-1)*(-1)*k(+2)/k(+1)+(k(+2)/k(+1)-1)^2)); ```
2. This is almost correct, but you need

because v has steady state 0. Otherwise, the n on the RHS would make the RHS 0, but it must be 1.
3. The same as in 2. applies here. TFP typically follows a log-normal process. If you specify A as normal mean 0 process, you must use

Otherwise, the RHS will again be 0 in steady state.
4. Note that the way you entered the timing for k, you are violating Dynare’s end of period stock timing convention and require

This was VERY helpful Johannes, I truly appreciate your help. I have more questions if you don’t mind:

1. I notice that my non-linear model is very sensitive to the parameters values. You could change one parameter and ended up with non zero residuals of the static equations, does that mean the model is bad? or this is usually what we expect with DSGE models.

2. to be able to log-linearize the model by dynare, do I need to only take the exp for every variable I have? Are there any materials could help with that?

Confusion: I understand that in economics it is always easier to interpret the log-linearized models. But if I log-linearize my model, and since I was able to find the impulse responses of the nonlinear version of it, do I expect to see the impulse responses of the log-linearized one by default? and do we expect to see the same dynamic of the impulse responses? I assume we should but I heard some ppl had problem with that part.

1. My aim is to find the optimal monetary policy responses and optimal monetary policy rule. Could you please refer me to any codes or materials on that for small open economies? Also, to be able to find the optimal monetary policy rule, do I need only the nonlinear system without taking any exp of the variables?

Again, I appreciate all the help!!!

1. Steady states are typically highly nonlinear functions of the deep parameters. It is to be expected that the steady state changes a lot when you change the parameters.
2. The answer is basically yes. Take a look at Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models” sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.
Regarding dynamics, log-linearization is essentially equal to dividing each variable response by its steady state. Hence, the IRFs from the log-linearized model are equal to the IRFs from the linearized model scaled by a particular constant. Hence, their shape is generally similar.
1. The log-transformation using exp() is a monotone and invertible transformation. It will not affect the maximum and hence does not alter the results (but you need to make sure that your objective function is correct and the same in both cases). Regarding small open economies: this is not my home turf. You need to google it.

I appreciate your help Johannes, I’m still working on coding the model. Just quick question, Lets say that I have an exogenous shock in the model like foreign price which we usually assume it follows AR(1). Would it be acceptable if I estimate that my self? in another word, if I regress the variable on its first lag and take the beta and the st of the estimated regression to be used in calibrating the exogenous shock of foreign price in the DSGE model. Thanks alot!!

If the process is exogenous, you can do that. It is what Kydland/Prescott originally did.