# 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
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).
Using Dynare
Download the rbc modfile.
using Dynare
Open the RBC model and solve the model. Fix the mistakes in the modfile if any.
= @dynare "rbc.mod";
context # ; 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
= rdb(ids = [
df_ "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_[!,["Subject","period","value"]] df_long
= unstack(df_long,:period, :Subject,:value); df
= dropmissing(sort(df)) df
rename!(df,[:period, :investment, :gdp, :consumption])
= plot(df[!,:period], df[!,:investment],label="investment")
pl1 = plot(df[!,:period], df[!,:gdp],label="gdp")
pl2 = plot(df[!,:period], df[!,:consumption],label="consumption")
pl3
plot(pl1,pl2,pl3;size=(800,800))
Detrend all series.
# detrend the consumption series
= df[!,:consumption]
series = HP(series, 1600)
trend = (series - trend)./trend
cycle :consumption_trend] = trend
df[!,:consumption_cycle] = cycle df[!,
= plot(series, title="consumption")
pl1 plot!(pl1, trend, label="consumption")
= plot(cycle, title="consumption (cycle)")
pl2 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\)?