First steps with Dynare and moment matching.

Business Cycles and Fluctuations - AE2E6

Using Dynare:

  • get familiar with the structure of a modfile
  • interpret results
    • compare moments with the data
  • edit a model
    • fix steady-state
    • extend a model (in particular recheck/rederive first order conditions)

Uncomment the following lines to install needed packages (if not already present).

# uncomment the next lines, the first time you run
# import Pkg; Pkg.add(["DBnomics", "Dynare", "DataFrames"])
# import Pkg; Pkg.add(url="https://github.com/sdBrinkmann/HPFilter.jl") # we install hpfilter from github

Using Dynare

Download the rbc modfile.

using Dynare

Open the RBC model and solve the model. Fix the mistakes in the modfile if any.

context = @dynare "rbc.mod";
# ; mutes the output
# graphs and other outputs are stored in subdirectory `rbc`
# the structure `context contains all the results.`

(if needed, download the correct model here )

Inspect the various elements of the solution (decision rule, unconditional moments, simulations).

Interpret the effect of a productivity shock. How does it depend on the productivity?

Bonus: open the same model with Dyno (see link on the course webpage). Compare the results.

Computing moments in the data

Download US time series from the world bank for: real gdp, investment, consumption, hours worked.

using Plots
using DBnomics
using DataFrames
using HPFilter: HP
using Statistics: cor, std
# google OECD
df_ = rdb(ids = [
    "OECD/QNA/USA.P5.LNBQRSA.Q", # investment
    "OECD/QNA/USA.B1_GS1.LNBQRSA.Q", # GDP
    "OECD/QNA/USA.P3.LNBQRSA.Q"

]);
# keep only the relevant data, in long format
df_long = df_[!,["Subject","period","value"]]
df = unstack(df_long,:period, :Subject,:value);
df = dropmissing(sort(df))
rename!(df,[:period, :investment, :gdp, :consumption])
pl1 = plot(df[!,:period], df[!,:investment],label="investment")
pl2 = plot(df[!,:period], df[!,:gdp],label="gdp")
pl3 = plot(df[!,:period], df[!,:consumption],label="consumption")

plot(pl1,pl2,pl3;size=(800,800))

Detrend all series.

# detrend the consumption series 
series = df[!,:consumption]
trend = HP(series, 1600)
cycle = (series - trend)./trend
df[!,:consumption_trend] = trend
df[!,:consumption_cycle] = cycle
pl1 = plot(series, title="consumption")
plot!(pl1, trend, label="consumption")
pl2 = plot(cycle, title="consumption (cycle)")
plot(pl1, pl2)
# detrend gdp

# write your code here
# detrend the investment series 

# write your code here

Compute the correlations between the detrended series. Compute the ratios \(\frac{\sigma(investment)}{\sigma(gdp)}\) and \(\frac{\sigma (consumption)}{\sigma (gdp)}\). Compare with the RBC model and comment.

Small Open Economy

Start from the same rbc model. Assume the representative agent can save \(b^{\star}_t\) as foreign assets, remunerated at a constant interest rate \(r^{\star}-1\).

Write the new budget constraint for the representative household.

Write the new optimality condition.

What is the long run constraint on interest rate \(r^{\star}\)?

Update the modfile (set \(\overline{b^{\star}}=0\))

Print theoretical moments. Comment.

Simulate the model over 100 periods. Comment.

Assume the foreign interest rate depends on the amount of foreign assets

\[r^{\star}=\frac{1}{\beta} + exp(-\kappa b^{\star}_t) - 1\]

with \(\kappa=0.01\). How do you interpret the equation for \(r^{\star}_t\). How should you modify the model equations?

Update the modfile and comment on the generated moments. Do they depend on the choice of \(\kappa\)?