├── .github
└── workflows
│ ├── dynare-6.0-matlab-r2024a-macos.yml
│ ├── dynare-6.0-matlab-r2024a-ubuntu.yml
│ ├── dynare-6.0-matlab-r2024a-windows.yml
│ └── latex.yml
├── .gitignore
├── LICENSE
├── README.md
├── exam
├── endterm_exam_ss2022.tex
├── endterm_exam_ss2023.tex
├── midterm_exam_ss2022.tex
├── midterm_exam_ss2023.tex
├── midterm_exam_ss2024.tex
└── midterm_exam_ss2025.tex
├── exercises
├── _common_header.tex
├── an_schorfheide_identif_bk.tex
├── an_schorfheide_identif_bk_solution.tex
├── arma_simulation.tex
├── arma_simulation_solution.tex
├── baxter_king_preprocess_steady.tex
├── baxter_king_preprocess_steady_solution.tex
├── brock_mirman_policy_function.tex
├── brock_mirman_policy_function_solution.tex
├── case_study_annicchiarico_DiDio_2015.tex
├── case_study_annicchiarico_DiDio_2015_solution.tex
├── case_study_ascari_sbordone_2014.tex
├── case_study_ascari_sbordone_2014_solution.tex
├── case_study_baxter_king_figure2.tex
├── case_study_baxter_king_figure2_solution.tex
├── case_study_baxter_king_figure3.tex
├── case_study_baxter_king_figure3_solution.tex
├── case_study_eichenbaum_rebelo_trabandt_2022.tex
├── case_study_eichenbaum_rebelo_trabandt_2022_solution.tex
├── computational_macroeconomics_scope.tex
├── computational_macroeconomics_scope_solution.tex
├── gitkraken_quick_tour.tex
├── gitkraken_quick_tour_solution.tex
├── log_linearization.tex
├── log_linearization_solution.tex
├── matlab_quick_tour.tex
├── matlab_quick_tour_solution.tex
├── matlab_symbolic.tex
├── matlab_symbolic_solution.tex
├── matrix_algebra.tex
├── matrix_algebra_solution.tex
├── nk_model_algebra.tex
├── nk_model_algebra_solution.tex
├── nk_preprocess_steady.tex
├── nk_preprocess_steady_solution.tex
├── nk_simulations.tex
├── nk_simulations_solution.tex
├── numerical_optimization.tex
├── numerical_optimization_solution.tex
├── preprocess_matlab_rbc.tex
├── preprocess_matlab_rbc_solution.tex
├── programming_languages.tex
├── programming_languages_solution.tex
├── rbc_model.tex
├── rbc_model_description_short.tex
├── rbc_model_solution.tex
├── rbc_steady_matlab.tex
├── rbc_steady_matlab_solution.tex
├── simulations_deterministic_vs_stochastic.tex
└── simulations_deterministic_vs_stochastic_solution.tex
├── exercises_1.tex
├── exercises_2.tex
├── exercises_3.tex
├── exercises_4.tex
├── exercises_5.tex
├── literature
└── _biblio.bib
├── plots
└── SimulatedTrajectory_x.pdf
├── progs
├── dynare
│ ├── BaxterKingGrowthSteadyState.mod
│ ├── BaxterKingSteadyState.mod
│ ├── Brock_Mirman.mod
│ ├── an_schorfheide_identif_bk.mod
│ ├── an_schorfheide_identif_dovish.mod
│ ├── an_schorfheide_identif_hawkish.mod
│ ├── an_schorfheide_loglinear.mod
│ ├── an_schorfheide_nonlinear.mod
│ ├── an_schorfheide_nonlinear_exp.mod
│ ├── an_schorfheide_params_shocks.inc
│ ├── an_schorfheide_sensitivity_bk.mod
│ ├── arma11.mod
│ ├── nk.mod
│ ├── nk2co_common.mod
│ ├── nk2co_do_plots.m
│ ├── nk2co_perm_infltarget_surprise.mod
│ ├── nk2co_perm_tax_announced.mod
│ ├── nk2co_temp_monpol_announced.mod
│ ├── nk2co_temp_monpol_surprise.mod
│ ├── nk2co_understand_perfect_foresight.m
│ ├── nk_illustrate_perturbation.mod
│ ├── nk_irfs_det.mod
│ ├── nk_irfs_det_do_plots.m
│ ├── nk_irfs_stoch.mod
│ ├── nk_var_typology.mod
│ ├── rbc.mod
│ ├── rbcCRRA.mod
│ ├── rbcCRRASteadyStateHelperFunction.m
│ └── rbcLogutil.mod
├── latex
│ ├── templateExamBiblio.bib
│ └── templateExamSolution.tex
├── matlab
│ ├── Brock_Mirman_compare.m
│ ├── Brock_Mirman_preprocessing.m
│ ├── Brock_Mirman_ss.m
│ ├── arma11CompareMATLABWithDynare.m
│ ├── arma11Simulate.m
│ ├── dlyapdoubling.m
│ ├── matrixAlgebraCholesky.m
│ ├── matrixAlgebraCompareLyapunovSolvers.m
│ ├── matrixAlgebraEigenvalues.m
│ ├── matrixAlgebraKroneckerFormula.m
│ ├── numericalOptimizationExamples.m
│ ├── perturbation_solver_LRE.m
│ ├── perturbation_solver_dynare_order1.m
│ ├── preprocessingComparisonRBC.m
│ ├── preprocessingRBC.m
│ ├── quickTourMatlab.m
│ ├── rbcCRRASteadyState.m
│ ├── rbcCRRASteadyStateTest.m
│ ├── rbcLogutilSteadyState.m
│ ├── rbcLogutilSteadyStateTest.m
│ ├── steadystateRBC.m
│ ├── symbolicToolboxIllustation.m
│ ├── templateMatlabExample.m
│ └── writeOut.m
└── replications
│ ├── Annicchiarico_DiDio_2015
│ ├── ann_dio_2015_calib_environmental_policy.inc
│ ├── ann_dio_2015_calib_no_policy.inc
│ ├── ann_dio_2015_environmental_regime.inc
│ ├── ann_dio_2015_irfs_cap_and_trade.log
│ ├── ann_dio_2015_irfs_cap_and_trade.mod
│ ├── ann_dio_2015_irfs_cap_and_trade
│ │ ├── Output
│ │ │ └── ann_dio_2015_irfs_cap_and_trade_results.mat
│ │ └── checksum
│ ├── ann_dio_2015_irfs_intensity_target.log
│ ├── ann_dio_2015_irfs_intensity_target.mod
│ ├── ann_dio_2015_irfs_intensity_target
│ │ ├── Output
│ │ │ └── ann_dio_2015_irfs_intensity_target_results.mat
│ │ └── checksum
│ ├── ann_dio_2015_irfs_no_policy.log
│ ├── ann_dio_2015_irfs_no_policy.mod
│ ├── ann_dio_2015_irfs_no_policy
│ │ ├── Output
│ │ │ └── ann_dio_2015_irfs_no_policy_results.mat
│ │ └── checksum
│ ├── ann_dio_2015_irfs_tax_policy.log
│ ├── ann_dio_2015_irfs_tax_policy.mod
│ ├── ann_dio_2015_irfs_tax_policy
│ │ ├── Output
│ │ │ └── ann_dio_2015_irfs_tax_policy_results.mat
│ │ └── checksum
│ ├── ann_dio_2015_modeleqs.inc
│ ├── ann_dio_2015_moms_cap_and_trade.log
│ ├── ann_dio_2015_moms_cap_and_trade.mod
│ ├── ann_dio_2015_steadystate_helper.m
│ ├── ann_dio_2015_symdecls.inc
│ ├── ann_dio_2015_tbl1_tbl2_no_policy.mod
│ ├── ann_dio_2015_tbl2_environmental_policy.mod
│ ├── as_irf_a.mod
│ └── fig1_fig2.m
│ ├── Ascari_Sbordone_2014
│ ├── Ascari_Sbordone_2014.mod
│ ├── as_fig11.mod
│ ├── as_fig14.mod
│ ├── ascari_sbordone_2014.log
│ ├── ascari_sbordone_2014_calib_common.inc
│ ├── ascari_sbordone_2014_common.mod
│ ├── ascari_sbordone_2014_fig11.log
│ ├── ascari_sbordone_2014_fig11.mod
│ ├── ascari_sbordone_2014_fig11
│ │ ├── Output
│ │ │ └── ascari_sbordone_2014_fig11_results.mat
│ │ ├── checksum
│ │ ├── gsa
│ │ │ ├── ascari_sbordone_2014_fig11_prior.mat
│ │ │ ├── ascari_sbordone_2014_fig11_prior_indeterm.eps
│ │ │ ├── ascari_sbordone_2014_fig11_prior_stable.eps
│ │ │ ├── ascari_sbordone_2014_fig11_prior_unstable.eps
│ │ │ └── prior_ok.mat
│ │ └── prior
│ │ │ └── definition.mat
│ ├── ascari_sbordone_2014_fig13.log
│ ├── ascari_sbordone_2014_fig13.mod
│ ├── ascari_sbordone_2014_fig13
│ │ ├── Output
│ │ │ └── ascari_sbordone_2014_fig13_results.mat
│ │ └── checksum
│ ├── ascari_sbordone_2014_fig14.log
│ ├── ascari_sbordone_2014_fig14.mod
│ ├── ascari_sbordone_2014_fig14
│ │ ├── Output
│ │ │ └── ascari_sbordone_2014_fig14_results.mat
│ │ └── checksum
│ ├── ascari_sbordone_2014_fig7.log
│ ├── ascari_sbordone_2014_fig7.mod
│ ├── ascari_sbordone_2014_fig8.log
│ ├── ascari_sbordone_2014_fig8.mod
│ ├── ascari_sbordone_2014_moments.log
│ └── ascari_sbordone_2014_moments.mod
│ ├── Auray_Eyquem_2019
│ ├── Auray_Eyquem_2019.mod
│ └── Auray_Eyquem_2019_plots.m
│ ├── Baxter_King_1993
│ ├── Baxter_King_1993_figure_2.mod
│ └── Baxter_King_1993_figure_3.mod
│ └── Eichenbaum_Rebelo_Trabandt_2022
│ ├── ert_model_figures_both.mod
│ ├── ert_model_figures_demand.mod
│ ├── ert_model_figures_supply.mod
│ ├── ert_model_flex.inc
│ ├── ert_model_go_calibrate_pi.m
│ ├── ert_model_histval.mod
│ ├── ert_model_homotopy.mod
│ ├── ert_model_initval.mod
│ ├── ert_model_no_homotopy.mod
│ ├── ert_model_plot_agg_results.m
│ ├── ert_model_plot_by_type_results.m
│ ├── ert_model_sticky.mod
│ └── ert_model_sticky_steady.mod
├── week_10.notyet
├── week_11.notyet
├── week_8.notyet
└── week_9.notyet
/.github/workflows/latex.yml:
--------------------------------------------------------------------------------
1 | name: LaTeX
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | tags:
8 | - '2024-week-*'
9 | - '2025-week-*'
10 | workflow_dispatch:
11 |
12 | jobs:
13 | build_documents:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Set up Git repository
17 | uses: actions/checkout@v4
18 |
19 | - name: Compile LaTeX exercises
20 | uses: xu-cheng/latex-action@v3
21 | with:
22 | root_file: "exercises*.tex"
23 | work_in_root_file_dir: true
24 |
25 | - name: Compile LaTeX exams
26 | uses: xu-cheng/latex-action@v3
27 | with:
28 | root_file: "exam/*_exam_*.tex"
29 | work_in_root_file_dir: true
30 |
31 | - name: Compile LaTeX slides
32 | uses: xu-cheng/latex-action@v3
33 | with:
34 | root_file: "slides/*.tex"
35 | work_in_root_file_dir: true
36 |
37 | - name: Create Release
38 | if: startsWith(github.ref, 'refs/tags/2025-week-')
39 | uses: ncipollo/release-action@v1
40 | with:
41 | artifacts: "exercises*.pdf, exam/*_exam_*.pdf, slides/slides_*.pdf"
42 | generateReleaseNotes: true
43 | token: ${{ secrets.GITHUB_TOKEN }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/settings.json
2 |
3 | class/
4 | exam/summer-*
5 | stuff/
6 |
7 | week_*.log
8 | week_*.out
9 | week_*.pdf
10 | week_*_solution.tex
11 | *_exam_*.log
12 | *_exam_*.out
13 | *_exam_*.pdf
14 |
15 | *.aux
16 | *.bbl
17 | *.bcf
18 | *.blg
19 | *.fdb_latexmk
20 | *.fls
21 | *.xml
22 | *.gz
23 | *.toc
24 |
25 | progs/replications/*/*\+*/
26 | progs/replications/Baxter_King_1993/*.log
27 | progs/replications/Baxter_King_1993/Baxter_King_1993_figure_2/
28 | progs/replications/Baxter_King_1993/Baxter_King_1993_figure_3/
29 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/*.log
30 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/Eichenbaum_Rebelo_Trabandt_2022/
31 |
32 | progs/dynare/*\+*/
33 | progs/dynare/*.log
34 |
35 | progs/dynare/arma_1_1/
36 | progs/dynare/Baxter_King_steady/
37 | progs/dynare/Baxter_King_steady_growth/
38 | progs/dynare/nk/
39 | progs/dynare/nk2co_common/
40 | progs/dynare/nk2co_perm_infltarget_surprise/
41 | progs/dynare/nk2co_perm_tax_announced/
42 | progs/dynare/nk2co_temp_monpol_announced/
43 | progs/dynare/nk2co_temp_monpol_surprise/
44 | progs/dynare/rbc/
45 | progs/dynare/rbc_ces/
46 | progs/dynare/rbc_logutil/
47 |
48 | progs/matlab/num_df.m
49 | progs/matlab/rbc_dynamic_g1.m
50 | progs/matlab/rbc_dynamic_resid.m
51 | progs/matlab/rbc_static_g1.m
52 | progs/matlab/rbc_static_resid.m
53 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_figures_both/
54 |
55 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_figures_supply/
56 |
57 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_histval/
58 |
59 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_homotopy/
60 |
61 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_initval/
62 |
63 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_no_homotopy/
64 |
65 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_sticky/
66 |
67 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_sticky_steady/
68 |
69 | progs/dynare/nk_stoch/
70 |
71 | progs/dynare/nk_var_typology/
72 |
73 | progs/dynare/nk_irfs_det/
74 |
75 | progs/dynare/nk_irfs_stoch/
76 |
77 | progs/dynare/an_schorfheide_identif_bk/
78 |
79 | progs/dynare/an_schorfheide_identif_dovish/
80 |
81 | progs/dynare/an_schorfheide_identif_hawkish/
82 |
83 | progs/dynare/an_schorfheide_sensitivity_bk/
84 |
85 | progs/matlab/BrockMirman_dynamic_g1.m
86 |
87 | progs/matlab/BrockMirman_dynamic_resid.m
88 |
89 | progs/matlab/BrockMirman_static_g1.m
90 |
91 | progs/matlab/BrockMirman_static_resid.m
92 |
93 | progs/dynare/an_schorfheide_loglinear/
94 |
95 | progs/dynare/an_schorfheide_nonlinear/
96 |
97 | progs/dynare/an_schorfheide_nonlinear_exp/
98 |
99 | progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl1_tbl2_no_policy.log
100 |
101 | progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl2_environmental_policy.log
102 |
103 | progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl1_tbl2_no_policy/
104 |
105 | progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl2_environmental_policy/
106 |
107 | progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_common.log
108 |
109 | progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_common/
110 |
111 | progs/dynare/arma11/
112 |
113 | progs/dynare/BaxterKingGrowthSteadyState/
114 |
115 | progs/dynare/BaxterKingSteadyState/
116 |
117 | progs/dynare/rbcCRRA/
118 |
119 | progs/dynare/rbcLogutil/
120 |
121 | progs/replications/Annicchiarico_DiDio_2015/as_irf_a/
122 |
123 | progs/replications/Ascari_Sbordone_2014/as_fig11/
124 |
125 | progs/replications/Ascari_Sbordone_2014/as_fig14/
126 |
127 | progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig7/
128 |
129 | progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig8/
130 |
131 | progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_moments/
132 |
133 | progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_figures_demand/
134 |
135 | progs/dynare/Brock_Mirman/
136 |
--------------------------------------------------------------------------------
/exercises/_common_header.tex:
--------------------------------------------------------------------------------
1 | % !TeX encoding = UTF-8
2 | % !TeX spellcheck = en_US
3 | \documentclass[a4paper]{scrartcl}
4 | \usepackage[T1]{fontenc}
5 | %\usepackage[utf8]{inputenc}
6 | \usepackage[english]{babel}
7 | \usepackage[bottom=2.5cm,top=2.0cm,left=2.0cm,right=2.0cm]{geometry}
8 | \usepackage{amssymb,amsmath,amsfonts}
9 | \usepackage{lmodern}
10 | \usepackage{csquotes}
11 | \usepackage{url}
12 | \usepackage{doi}
13 | \usepackage{hyperref}
14 | \usepackage{enumitem}
15 | \usepackage{graphicx}
16 | \usepackage[dvipsnames]{xcolor}
17 | \definecolor{mygreen}{rgb}{0,0.4,0}
18 | \definecolor{mygray}{rgb}{0.5,0.5,0.5}
19 | \usepackage[numbered,framed]{matlab-prettifier}
20 | \usepackage[backend=biber,style=authoryear]{biblatex}
21 | \addbibresource{literature/_biblio.bib}
22 | \usepackage[stable]{footmisc}
23 | \usepackage{booktabs,longtable}
24 | \usepackage{nameref}
25 | \usepackage{float}
26 | \usepackage{tikz}
27 | \usetikzlibrary{positioning}
28 | \usetikzlibrary{decorations.text}
29 | \renewcommand{\contentsname}{Overview}
30 |
31 | \usepackage[
32 | %nosolutionfiles
33 | ]{answers}
34 |
--------------------------------------------------------------------------------
/exercises/arma_simulation.tex:
--------------------------------------------------------------------------------
1 | \section[ARMA{(1,1)} Simulation]{ARMA{(1,1)} Simulation\label{ex:ARMASimulation}}
2 | Consider the ARMA{(1,1)} model:
3 | \begin{align*}
4 | x_t - \theta x_{t-1} = \varepsilon_t - \phi \varepsilon_{t-1}
5 | \end{align*}
6 | where \(\varepsilon_t \sim N(0,1)\).
7 |
8 | \begin{enumerate}
9 |
10 | \item
11 | Compute the non-stochastic steady-state with pen and paper,
12 | i.e.\ what is the value of \(x_t\) if \(\varepsilon_t = 0\) for all \(t\)?
13 |
14 | \item
15 | Write a Dynare mod file for this model:
16 |
17 | \begin{itemize}
18 |
19 | \item
20 | \(x\) is the endogenous variable, \({\varepsilon}\) the exogenous variable, and \({\theta}\) and \({\phi}\) are the parameters.
21 |
22 | \item
23 | Set \(\theta = \phi = 0.4\).
24 |
25 | \item
26 | Write either a \texttt{steady\_state\_model} or \texttt{initval} block and compute the steady-state.
27 |
28 | \item
29 | Start at the non-stochastic steady-state and simulate 200 data points using a \texttt{shocks} block
30 | and the \texttt{stoch\_simul} command.
31 | Plot both \(x\) as well as \({\varepsilon}\) using \texttt{rplot}.
32 |
33 | \item
34 | Try out different values for \({\theta}\) and \({\phi}\).
35 | What do you notice?
36 |
37 | \end{itemize}
38 |
39 | \item
40 | Redo the exercise in MATLAB without using Dynare.
41 |
42 | \end{enumerate}
43 |
44 | \emph{Hints}:
45 |
46 | \begin{itemize}
47 |
48 | \item
49 | Don't forget to add Dynare's matlab folder:
50 | \texttt{addpath C:/dynare/6.0/matlab} for Windows,
51 | \texttt{addpath /Applications/Dynare/6.0/matlab} for macOS,
52 | \texttt{addpath /opt/dynare/6.0/matlab} for Linux machines.
53 | If you installed Dynare to a different folder, adapt the path accordingly.
54 |
55 | \item
56 | When saving your Dynare script as a mod file, try to use a simple name.
57 | That is, don't use special characters or spaces in the filename, e.g.\
58 | \texttt{arma{(1,1)}.mod} as well as \texttt{arma 1 1.mod} are not valid filenames,
59 | whereas \texttt{arma.mod} or \texttt{arma\_1\_1.mod} or \texttt{arma11.mod} are valid.
60 |
61 | \item
62 | It is advised to save the mod file directly on your hard drive and not on a cloud storage drive.
63 | If you do save it to a folder that is in sync with e.g.\ Dropbox, iCloud, Nextcloud, OneDrive (etc),
64 | please (temporarily) deactivate sync activities,
65 | to prevent sync conflicts and weird errors when running Dynare.
66 |
67 | \end{itemize}
68 |
69 |
70 | \begin{solution}\textbf{Solution to \nameref{ex:ARMASimulation}}
71 | \ifDisplaySolutions%
72 | \input{exercises/arma_simulation_solution.tex}
73 | \fi
74 | \newpage
75 | \end{solution}
--------------------------------------------------------------------------------
/exercises/arma_simulation_solution.tex:
--------------------------------------------------------------------------------
1 | \begin{enumerate}
2 |
3 | \item
4 | As for all \(t\) the shocks are zero, i.e.\
5 | \(\varepsilon_t = 0\), we get \(x - \theta x = 0 \Leftrightarrow x = 0\),
6 | where \(x\) denotes the non-stochastic steady-state
7 | (we drop the time subscript in the original equation when computing the steady-state).
8 |
9 | \item
10 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/dynare/arma11.mod}
11 |
12 | Some notes:
13 |
14 | \begin{itemize}
15 |
16 | \item
17 | Whenever the parameters are equal to each other, the simulated series for \(x_t\) is always equal to the drawn shocks \(\varepsilon_t\).
18 |
19 | \item
20 | Sometimes Dynare prints an error message, e.g.\ try out \(\theta=1.5\) and \(\theta=0.4\).
21 | If you are familiar with time series models, this is due to the fact that this parameter combination provides a non-stationary process,
22 | i.e.\ the process explodes and does not return to the equilibrium/steady-state.
23 | \end{itemize}
24 |
25 | \item
26 | This function simulates the ARMA{(1,1)} model in MATLAB:\@
27 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/arma11Simulate.m}
28 | This script can be used to compare the results from Dynare with the results from MATLAB:\@
29 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/arma11CompareMATLABWithDynare.m}
30 |
31 | \end{enumerate}
--------------------------------------------------------------------------------
/exercises/case_study_annicchiarico_DiDio_2015_solution.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/exercises/case_study_annicchiarico_DiDio_2015_solution.tex
--------------------------------------------------------------------------------
/exercises/case_study_ascari_sbordone_2014.tex:
--------------------------------------------------------------------------------
1 | \section[Case Study Ascari and Sbordone (2014): The Macroeconomics of Trend Inflation]{Case Study Ascari and Sbordone (2014): The Macroeconomics of Trend Inflation\label{ex:CaseStudy.Ascari.Sbordone.2014}}
2 |
3 | \begin{enumerate}
4 | \item Read the paper by \textcite{Ascari.Sbordone_2014_MacroeconomicsTrendInflation} and its Appendix.
5 | How does the model differ from the New Keynesian model that we studied in the course so far?
6 |
7 | \item Consider the following Dynare files given in the appendix:
8 | \begin{itemize}
9 | \item \texttt{ascari\_sbordone\_2014\_common.mod}
10 | \item \texttt{ascari\_sbordone\_2014\_calib\_common.inc}
11 | \end{itemize}
12 | Explain what each file is doing.
13 |
14 | \item Replicate figure 14 of the paper.
15 | Set initially \(\varphi = 1\), \(\phi_\pi=2\), \(\phi_y = 0.5/4\) and \(\rho_i=0.8\).
16 |
17 | \item Replicate figure 13 of the paper.
18 | Set initially \(\varphi = 0\), \(\phi_\pi=1.5\), \(\phi_y = 0.5/4\) and \(\rho_i=0\).
19 |
20 | \item Replicate the business cycle moments reported on page 717.
21 | Set initially \(\varphi = 1\), \(\rho_a=0.95\), \(\rho_i=0\) \(\phi_\pi=1.5\), and \(\phi_y = 0.5/4\).
22 | Note that for the business cycle moments, the technology shock standard error is actually \(0.45\).
23 |
24 | \item Replicate figure 7 of the paper.
25 | Set initially \(\varphi = 1\), \(\phi_\pi=2\), \(\phi_y = 0.5/4\) and \(\rho_i=0.8\).
26 |
27 | \item Replicate figure 8 of the paper.
28 | Set initially \(\varphi = 1\), \(\phi_\pi=2\), \(\phi_y = 0.5/4\) and \(\rho_i=0.8\).
29 |
30 | \item Replicate figure 11 of the paper.
31 | Set initially \(\varphi = 1\), \(\phi_\pi=2\), \(\phi_y = 0.5/4\) and \(\rho_i=0.8\).
32 | Note that as described in footnote 54, the determinacy region in Figure 11 is actually the \enquote{determinacy and stability region},
33 | i.e.\ it does not distinguish whether the Blanchard-Kahn conditions fail because of too many unstable roots (instability, info==3)
34 | or because of too few unstable roots (indeterminacy, info==4).
35 |
36 | \end{enumerate}
37 |
38 | \paragraph{Hints}
39 |
40 | \begin{itemize}
41 |
42 | \item The annual inflation target is disaggregated to quarterly figures using the geometric mean.
43 | Simply dividing by 4 results in small numerical differences.
44 |
45 | \item The labor disutility parameter, which is unspecified in the paper is set so that labor is 1/3 in the benchmark case.
46 |
47 | \item The technology parameter, which is also left unspecified in the published version, is set to 1 in steady-state.
48 |
49 | \end{itemize}
50 |
51 |
52 | \begin{solution}\textbf{Solution to \nameref{ex:CaseStudy.Ascari.Sbordone.2014}}
53 | \ifDisplaySolutions%
54 | \input{exercises/case_study_ascari_sbordone_2014_solution.tex}
55 | \fi
56 | \newpage
57 | \end{solution}
--------------------------------------------------------------------------------
/exercises/case_study_ascari_sbordone_2014_solution.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/exercises/case_study_ascari_sbordone_2014_solution.tex
--------------------------------------------------------------------------------
/exercises/case_study_baxter_king_figure2.tex:
--------------------------------------------------------------------------------
1 | \section[Case Study Baxter and King (1993, AER): Macroeconomic Effects Of A Permanent Increase in Basic Government Purchases]{Case Study Baxter and King (1993, AER): Macroeconomic Effects Of A Permanent Increase in Basic Government Purchases\label{ex:CaseStudy.BaxterKing.Figure2}}
2 |
3 | \begin{enumerate}
4 |
5 | \item
6 | Read the paper by \textcite{Baxter.King_1993_FiscalPolicyGeneral}
7 | and focus particularly on the model equations and analysis done in section III.B.
8 |
9 | \item
10 | Write a Dynare mod file for the model
11 | and calibrate it according to the \emph{Benchmark Model with Basic Government Purchases} given in Table 1.
12 | Compute the steady-state using an \texttt{initval} block.
13 |
14 | \item Replicate Figure 2.
15 |
16 | \end{enumerate}
17 |
18 | \paragraph{Notes and hints}
19 |
20 | \begin{itemize}
21 | \item
22 | According to footnote 3, the quantitative analysis corresponds to a model with labor-augmenting technical progress.
23 | Calibrate \(\gamma_X\) such that the economy grows at 1.6\% per annum,
24 | a typical value used in e.g.\ \textcite{King.Plosser.Rebelo_1988_ProductionGrowthBusiness}.
25 |
26 | \item
27 | Pay attention to the different scales on the y-axes, i.e.\ commodity units, percent, and basis points.
28 |
29 | \item
30 | Skip the term structure variable in panel \emph{C.}, as we will re-visit the term structure in RBC models later on.
31 |
32 | \item Use a perfect foresight simulation for computing the transition path
33 | (i) from the initial steady-state (specified by \texttt{initval}) to
34 | (ii) a terminal steady-state (specified by \texttt{endval}) with
35 | (iii) a permanent increase in basic government purchases (specified by setting a nonzero value on the exogenous variable in the terminal steady-state).
36 | The following code snippet might be useful:
37 |
38 | \end{itemize}
39 |
40 | {\footnotesize
41 | \begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize]
42 | idx_y = varlist_indices('y', M_.endo_names); % index to access y in oo_.endo_simul
43 |
44 | % STEP 1: SET INITIAL CONDITION
45 | initval;
46 | % TODO: add values for all variables with the initial steady-state
47 | end;
48 | steady; % compute initial steady-state
49 | % steady after initval uses the computed steady-state to initialize oo_.endo_simul
50 |
51 | % STEP 2: SET TERMINAL CONDITION
52 | commodity_unit = 0.01*oo_.steady_state(idx_y); % commodity unit (p.321) defined as 1% of initial output
53 |
54 | endval;
55 | % TODO: set a nonzero value for the exogenous variable on basic government spending to implement a permanent increase
56 | % other variables that are not specified in the endval block remain at the initial steady-state
57 | end;
58 |
59 | steady; % recompute steady-state numerically starting from old steady-state and changed values
60 | % steady after endval will set the terminal condition oo_.endo_simul(:,end) to the endval steady-state
61 |
62 | % STEP 3: COMPUTE TRANSITION PATH
63 | perfect_foresight_setup(periods=200);
64 | perfect_foresight_solver;
65 |
66 | % STEP 4: PLOTTING
67 | % oo_.endo_simul contains the simulated variables,
68 | % note that the first entry is the initial condition (initval steady-state)
69 | % and the last is the terminal condition (endval steady-state)
70 | horizon = 1:22;
71 | % do transformations on plotted variables
72 | plot_y = (oo_.endo_simul(idx_y,horizon+1)-oo_.endo_simul(idx_y,1))./commodity_unit; % deviation from initial steady-state, normalized in commodity units
73 | plot(horizon,plot_y, "o",'MarkerEdgeColor','black','MarkerFaceColor','black','MarkerSize',8,'LineStyle','none');
74 |
75 | \end{lstlisting}
76 | }%
77 |
78 | \begin{solution}\textbf{Solution to \nameref{ex:CaseStudy.BaxterKing.Figure2}}
79 | \ifDisplaySolutions%
80 | \input{exercises/case_study_baxter_king_figure2_solution.tex}
81 | \fi
82 | \newpage
83 | \end{solution}
--------------------------------------------------------------------------------
/exercises/case_study_baxter_king_figure2_solution.tex:
--------------------------------------------------------------------------------
1 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Baxter_King_1993/Baxter_King_1993_figure_2.mod}
--------------------------------------------------------------------------------
/exercises/case_study_baxter_king_figure3.tex:
--------------------------------------------------------------------------------
1 | \section[Case Study Baxter and King (1993, AER): Macroeconomic Effects Of A Four-Year War]{Case Study Baxter and King (1993, AER): Macroeconomic Effects Of A Four-Year War\label{ex:CaseStudy.BaxterKing.Figure3}}
2 |
3 | \begin{enumerate}
4 | \item
5 | Read the paper by \textcite{Baxter.King_1993_FiscalPolicyGeneral}
6 | and focus particularly on the model equations and analysis done in section IV.A.
7 |
8 | \item
9 | Write a Dynare mod file for the model and calibrate it according to
10 | the \emph{Benchmark Model with Basic Government Purchases} given in Table 1.
11 | Compute the steady-state using an \texttt{initval} block.
12 |
13 | \item
14 | Replicate Figure 3.
15 |
16 | \item
17 | Do you think this simulation scenario reflects the essence of a war shock?
18 |
19 | \end{enumerate}
20 |
21 | \paragraph{Notes and hints}
22 |
23 | \begin{itemize}
24 | \item
25 | According to footnote 3, the quantitative analysis corresponds to a model with labor-augmenting technical progress.
26 | Calibrate \(\gamma_X\) such that the economy grows at 1.6\% per annum,
27 | a typical value used in e.g.\ \textcite{King.Plosser.Rebelo_1988_ProductionGrowthBusiness}.
28 |
29 | \item
30 | Pay attention to the different scales on the y-axes,
31 | i.e.\ commodity units, percent, and basis points.
32 |
33 | \item
34 | Skip the term structure variable in panel \emph{C.},
35 | as we will re-visit the term structure in RBC models later on.
36 |
37 | \item
38 | Use a perfect foresight simulation for computing the transition path
39 | from the initial steady-state (specified by an \texttt{initval} block)
40 | subject to a sequence of four basic government purchases shocks
41 | (specified by a \texttt{shocks} block).
42 |
43 | \end{itemize}
44 |
45 | \begin{solution}\textbf{Solution to \nameref{ex:CaseStudy.BaxterKing.Figure3}}
46 | \ifDisplaySolutions%
47 | \input{exercises/case_study_baxter_king_figure3_solution.tex}
48 | \fi
49 | \newpage
50 | \end{solution}
--------------------------------------------------------------------------------
/exercises/case_study_baxter_king_figure3_solution.tex:
--------------------------------------------------------------------------------
1 | \begin{enumerate}
2 |
3 | \item[2.~and 3.]
4 | The mod file might look like this:
5 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Baxter_King_1993/Baxter_King_1993_figure_3.mod}
6 |
7 | \item[4.]
8 | No, for many reasons. To name just two:
9 |
10 | \begin{itemize}
11 |
12 | \item
13 | A war is a large shock with unknown duration.
14 | Perfect foresight simulations do not capture this as in period 1 everything is revealed to the agents.
15 | A solution to this would be a perfect-foresight simulation with expectation errors (sometimes called MIT-shock).
16 | To this end, one simulates the sequence of shocks
17 | but alters the information set of the agents in each period
18 | before the onset of another shock.
19 | Algorithmically, we repeat the simulation cycle four times
20 | and then combine the simulations,
21 | utilizing the first one for periods \(1\) to \(2\),
22 | the second one for \(2\) to \(3\), the third one for \(3\) to \(4\) \ldots,
23 | and the fourth one for \(4\) to \(T\).
24 | In Dynare 6.0 there is a new command for such a simulation called
25 | \texttt{perfect{\_}foresight{\_}with{\_}expectation{\_}errors}.
26 | For older versions of Dynare this type of simulation can be done
27 | by running a sequence of perfect foresight simulations
28 | while adjusting initial conditions manually.
29 | Intuitively, this captures the belief that guides agents during times of war;
30 | namely, that the conflict will last only one year
31 | (the surprise shock on impact) and will not occur again.
32 | However, this belief is challenged when the war continues beyond the expected duration,
33 | and agents are surprised by the ongoing conflict
34 | (restart the simulation with a new surprise shock in the next period).
35 | Despite this surprise, the belief in a one-year duration persists,
36 | leading to ongoing cycles of surprise shocks (and expectation errors).
37 |
38 | \item
39 | A war shock has many channels;
40 | solely relying on a demand-side effect via government spending
41 | reflects a very US-specific view.
42 | There is research that war shocks are rather dominated by supply-side effects
43 | and also accompanied by different policy stances during war times.
44 | One could argue that the current simulation is for a neighboring country,
45 | as the US has never really been a war site itself
46 | (except for comparably minor battles of Pearl Harbor and the Aleutian islands
47 | during World War II).
48 | \end{itemize}
49 |
50 | \end{enumerate}
51 |
--------------------------------------------------------------------------------
/exercises/computational_macroeconomics_scope.tex:
--------------------------------------------------------------------------------
1 | \section[What is Computational Macroeconomics]{What is Computational Macroeconomics\label{ex:ComputationalMacroeconomics}}
2 | Broadly define the scope and research topics of \enquote{Computational Macroeconomics},
3 | sometimes referred to as \enquote{Numerical Methods in Macroeconomics}.
4 | What are the challenges and approaches?
5 |
6 | \paragraph{Readings}
7 | \begin{itemize}
8 | \item \textcite[Ch. 1--2]{Fernandez-Villaverde.Rubio-Ramirez.Schorfheide_2016_SolutionEstimationMethods}
9 | \item \textcite[Ch. 1--2]{Maliar.Maliar_2014_NumericalMethodsLargeScale}
10 | \item \textcite[Ch. 1]{Judd_1998_NumericalMethodsEconomics}
11 | \end{itemize}
12 |
13 | \begin{solution}\textbf{Solution to \nameref{ex:ComputationalMacroeconomics}}
14 | \ifDisplaySolutions%
15 | \input{exercises/computational_macroeconomics_scope_solution.tex}
16 | \fi
17 | \newpage
18 | \end{solution}
--------------------------------------------------------------------------------
/exercises/computational_macroeconomics_scope_solution.tex:
--------------------------------------------------------------------------------
1 | Computational macroeconomics combines (i) modern theoretical macroeconomics
2 | (the study of aggregated variables such as economic growth, unemployment and inflation
3 | by means of structural macroeconomic models)
4 | with (ii) state-of-the-art numerical methods (the application of numerical methods by means of algorithms).
5 | To this end, we will focus on the workhorse Dynamic Stochastic General Equilibrium (DSGE) model paradigm,
6 | and develop the numerical procedures and algorithms required to solve and simulate such models.
7 | This enables us to look at abstract macroeconomic concepts, for example:
8 | \begin{itemize}
9 | \item transmission channels of macroeconomic shocks in linearly vs non-linearly solved models
10 | \item the short- and long-run effects of a higher inflation target
11 | \item models with occasionally binding constraints (zero-lower-bound, irreversible investment)
12 | \item the effects of quantitative easing/tightening (possibly at the zero-lower-bound)
13 | \item importance of precautionary savings and heterogenous agents
14 | \item fiscal multipliers: the effects of government spending and taxes
15 | \item models with rare disasters (financial crises, pandemics, wars)
16 | \item dynamics of the transition from dirty to green energy
17 | \item optimal monetary, fiscal and environmental policy
18 | \end{itemize}
19 |
20 | To study such phenomena we typically cannot use simplified pen-and-paper models anymore,
21 | but need to rely on a computer to solve and simulate such models.
22 | The computer basically becomes our lab in which we can conduct experiments
23 | by changing parameters or running counter-factual scenarios and policies.
24 | This enables us to not only describe but also quantify transmission channels and effects of different economic policies
25 | in order to provide sound and exact policy analysis and advice.
26 |
27 | The computational implementation, however, is often cumbersome and challenging.
28 | Fortunately, modern programming languages make it easier for us to develop algorithms
29 | and toolboxes for dealing with structural models in macroeconomics.
30 | There is always a trade-off between model complexity and numerical method complexity.
31 | Sometimes it is easier to simplify slightly your model instead of inventing new numerical methods.
32 | Other times the specific question under study enforces you to develop new algorithms and approaches.
33 | In practice, however, most of the times you don't have to reinvent the wheel,
34 | but build on previous approaches, improve algorithms or adapt them in order to answer your research question.
35 | The challenge is often that the codes developed so far are quite model-specific
36 | and require a high degree of fine-tuning and thus a deep understanding of the underlying algorithms.
37 | Open-Source projects like Dynare aim to provide a model-independent and user-friendly approach;
38 | but it takes time for the development team of Dynare to catch up with the most recent developments in the literature
39 | and keeping legacy code up-to-date.
40 |
41 | Be warned: there is quite the investment one needs to undergo to study computational macroeconomics
42 | and there is a huge component of self-teaching involved,
43 | because most of us lack the required background in computational science, numerics and mathematics.
44 | In fact, most macroeconomists doing research in this area are more or less self-taught (I can attest to this for myself),
45 | and we are always trying to look across the pond at what the current developments are in computer science and numerical mathematics
46 | and whether or not these are useful to solve and simulate our structural models.
--------------------------------------------------------------------------------
/exercises/matlab_quick_tour_solution.tex:
--------------------------------------------------------------------------------
1 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/quickTourMatlab.m}
--------------------------------------------------------------------------------
/exercises/matlab_symbolic_solution.tex:
--------------------------------------------------------------------------------
1 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/symbolicToolboxIllustation.m}
--------------------------------------------------------------------------------
/exercises/matrix_algebra.tex:
--------------------------------------------------------------------------------
1 | \section[Matrix Algebra]{Matrix Algebra\label{ex:MatrixAlgebra}}
2 | Let
3 | \begin{align*}
4 | A = \begin{pmatrix}0.5 &0 &0 \\0.1&0.1&0.3\\0&0.2&0.3 \end{pmatrix}
5 | &&
6 | \Sigma_u = \begin{pmatrix}2.25 & 0 & 0\\ 0 & 1 & 0.5\\ 0 & 0.5 & 0.74 \end{pmatrix}
7 | \end{align*}
8 |
9 | \begin{enumerate}
10 |
11 | \item
12 | Compute the eigenvalues of A.
13 | What would this imply for the system \(y_t = c + A y_{t-1} + u_t\) with \(u_t\) being white noise
14 | (\(E[u_t]=0\), \(E[u_t u_t'] = \Sigma_u\), and \(\forall s\neq t: E[u_t u_{t+s}'] = 0\))?
15 |
16 | \item
17 | Consider the matrices \(D\): \(m\times n\), \(E\): \(n\times p\) and \(F\): \(p\times k\).
18 | Show that
19 | \begin{align*}
20 | vec(DEF)=\left(F'\otimes D\right) vec(E)
21 | \end{align*}
22 | where \(\otimes \) is the Kronecker product and \(vec\) the vectorization operator.
23 |
24 | \item
25 | Compute a regular lower triangular matrix \(W \in \mathbb{R}^{3 \times 3}\)
26 | and a diagonal matrix \(\Sigma_\varepsilon \in \mathbb{R}^{3 \times 3}\)
27 | such that \(\Sigma_u=W \Sigma_\varepsilon W'\).
28 | \\
29 | Hint: Use the Cholesky factorization
30 | \(\Sigma_u = P P' = W \Sigma_\varepsilon^{\frac{1}{2}}(W \Sigma_\varepsilon^{\frac{1}{2}})'\).
31 |
32 | \item
33 | Solve the discrete Lyapunov matrix equation \(\Sigma_{y} = A\Sigma_{y}A' + \Sigma_{u}\) using
34 | \begin{enumerate}
35 | \item the Kronecker product and vectorization
36 | \item the following iterative algorithm:
37 | \begin{align*}
38 | \Sigma_{y,0} &= I, A_0 = A, \Sigma_{u,0} = \Sigma_{u}\\
39 | \Sigma_{y,i+1} &= A_i \Sigma_{y,i} A_i' + \Sigma_{u,i}\\
40 | \Sigma_{u,i+1} &= A_i \Sigma_{u,i} A_i' + \Sigma_{u,i}\\
41 | A_{i+1} &= A_i A_i
42 | \end{align*}
43 | Write a loop until either a maximal number of iterations (say 500) is reached
44 | or each element of \(\Sigma_{y,i+1}-\Sigma_{y,i}\) is less than \(10^{-25}\) in absolute terms.
45 | \item Compare both approaches for A and \(\Sigma_u\) given above.
46 | \end{enumerate}
47 |
48 | \end{enumerate}
49 |
50 | \paragraph{Readings:}
51 |
52 | \begin{itemize}
53 | \item \textcite[Ch.~4.2]{Anderson.McGrattan.Hansen.EtAl_1996_MechanicsFormingEstimating}
54 | \item \textcite[Ch.~6.7]{Anderson.Moore_1979_OptimalFiltering}
55 | \item \textcite[Ch.~4.10]{Uribe.Schmitt-Grohe_2017_OpenEconomyMacroeconomics}
56 | \end{itemize}
57 |
58 | \begin{solution}\textbf{Solution to \nameref{ex:MatrixAlgebra}}
59 | \ifDisplaySolutions%
60 | \input{exercises/matrix_algebra_solution.tex}
61 | \fi
62 | \newpage
63 | \end{solution}
--------------------------------------------------------------------------------
/exercises/nk_simulations.tex:
--------------------------------------------------------------------------------
1 | \section[Basic New Keynesian Model: Simulations in Dynare]{New Keynesian Model: Simulations in Dynare\label{ex:NewKeynesianModelSimulationsDynare}}
2 | Consider the basic New Keynesian (NK) model with capital, monopolistic competition, Calvo price rigidities, and investment adjustment costs,
3 | which is given in the Dynare mod file called \texttt{nk.mod}.
4 |
5 | \begin{enumerate}
6 |
7 | \item Use stochastic simulations (i.e. the \texttt{stoch\_simul(order=1,irf=30)} command) for the \emph{hat} variables to study the effects of a
8 | \begin{enumerate}
9 | \item unit shock to technology $\varepsilon_{a,t}$.
10 | \item contractionary monetary policy shock of an increase of 25 basis points in $\varepsilon_{\nu,t}$.
11 | \item discount factor shock by setting the size of the initial shock $\varepsilon_{\zeta,t}$ to -0.5 percentage points.
12 | \end{enumerate}
13 | Try to explain the responses of the agents and model variables in your own words using the economic mechanisms of this model.
14 |
15 | \item Redo the previous exercise using deterministic simulations,
16 | i.e.\ using \texttt{perfect\_foresight\_setup} and \texttt{perfect\_foresight\_solver}.
17 | Compare both simulation approaches.
18 | \end{enumerate}
19 |
20 | \paragraph{Readings}
21 | \begin{itemize}
22 | \item \textcite[Ch.~3]{Gali_2015_MonetaryPolicyInflation}
23 | \item \textcite{Rupert.Sustek_2019_MechanicsNewKeynesianModels}
24 | \end{itemize}
25 |
26 | \begin{solution}\textbf{Solution to \nameref{ex:NewKeynesianModelSimulationsDynare}}
27 | \ifDisplaySolutions
28 | \input{exercises/nk_simulations_solution.tex}
29 | \fi
30 | \newpage
31 | \end{solution}
--------------------------------------------------------------------------------
/exercises/numerical_optimization.tex:
--------------------------------------------------------------------------------
1 | \section[Numerical optimization in MATLAB]{Numerical optimization in MATLAB\label{ex:MatlabNumericalOptimization}}
2 |
3 | \begin{enumerate}
4 |
5 | \item
6 | In a nutshell, what is the goal of numerical optimization?
7 |
8 | \item
9 | What is an \emph{objective function}, what are \emph{decision or design variables}, what is a \emph{gradient}, and what is a \emph{constraint}?
10 |
11 | \item
12 | What is the general idea behind gradient-based optimization algorithms?
13 |
14 | \item
15 | What is the general idea behind gradient-free optimization algorithms? Name a few examples.
16 |
17 | \item
18 | In numerical optimization theory, the Rosenbrock function is a non-convex function
19 | often used as a performance test problem for optimization algorithms.
20 | It is defined by:
21 | \begin{align*}
22 | f(x,y) = 100{(y-x^2)}^2 + {(1-x)}^2
23 | \end{align*}
24 | The global minimum is inside a long, narrow, parabolic shaped flat valley.
25 | To find the valley is trivial;
26 | to converge to the global minimum, however, is difficult.
27 |
28 | \begin{enumerate}
29 |
30 | \item
31 | Make a 3D plot of the function to see that the global minimum is at \((x, y)=(1, 1)\) where \(f(x, y)=0\).
32 | \begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize]
33 | fsurf(@(x,y) ((1-x).^2)+(100*((y-(x.^2)).^2)),[-2 2 -2 5],'ShowContours','on')
34 | title('Rosenbrock function')
35 | xlabel('x')
36 | ylabel('y')
37 | \end{lstlisting}
38 |
39 | \item
40 | Find the global minimum of the function by trying out different optimizers.
41 | Draw the initial values randomly (e.g.\ with \texttt{randi}).
42 |
43 | \end{enumerate}
44 |
45 | \item
46 | In numerical optimization theory, the Rastrigin function is a non-convex function
47 | often used as a performance test problem for optimization algorithms.
48 | It is a typical example of a non-linear multi-modal function and given by:
49 | \begin{align*}
50 | f(x,y) = 20 + x^2 + y^2 - 10(\cos(2\pi x)+\cos(2\pi y))
51 | \end{align*}
52 | Note that the global minimum is at \((x, y)=(0, 0)\) where \(f(x, y)=0\).
53 | Finding the minimum of this function is a fairly difficult problem
54 | due to its large search space and its large number of local minima.
55 | Repeat the previous exercise on the Rastrigin function.
56 | \end{enumerate}
57 |
58 |
59 | \paragraph{Readings}
60 | \begin{itemize}
61 | \item AlphaOpt: Introduction to Optimization: What Is Optimization?\\
62 | \url{https://youtu.be/Q2dewZweAtU?si=qGu_NpNSbM9yuAdR}
63 | \item MathWorks: Comparison of Six Solvers\\
64 | \url{https://mathworks.com/help/gads/example-comparing-several-solvers.html}
65 | \end{itemize}
66 |
67 | \begin{solution}\textbf{Solution to \nameref{ex:MatlabNumericalOptimization}}
68 | \ifDisplaySolutions%
69 | \input{exercises/numerical_optimization_solution.tex}
70 | \fi
71 | \newpage
72 | \end{solution}
--------------------------------------------------------------------------------
/exercises/preprocess_matlab_rbc_solution.tex:
--------------------------------------------------------------------------------
1 | \begin{enumerate}
2 |
3 | \item
4 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/dynare/rbc.mod}
5 |
6 | \item
7 | Dynare's preprocessor creates the following script files:
8 | \begin{itemize}
9 | \item
10 | \texttt{driver.m}: the preprocessor reads the text and information provided in the mod file and creates MATLAB code from this.
11 | The \texttt{driver.m} contains these transformations and it is pure MATLAB code,
12 | meaning that you can simply run it in MATLAB (e.g.\ hit the green run button).
13 | In this script all model information is stored into structures.
14 | Particularly, the global structures \texttt{M\_} (which contains model information),
15 | \texttt{options\_} (which contains default values for options),
16 | and \texttt{oo\_} (which contains results) are initialized
17 | (and some other structures as well depending on the commands you run in your mod file).
18 |
19 | \item
20 | \texttt{dynamic\_resid.m}: this is a script file with MATLAB code that evaluates the residuals of the dynamic model equations,
21 | i.e.\ what we get when we put all model equations on the right hand side
22 | and evaluate this system of equations for arbitrary values of the dynamic variables and the parameters.
23 | Note that the dynamic files distinguish that variables can appear at different timings \(t-1\), \(t\) or \(t+1\).
24 |
25 | \item
26 | \texttt{static\_resid.m}: this is a script file with MATLAB code that evaluates the residuals of the static model equations.
27 | The static model equations are given when we strip of the timings of the variables.
28 | The file then computes the residuals, i.e.\ when we put all model equations on the right hand side
29 | and evaluate the static system of equations for arbitrary values of the static variables and parameters.
30 |
31 | \item
32 | \texttt{dynamic\_g1.m}: this is a script file with MATLAB code that evaluates the Jacobian of the dynamic model equations
33 | with respect to the dynamic model variables and the exogenous shock.
34 | That is, let \(f(z)\) denote the model equations and \(z\) the vector of the dynamic variables and the exogenous variables,
35 | then \(g1\) computes \(\partial f(z) \ \partial z\).
36 |
37 | \item
38 | \texttt{static\_g1.m}: this is a script file with MATLAB code that evaluates the Jacobian of the static model equations
39 | with respect to the model variables.
40 | That is, let \(\bar{f}(y)\) denote the model equations and \(y\) the vector of the model variables,
41 | then this file computes \(\partial \bar{f}(y) \ \partial y\).
42 | \end{itemize}
43 |
44 | \item
45 | The Jacobian \(g_1\) of the dynamic model is a key matrix for solving and simulating DSGE models.
46 | It's row dimension is equal to the number of equations,
47 | and the columns correspond to which endogenous variable the derivative is taken with respect to.
48 | First come the \(t-1\) variables (that actually appear in the model equations at \(t-1\)),
49 | then the \(t\) variables (that actually appear in the model equations at \(t\)),
50 | then the \(t+1\) variables (that actually appear in the model equations at \(t+1\)),
51 | and lastly the exogenous variables.
52 | When computing the Jacobian of the dynamic model,
53 | the order of the endogenous variables in the columns is stored in \texttt{M\_.lead\_lag\_incidence}.
54 | The rows of this matrix represent time periods: the first row denotes a lagged (time \(t-1\)) variable,
55 | the second row a contemporaneous (time \(t\)) variable,
56 | and the third row a leaded (time \(t+1\)) variable.
57 | The columns of the matrix represent the endogenous variables in their order of declaration.
58 | A zero in the matrix means that this endogenous does not appear in the model in this time period.
59 | The value in the \texttt{M\_.lead\_lag\_incidence} matrix
60 | corresponds to the column of that variable in the Jacobian \(g_1\) of the dynamic model.
61 |
62 | \item
63 | A preprocessing script:
64 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/preprocessingRBC.m}
65 |
66 | \item
67 | A script for comparison:
68 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/preprocessingComparisonRBC.m}
69 |
70 | \end{enumerate}
--------------------------------------------------------------------------------
/exercises/programming_languages.tex:
--------------------------------------------------------------------------------
1 | \section[Programming Languages]{Programming Languages\label{ex:ProgrammingLanguages}}
2 | \begin{enumerate}
3 | \item Name some popular programming languages in macroeconomics.
4 | Which are general purpose, which are domain specific?
5 | \item What are the differences between compiled and interpreted languages?
6 | \item What is important when choosing a programming language for scientific computing in macroeconomics?
7 | Which programming language{(s)} would you choose?
8 | \end{enumerate}
9 |
10 | \paragraph{Readings}
11 | \begin{itemize}
12 | \item \textcite{Aguirre.Danielsson_2020_WhichProgrammingLanguage}
13 | \item \textcite{Aruoba.Fernandez-Villaverde_2015_ComparisonProgrammingLanguages} (note the Update available at \url{https://www.sas.upenn.edu/~jesusfv/Update_March_23_2018.pdf})
14 | \end{itemize}
15 |
16 | \begin{solution}\textbf{Solution to \nameref{ex:ProgrammingLanguages}}
17 | \ifDisplaySolutions%
18 | \input{exercises/programming_languages_solution.tex}
19 | \fi
20 | \newpage
21 | \end{solution}
--------------------------------------------------------------------------------
/exercises/rbc_model_description_short.tex:
--------------------------------------------------------------------------------
1 | \begin{center}
2 | \begin{longtable}{lc}
3 | \caption{Dynamic Model Equations\label{tbl:RBC.Model}}\\%
4 | \toprule%
5 | \multicolumn{1}{c}{\textbf{Equation}} &
6 | \multicolumn{1}{c}{\textbf{Description}}\\%
7 | \midrule\midrule%
8 | \endfirsthead%
9 | \multicolumn{2}{c}{{\tablename} \thetable{} {--} Continued}\\%
10 | \midrule%
11 | \multicolumn{1}{c}{\textbf{Variable}} &
12 | \multicolumn{1}{c}{\textbf{Description}}\\%
13 | \midrule\midrule%
14 | \endhead%
15 | \({{\gamma}}\, {{c}}_{t}^{-1}={{\gamma}}\, {{\beta}}\, {{c}}_{t+1}^{-1}\, \left(1-{{\delta}}+{{r}}_{t+1}\right)\) & intertemporal optimality (Euler)
16 | \\
17 | \({{w}}_{t}=-\frac{-{{\psi}}\, {\left(1-{{n}}_{t}\right)}^{-1}}{{{\gamma}}\, {{c}}_{t}^{-1}}\) & labor supply
18 | \\
19 | \({{k}}_{t}=\left(1-{{\delta}}\right)\, {{k}}_{t-1}+{{i}}_{t}\) & capital accumulation
20 | \\
21 | \({{y}}_{t}={{c}}_{t}+{{i}}_{t}\) & market clearing
22 | \\
23 | \({{y}}_{t}={{a}}_{t}\, {{k}}_{t-1}^{{{\alpha}}}\, {{n}}_{t}^{1-{{\alpha}}}\) & production function
24 | \\
25 | \({{w}}_{t}=\left(1-{{\alpha}}\right)\frac{{{y}}_{t}}{{{n}}_{t}}\) & labor demand
26 | \\
27 | \({{r}}_{t}={{\alpha}}\frac{{{y}}_{t}}{{{k}}_{t-1}}\) & capital demand
28 | \\
29 | \(\log\left({{a}}_{t}\right)= (1-\rho) \log{(a)} + {{\rho}}\, \log\left({{a}}_{t-1}\right)+{{\varepsilon}}_{t}\) & total factor productivity
30 | \\
31 | \bottomrule%
32 | \end{longtable}
33 | \end{center}
34 |
35 | \begin{minipage}{.3\linewidth}
36 | \begin{center}
37 | \begin{longtable}{cc}
38 | \caption{Variables\label{tbl:RBC.Variables}}\\%
39 | \toprule
40 | \multicolumn{1}{c}{\textbf{Variable}} &
41 | \multicolumn{1}{c}{\textbf{Description}}\\%
42 | \midrule\midrule%
43 | \endfirsthead%
44 | \multicolumn{2}{c}{{\tablename} \thetable{} {--} Continued}\\%
45 | \midrule%
46 | \multicolumn{1}{c}{\textbf{Variable}} &
47 | \multicolumn{1}{c}{\textbf{Description}}\\%
48 | \midrule\midrule%
49 | \endhead%
50 | \({y}\) & output\\
51 | \({c}\) & consumption\\
52 | \({k}\) & capital\\
53 | \({n}\) & labor\\
54 | \({a}\) & productivity\\
55 | \({r}\) & interest rate\\
56 | \({w}\) & wage\\
57 | \({i}\) & investment\\
58 | \({\varepsilon}\) & TFP shock\\
59 | \bottomrule%
60 | \end{longtable}
61 | \end{center}
62 | \end{minipage}%
63 | \begin{minipage}{.65\linewidth}
64 | \begin{center}
65 | \begin{longtable}{ccc}
66 | \caption{Parameter Values\label{tbl:RBC.Parameters}}\\%
67 | \toprule%
68 | \multicolumn{1}{c}{\textbf{Parameter}} &
69 | \multicolumn{1}{c}{\textbf{Value}} &
70 | \multicolumn{1}{c}{\textbf{Description}}\\%
71 | \midrule%
72 | \endfirsthead%
73 | \multicolumn{3}{c}{{\tablename} \thetable{} {--} Continued}\\%
74 | \midrule%
75 | \multicolumn{1}{c}{\textbf{Parameter}} &
76 | \multicolumn{1}{c}{\textbf{Value}} &
77 | \multicolumn{1}{c}{\textbf{Description}}\\%
78 | \midrule%
79 | \endhead%
80 | \({\beta}\) & 0.990 & discount factor\\
81 | \({\delta}\) & 0.025 & depreciation rate\\
82 | \({\gamma}\) & 1.000 & consumption utility weight\\
83 | \({\psi}\) & 1.600 & labor disutility weight\\
84 | \({\alpha}\) & 0.350 & elasticity of capital\\
85 | \({\rho}\) & 0.900 & persistence technology\\
86 | \(A\) & 1 & normalization\\
87 | \bottomrule%
88 | \end{longtable}
89 | \end{center}
90 | \end{minipage}
--------------------------------------------------------------------------------
/exercises/rbc_steady_matlab.tex:
--------------------------------------------------------------------------------
1 | \section[RBC model: steady-state in MATLAB]{RBC model: steady-state in MATLAB\label{ex:RBCModelSteadyMATLAB}}
2 | Consider the basic Real Business Cycle (RBC) model with leisure and log utility function.
3 | The dynamic model equations are given in Table~\ref{tbl:RBC.Model},
4 | the variable description in Table~\ref{tbl:RBC.Variables},
5 | and the description and calibration of parameters in Table~\ref{tbl:RBC.Parameters}.
6 |
7 | \begin{enumerate}
8 |
9 | \item
10 | Create a Dynare mod file for this model and use a \texttt{steady\_state\_model} block to compute the steady-state.
11 | Store the computed steady-state into a variable \texttt{stst\_dyn}.
12 | Evaluate the static file at the steady-state and store your result into a variable \texttt{resid\_dyn}.
13 | Compute the sum of squared residuals of \texttt{resid\_dyn} and store your result into a variable \texttt{ssq\_dyn}.
14 |
15 | \item
16 | Preprocess the model using the function \texttt{preprocessing\_matlab\_rbc.m} created in a previous exercise.
17 |
18 | \item
19 | Put the values for the parameters given in Table~\ref{tbl:RBC.Parameters} into a vector \texttt{MODEL.params}.
20 |
21 | \item
22 | Create two function handles:
23 | \begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize]
24 | exo_vars = 0;
25 | obj = @(xparam) rbc_static_resid(xparam,exo_vars,MODEL.params) ;
26 | obj_ssq = @(xparam) sum(rbc_static_resid(xparam,exo_vars,MODEL.params).^2);
27 | \end{lstlisting}
28 |
29 | \item
30 | Provide initial guess values for the steady-state of all endogenous variables in a vector called \texttt{xparam0}.
31 | Also create two vectors \texttt{LB} and \texttt{UB} with a lower and upper bound for the variables.
32 |
33 | \item
34 | Minimize either \texttt{obj} or \texttt{obj\_ssq} with different numerical optimization algorithms.
35 | You might want to have a look into
36 | \texttt{fsolve}, \texttt{lsqnonlin}, \texttt{fminunc}, \texttt{fminsearch}, \texttt{fmincon}, \texttt{simulannealbnd} and \texttt{patternsearch}.
37 |
38 | \item
39 | Compare the computed steady-state values, the residuals of the static model equations and the sum of squared residuals.
40 |
41 | \item
42 | Redo the exercise, but now randomize your starting values
43 | by drawing them uniformly given the lower and upper bounds.
44 | That is, use the following code snippet:
45 | \begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize]
46 | randomize_initial_values = true; % set to true to randomize initial values
47 | if randomize_initial_values
48 | no_good = 1;
49 | while no_good
50 | xparam0 = LB + (UB-LB).*rand(length(xparam0),1);
51 | if all(~isnan(obj(xparam0)))
52 | no_good = 0;
53 | end
54 | end
55 | end
56 | \end{lstlisting}
57 | \end{enumerate}
58 |
59 | \newpage
60 | \input{exercises/rbc_model_description_short.tex}
61 |
62 |
63 | \begin{solution}\textbf{Solution to \nameref{ex:RBCModelSteadyMATLAB}}
64 | \ifDisplaySolutions%
65 | \input{exercises/rbc_steady_matlab_solution.tex}
66 | \fi
67 | \newpage
68 | \end{solution}
--------------------------------------------------------------------------------
/exercises/rbc_steady_matlab_solution.tex:
--------------------------------------------------------------------------------
1 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/steadystateRBC.m}
--------------------------------------------------------------------------------
/exercises/simulations_deterministic_vs_stochastic.tex:
--------------------------------------------------------------------------------
1 | \section[Deterministic vs stochastic simulations]{Deterministic vs stochastic simulations\label{ex:SimulationsDeterministicStochastic}}
2 | What is the difference between deterministic and stochastic simulations of DSGE models?
3 | In other words, what is the difference between using \texttt{perfect\_foresight\_solver} or \texttt{stoch\_simul} in Dynare?
4 |
5 | \paragraph{Readings}
6 | \begin{itemize}
7 | \item \textcite{Mutschler_2023_UnderstandingDeterministicSimulations}
8 | \end{itemize}
9 |
10 | \begin{solution}\textbf{Solution to \nameref{ex:SimulationsDeterministicStochastic}}
11 | \ifDisplaySolutions%
12 | \input{exercises/simulations_deterministic_vs_stochastic_solution.tex}
13 | \fi
14 | \newpage
15 | \end{solution}
--------------------------------------------------------------------------------
/exercises/simulations_deterministic_vs_stochastic_solution.tex:
--------------------------------------------------------------------------------
1 | The key difference between stochastic and deterministic models stems from the role of uncertainty.
2 | In a deterministic world we have perfect knowledge about all future events including policy actions.
3 | Given some initial data we can derive optimal trajectories
4 | leading to a steady-state which generates the highest outcome, e.g.\ total utility flows.
5 | Contrary to that, in a stochastic setting there is always some randomness involved.
6 | That is, the agents do not know if or when a shock will hit the economy.
7 | They do, however, build (mathematical) expectations because the probability distribution of those shocks is known to the agents.
8 |
9 | \begin{itemize}
10 | \item
11 | Consequentially deterministic models can be used if an occurrence of an innovation in the future is completely certain and predictable,
12 | independent of the duration the shock takes place.
13 | The corresponding so-called \emph{deterministic} simulation provides us with a good impression about the propagation of this shock.
14 | The \emph{unknowns} that we search for are the trajectories of the variables given the model equations,
15 | not a recursive decision role aka policy function.
16 | We typically use deterministic simulations to study changes in taxes
17 | or the introduction of a new currency, etc.
18 | Also, when studying transition dynamics from one steady-state to another one deterministic simulations are typically used.
19 | Particularly, when we want to take all nonlinearities of the model into account,
20 | as we do not approximate a policy function or a decision rule.
21 | Now given the nature of perfect foresight,
22 | there is no uncertainty in the model except when a shock hits on impact (in period 0).
23 | This is important to keep in mind when studying the effects of news shocks or anticipated shocks,
24 | i.e.\ shocks that are announced on impact, but materialize later.
25 | Only the announcement is a surprise,
26 | everything else is known with certainty.
27 |
28 | \item
29 | Stochastic simulations rely on the probability distribution of the shocks,
30 | i.e.\ the exact value and timing of shocks is not known,
31 | but that they \emph{might} happen and agents do form expectations about that knowing only the distribution of the shocks.
32 | Such models are in a sense more realistic as the future is uncertain
33 | and agents make probability statements about their decision.
34 | Stochastic simulations are useful to study transmission mechanisms of stochastic shocks (impulse-response analysis),
35 | how important is the variability of shocks for the variance of the variables (variance decomposition),
36 | and also to estimate model parameters with data.
37 | The unknowns that we search for are the so-called \emph{policy functions or decision rules} of the agents,
38 | that describe optimal recursive behavior given the current state of the economy and the current realization of shocks.
39 | There is a downside to use stochastic simulations
40 | as we need to find the policy function or approximate it numerically.
41 |
42 | \end{itemize}
--------------------------------------------------------------------------------
/exercises_1.tex:
--------------------------------------------------------------------------------
1 | % !TEX root = exercises_1.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{exercises_1_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2025\\~\\Exercise Sheet 1}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/exercises_1.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{exercises_1_solution}[exercises_1_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/computational_macroeconomics_scope.tex}\newpage
18 | \input{exercises/programming_languages.tex}\newpage
19 | \input{exercises/matlab_quick_tour.tex}\newpage
20 | \input{exercises/arma_simulation.tex}\newpage
21 | \input{exercises/gitkraken_quick_tour.tex}\newpage
22 | \printbibliography%
23 | \newpage
24 | \appendix
25 | \section{Exam template files for \LaTeX}
26 | \lstinputlisting[language=tex,frame=single,title=\lstname,breaklines=true,breakatwhitespace=false,basicstyle=\scriptsize\mlttfamily]{progs/latex/templateExamSolution.tex}
27 | \lstinputlisting[language=tex,frame=single,title=\lstname,breaklines=false,breakatwhitespace=false,basicstyle=\scriptsize\mlttfamily]{progs/latex/templateExamBiblio.bib}
28 | \lstinputlisting[style=Matlab-editor,basicstyle=\footnotesize\mlttfamily,title=\lstname]{progs/matlab/templateMatlabExample.m}
29 |
30 |
31 | \Closesolutionfile{exercises_1_solution}
32 | \ifDisplaySolutions%
33 | \newpage
34 | \section{Solutions}
35 | \input{exercises_1_solution}
36 | \fi
37 | \end{document}
--------------------------------------------------------------------------------
/exercises_2.tex:
--------------------------------------------------------------------------------
1 | % !TEX root = exercises_2.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{exercises_2_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2025\\~\\Exercise Sheet 2}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/exercises_2.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{exercises_2_solution}[exercises_2_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/rbc_model.tex}\newpage
18 | \input{exercises/baxter_king_preprocess_steady.tex}\newpage
19 | \input{exercises/case_study_baxter_king_figure2.tex}\newpage
20 | \printbibliography%
21 | \newpage
22 |
23 | \Closesolutionfile{exercises_2_solution}
24 | \ifDisplaySolutions%
25 | \newpage
26 | \appendix
27 | \section{Solutions}
28 | \input{exercises_2_solution}
29 | \fi
30 | \end{document}
--------------------------------------------------------------------------------
/exercises_3.tex:
--------------------------------------------------------------------------------
1 | % !TEX root = exercises_3.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{exercises_3_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2025\\~\\Exercise Sheet 3}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/exercises_3.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{exercises_3_solution}[exercises_3_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/case_study_baxter_king_figure3.tex}\newpage
18 | \input{exercises/matlab_symbolic.tex}\newpage
19 | \input{exercises/matrix_algebra.tex}\newpage
20 | \input{exercises/preprocess_matlab_rbc.tex}\newpage
21 |
22 | \appendix
23 | \section{writeOut.m\label{app:writeOut}}
24 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/matlab/writeOut.m}
25 |
26 | \printbibliography%
27 | \newpage
28 |
29 | \Closesolutionfile{exercises_3_solution}
30 | \ifDisplaySolutions%
31 | \newpage
32 | \appendix
33 | \section{Solutions}
34 | \input{exercises_3_solution}
35 | \fi
36 | \end{document}
--------------------------------------------------------------------------------
/exercises_4.tex:
--------------------------------------------------------------------------------
1 | % !TEX root = exercises_4.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{exercises_4_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2025\\~\\Exercise Sheet 4}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/exercises_4.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{exercises_4_solution}[exercises_4_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/nk_model_algebra.tex}\newpage
18 | \input{exercises/nk_preprocess_steady.tex}\newpage
19 | \printbibliography%
20 | \newpage
21 |
22 | \Closesolutionfile{exercises_4_solution}
23 | \ifDisplaySolutions%
24 | \newpage
25 | \appendix
26 | \section{Solutions}
27 | \input{exercises_4_solution}
28 | \fi
29 | \end{document}
--------------------------------------------------------------------------------
/exercises_5.tex:
--------------------------------------------------------------------------------
1 | % !TEX root = exercises_5.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{exercises_5_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2025\\~\\Exercise Sheet 5}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.1\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/exercises_5.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{exercises_5_solution}[exercises_5_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/numerical_optimization.tex}\newpage
18 | \input{exercises/rbc_steady_matlab.tex}\newpage
19 | \input{exercises/simulations_deterministic_vs_stochastic.tex}\newpage
20 |
21 | %\printbibliography%
22 | \newpage
23 |
24 | \Closesolutionfile{exercises_5_solution}
25 | \ifDisplaySolutions%
26 | \newpage
27 | \appendix
28 | \section{Solutions}
29 | \input{exercises_5_solution}
30 | \fi
31 | \end{document}
--------------------------------------------------------------------------------
/plots/SimulatedTrajectory_x.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/plots/SimulatedTrajectory_x.pdf
--------------------------------------------------------------------------------
/progs/dynare/Brock_Mirman.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % computes the first-order perturbation solution, impulse-response function
3 | % and simulated data in the Brock and Mirman (1972) model
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: June 13, 2023
7 | % =========================================================================
8 | var c a k;
9 | varexo eps_a;
10 | parameters ALPHA BETA RHO;
11 |
12 | ALPHA = 0.3;
13 | BETA = 0.96;
14 | RHO = 0.5;
15 | SIG = 0.2;
16 |
17 | model;
18 | c^(-1) = ALPHA*BETA*c(+1)^(-1)*a(+1)*k^(ALPHA-1);
19 | k = a*k(-1)^ALPHA - c;
20 | log(a) = RHO*log(a(-1)) + eps_a;
21 | end;
22 |
23 | steady_state_model;
24 | a = 1;
25 | k = (ALPHA*BETA*a)^(1/(1-ALPHA));
26 | c = a*k^ALPHA-k;
27 | end;
28 | steady;
29 |
30 | shocks;
31 | var eps_a = SIG^2;
32 | end;
33 | stoch_simul(order=1,irf=30,periods=200);
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_identif_bk.mod:
--------------------------------------------------------------------------------
1 | % This file implements the stationary nonlinear model equations of
2 | % An and Schorfheide (2007, Econometric Reviews)
3 | % =========================================================================
4 | % Willi Mutschler (willi@mutschler.eu)
5 | % Version: June 13, 2023
6 | % =========================================================================
7 | var
8 | c ${c}$ (long_name='detrended consumption (C/A)')
9 | z ${z}$ (long_name='shifter to steady-state technology growth')
10 | p ${\pi}$ (long_name='gross inflation rate')
11 | r ${R}$ (long_name='nominal interest rate')
12 | y ${y}$ (long_name='detrended output (Y/A)')
13 | ystar ${y^*}$ (long_name='detrended flex-price output (Y^*/A)')
14 | g ${g}$ (long_name='government consumption process (g = 1/(1-G/Y))')
15 | rstar ${R^*}$ (long_name='auxiliary nominal interest rate for policy rule')
16 | ;
17 |
18 | varexo
19 | epsr ${\varepsilon^R}$ (long_name='monetary policy shock')
20 | epsg ${\varepsilon^g}$ (long_name='government spending shock')
21 | epsz ${\varepsilon^z}$ (long_name='total factor productivity growth shock')
22 | ;
23 |
24 | parameters
25 | TAU ${\tau}$ (long_name='inverse of intertemporal elasticity of subsitution')
26 | KAPPA ${\kappa}$ (long_name='auxiliary parameter, slope of New-Keynesian Phillips curve')
27 | PSI1 ${\psi_1}$ (long_name='Taylor rule sensitivity parameter to inflation deviations')
28 | PSI2 ${\psi_2}$ (long_name='Taylor rule sensitivity parameter to output deviations')
29 | RHOR ${\rho_R}$ (long_name='Taylor rule persistence')
30 | RHOG ${\rho_{g}}$ (long_name='persistence government spending process')
31 | RHOZ ${\rho_z}$ (long_name='persistence TFP growth rate process')
32 | RA ${r_{A}}$ (long_name='annualized steady-state real interest rate')
33 | PA ${\pi^{(A)}}$ (long_name='annualized target inflation rate')
34 | GAMQ ${\gamma^{(Q)}}$ (long_name='quarterly steady-state growth rate of technology')
35 | NU ${\nu}$ (long_name='inverse of elasticity of demand in Dixit Stiglitz aggregator')
36 | GBAR ${\bar{g}}$ (long_name='steady-state government spending process')
37 | ;
38 |
39 |
40 | model;
41 | //auxiliary parameters
42 | #GAMMA = 1+GAMQ/100; //below eq.(38)
43 | #BETA = 1/(1+RA/400); //below eq.(38)
44 | #PBAR = 1+PA/400; //below eq.(38)
45 | #PHI = TAU*(1-NU)/(NU*PBAR^2*KAPPA); //relationship slope of New Keynesian Phillips Curve eq.(32)
46 |
47 | [name='Euler equation']
48 | 1 = BETA * (c(+1)/c)^(-TAU) * 1/(GAMMA*z(+1)) * r/p(+1);
49 | [name='Phillips curve based on Rotemberg price setting and Dixit/Stiglitz aggregator']
50 | 1 = PHI*(p-steady_state(p))*( (1-1/(2*NU))*p + steady_state(p)/(2*NU) )
51 | -PHI*BETA*( (c(+1)/c)^(-TAU)*y(+1)/y*(p(+1)-steady_state(p))*p(+1) )
52 | +1/NU*(1-c^TAU);
53 | [name='market clearing']
54 | y = c + (g-1)/g*y + PHI/2*(p-steady_state(p))^2*y;
55 | [name='monetary policy equation']
56 | r = rstar^(1-RHOR)*r(-1)^RHOR*exp(epsr);
57 | [name='monetary policy feedback rule']
58 | rstar = steady_state(r) * (p/PBAR)^PSI1 * (y/ystar)^PSI2;
59 | [name='technology growth process']
60 | log(z) = RHOZ*log(z(-1)) + epsz;
61 | [name='government spending process']
62 | log(g) = (1-RHOG)*log(GBAR) + RHOG*log(g(-1)) + epsg;
63 | [name='flex-price output']
64 | ystar = (1-NU)^(1/TAU)*g;
65 | end;
66 |
67 | steady_state_model;
68 | z = 1;
69 | p = 1+PA/400;
70 | g = GBAR;
71 | r = (1+GAMQ/100) / (1/(1+RA/400)) * p;
72 | rstar = r;
73 | c = (1-NU)^(1/TAU);
74 | y = g*c;
75 | ystar = y;
76 | YGR = GAMQ;
77 | INFL = PA;
78 | INT = PA + RA + 4*GAMQ;
79 | end;
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_identif_dovish.mod:
--------------------------------------------------------------------------------
1 | % This file computes impulse responses and theoretical moments of the
2 | % stationary nonlinear model equations of An and Schorfheide (2007,
3 | % Econometric Reviews) for a dovish monetary policy rule to showcase
4 | % identification problems when comparing these to a hawkish monetary policy
5 | % rule (see an_schorfheide_identif_hawkish.mod)
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: June 13, 2023
9 | % =========================================================================
10 |
11 | @#include "an_schorfheide_identif_bk.mod"
12 |
13 | % common calibration
14 | TAU = 2;
15 | KAPPA = 0.33;
16 | NU = 0.1;
17 | RHOG = 0.95;
18 | RHOZ = 0.90;
19 | RA = 1;
20 | PA = 3.2;
21 | GAMQ = 0.5;
22 | GBAR = 1/0.85;
23 | SIG2Z = 0.9;
24 | SIG2G = 0.36;
25 |
26 | % dovish Taylor rule (values are taken from Qu and Tkachenko (2012, Table 1, panel (b) \theta_{-9})
27 | PSI1 = 1.043195;
28 | PSI2 = 0.918417;
29 | RHOR = 0.792647;
30 | SIG2R = 0.446783;
31 |
32 | shocks;
33 | var epsr = SIG2R;
34 | var epsz = SIG2Z;
35 | var epsg = SIG2G;
36 | end;
37 |
38 | stoch_simul(order=1);
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_identif_hawkish.mod:
--------------------------------------------------------------------------------
1 | % This file computes impulse responses and theoretical moments of the
2 | % stationary nonlinear model equations of An and Schorfheide (2007,
3 | % Econometric Reviews) for a hawkish monetary policy rule to showcase
4 | % identification problems when comparing these to a dovish monetary policy
5 | % rule (see an_schorfheide_identif_dovish.mod)
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: June 13, 2023
9 | % =========================================================================
10 |
11 | @#include "an_schorfheide_identif_bk.mod"
12 |
13 | % common calibration
14 | TAU = 2;
15 | KAPPA = 0.33;
16 | NU = 0.1;
17 | RHOG = 0.95;
18 | RHOZ = 0.90;
19 | RA = 1;
20 | PA = 3.2;
21 | GAMQ = 0.5;
22 | GBAR = 1/0.85;
23 | SIG2Z = 0.9;
24 | SIG2G = 0.36;
25 |
26 | % hawkish Taylor rule
27 | PSI1 = 1.5;
28 | PSI2 = 0.125;
29 | RHOR = 0.75;
30 | SIG2R = 0.4;
31 |
32 | shocks;
33 | var epsr = SIG2R;
34 | var epsz = SIG2Z;
35 | var epsg = SIG2G;
36 | end;
37 |
38 | stoch_simul(order=1);
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_loglinear.mod:
--------------------------------------------------------------------------------
1 | % This file implements the log-linearized model equations of
2 | % An and Schorfheide (2007, Econometric Reviews)
3 | % =========================================================================
4 | % Willi Mutschler (willi@mutschler.eu)
5 | % Version: June 13, 2023
6 | % =========================================================================
7 |
8 | var
9 | // variables in log dev. from steady-state
10 | chat ${\hat{c}}$ (long_name='detrended consumption (log dev. from steady-state)')
11 | zhat ${\hat{z}}$ (long_name='technology growth (log dev. from steady-state)')
12 | phat ${\hat{\pi}}$ (long_name='inflation rate (log dev. from steady-state)')
13 | rhat ${\hat{R}}$ (long_name='nominal interest rate (log dev. from steady-state)')
14 | yhat ${\hat{y}}$ (long_name='detrended output (log dev. from steady-state)')
15 | ghat ${\hat{g}}$ (long_name='government consumption (log dev. from steady-state)')
16 | // observable variables
17 | YGR ${YGR}$ (long_name='output growth rate (quarter-on-quarter)')
18 | INFL ${INFL}$ (long_name='annualized inflation rate')
19 | INT ${INT}$ (long_name='annualized nominal interest rate')
20 | ;
21 |
22 | varexo
23 | epsr ${\varepsilon^R}$ (long_name='monetary policy shock')
24 | epsg ${\varepsilon^g}$ (long_name='government spending shock')
25 | epsz ${\varepsilon^z}$ (long_name='total factor productivity growth shock')
26 | ;
27 |
28 | parameters
29 | TAU ${\tau}$ (long_name='inverse of intertemporal elasticity of subsitution')
30 | KAPPA ${\kappa}$ (long_name='auxiliary parameter, slope of New-Keynesian Phillips curve')
31 | PSI1 ${\psi_1}$ (long_name='Taylor rule sensitivity parameter to inflation deviations')
32 | PSI2 ${\psi_2}$ (long_name='Taylor rule sensitivity parameter to output deviations')
33 | RHOR ${\rho_R}$ (long_name='Taylor rule persistence')
34 | RHOG ${\rho_{g}}$ (long_name='persistence government spending process')
35 | RHOZ ${\rho_z}$ (long_name='persistence TFP growth rate process')
36 | RA ${r_{A}}$ (long_name='annualized steady-state real interest rate')
37 | PA ${\pi^{(A)}}$ (long_name='annualized target inflation rate')
38 | GAMQ ${\gamma^{(Q)}}$ (long_name='quarterly steady-state growth rate of technology')
39 | NU ${\nu}$ (long_name='inverse of elasticity of demand in Dixit Stiglitz aggregator')
40 | GBAR ${\bar{g}}$ (long_name='steady-state government spending process')
41 | ;
42 |
43 | model;
44 | #BETA = 1/(1+RA/400); //below eq.(38)
45 | [name='New Keynesian IS curve']
46 | yhat = yhat(+1) + ghat - ghat(+1) - 1/TAU*(rhat -phat(+1) - zhat(+1));
47 | [name='New Keynesian Phillips curve']
48 | phat = BETA*phat(+1) + KAPPA*(yhat-ghat);
49 | [name='market clearing']
50 | chat = yhat - ghat;
51 | [name='Taylor rule']
52 | rhat = RHOR*rhat(-1) + (1-RHOR)*PSI1*phat + (1-RHOR)*PSI2*(yhat-ghat) + epsr;
53 | [name='government spending rule']
54 | ghat = RHOG*ghat(-1) + epsg;
55 | [name='total factor productivity growth']
56 | zhat = RHOZ*zhat(-1) + epsz;
57 | [name='output growth (q-on-q)']
58 | YGR = GAMQ + 100*( yhat - yhat(-1) + zhat );
59 | [name='annualized inflation']
60 | INFL = PA + 400*phat;
61 | [name='annualized nominal interest rate']
62 | INT = PA + RA + 4*GAMQ + 400*rhat;
63 | end;
64 |
65 | steady_state_model;
66 | chat=0; zhat=0; phat=0; rhat=0; yhat=0; ghat=0;
67 | YGR = GAMQ;
68 | INFL = PA;
69 | INT = PA + RA + 4*GAMQ;
70 | end;
71 |
72 | @#include "an_schorfheide_params_shocks.inc"
73 | steady;
74 | stoch_simul(order=1,nograph);
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_nonlinear_exp.mod:
--------------------------------------------------------------------------------
1 | % This file implements the exponentially transformed stationary nonlinear
2 | % model equations of An and Schorfheide (2007, Econometric Reviews)
3 | % =========================================================================
4 | % Willi Mutschler (willi@mutschler.eu)
5 | % Version: June 13, 2023
6 | % =========================================================================
7 |
8 | var
9 | chat ${\hat{c}}$ (long_name='detrended consumption (log dev. from steady-state)')
10 | zhat ${\hat{z}}$ (long_name='technology growth (log dev. from steady-state)')
11 | phat ${\hat{\pi}}$ (long_name='inflation rate (log dev. from steady-state)')
12 | rhat ${\hat{R}}$ (long_name='nominal interest rate (log dev. from steady-state)')
13 | yhat ${\hat{y}}$ (long_name='detrended output (log dev. from steady-state)')
14 | ghat ${\hat{g}}$ (long_name='government consumption (log dev. from steady-state)')
15 | // observable variables
16 | YGR ${YGR}$ (long_name='output growth rate (quarter-on-quarter)')
17 | INFL ${INFL}$ (long_name='annualized inflation rate')
18 | INT ${INT}$ (long_name='annualized nominal interest rate')
19 | ;
20 |
21 | varexo
22 | epsr ${\varepsilon^R}$ (long_name='monetary policy shock')
23 | epsg ${\varepsilon^g}$ (long_name='government spending shock')
24 | epsz ${\varepsilon^z}$ (long_name='total factor productivity growth shock')
25 | ;
26 |
27 | parameters
28 | TAU ${\tau}$ (long_name='inverse of intertemporal elasticity of subsitution')
29 | KAPPA ${\kappa}$ (long_name='auxiliary parameter, slope of New-Keynesian Phillips curve')
30 | PSI1 ${\psi_1}$ (long_name='Taylor rule sensitivity parameter to inflation deviations')
31 | PSI2 ${\psi_2}$ (long_name='Taylor rule sensitivity parameter to output deviations')
32 | RHOR ${\rho_R}$ (long_name='Taylor rule persistence')
33 | RHOG ${\rho_{g}}$ (long_name='persistence government spending process')
34 | RHOZ ${\rho_z}$ (long_name='persistence TFP growth rate process')
35 | RA ${r_{A}}$ (long_name='annualized steady-state real interest rate')
36 | PA ${\pi^{(A)}}$ (long_name='annualized target inflation rate')
37 | GAMQ ${\gamma^{(Q)}}$ (long_name='quarterly steady-state growth rate of technology')
38 | NU ${\nu}$ (long_name='inverse of elasticity of demand in Dixit Stiglitz aggregator')
39 | GBAR ${\bar{g}}$ (long_name='steady-state government spending process')
40 | ;
41 |
42 | model;
43 | #BETA = 1/(1+RA/400); //below eq.(38)
44 | #PBAR = 1+PA/400; //below eq.(38)
45 | #PHI = TAU*(1-NU)/(NU*PBAR^2*KAPPA); //relationship slope of New Keynesian Phillips Curve eq.(32)
46 | // auxiliary steady-state values
47 | #PSS = PBAR;
48 | #GSS = GBAR;
49 |
50 | [name='Euler equation']
51 | 1 = exp( -TAU*chat(+1) + TAU*chat + rhat - zhat(+1) - phat(+1));
52 | [name='Phillips curve based on Rotemberg price setting and Dixit/Stiglitz aggregator']
53 | 0 = ( exp(phat)-1 ) * ( (1-1/(2*NU)) * exp(phat) + 1/(2*NU) )
54 | - BETA*( ( exp(phat(+1))-1 ) * exp( -TAU*chat(+1) + TAU*chat + yhat(+1) - yhat + phat(+1) ) )
55 | + (1-NU)/(PHI*PSS^2*NU) * ( 1-exp(TAU*chat) );
56 | [name='market clearing']
57 | exp(chat-yhat) = exp(-ghat) - PHI*PSS^2*GSS/2 * (exp(phat)-1)^2;
58 | [name='monetary policy equation and feedback rule']
59 | rhat = RHOR*rhat(-1) + (1-RHOR)*PSI1*phat + (1-RHOR)*PSI2*(yhat-ghat) + epsr;
60 | [name='technology growth process']
61 | zhat = RHOZ*zhat(-1) + epsz;
62 | [name='government spending process']
63 | ghat = RHOG*ghat(-1) + epsg;
64 |
65 | [name='output growth (q-on-q)']
66 | YGR = GAMQ + 100*( yhat - yhat(-1) + zhat );
67 | [name='annualized inflation']
68 | INFL = PA + 400*phat;
69 | [name='annualized nominal interest rate']
70 | INT = PA + RA + 4*GAMQ + 400*rhat;
71 | end;
72 |
73 | steady_state_model;
74 | chat=0; zhat=0; phat=0; rhat=0; yhat=0; ghat=0;
75 | YGR = GAMQ;
76 | INFL = PA;
77 | INT = PA + RA + 4*GAMQ;
78 | end;
79 |
80 | @#include "an_schorfheide_params_shocks.inc"
81 | steady;
82 | stoch_simul(order=1,nograph);
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_params_shocks.inc:
--------------------------------------------------------------------------------
1 | % This file provides the calibration of parameters and shock variances
2 | % of the model in An and Schorfheide (2007, Econometric Reviews) according
3 | % to Table (3, DGP D_1(Q))
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: June 13, 2023
7 | % =========================================================================
8 |
9 | TAU = 2.00;
10 | KAPPA = 0.33;
11 | PSI1 = 1.50;
12 | PSI2 = 0.125;
13 | RHOR = 0.75;
14 | RHOG = 0.95;
15 | RHOZ = 0.90;
16 | RA = 1.00;
17 | PA = 3.20;
18 | GAMQ = 0.55;
19 | NU = 0.10;
20 | GBAR = 1/0.85;
21 |
22 | shocks;
23 | var epsr; stderr 0.20/100;
24 | var epsg; stderr 0.60/100;
25 | var epsz; stderr 0.30/100;
26 | end;
--------------------------------------------------------------------------------
/progs/dynare/an_schorfheide_sensitivity_bk.mod:
--------------------------------------------------------------------------------
1 | % This file illustrates the Taylor principle by using Dynare's sensitivity
2 | % toolbox on the nonlinear model equations of An and Schorfheide (2007,
3 | % Econometric Reviews)
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: June 13, 2023
7 | % =========================================================================
8 | @#include "an_schorfheide_identif_bk.mod"
9 |
10 | TAU = 2;
11 | KAPPA = 0.33;
12 | NU = 0.1;
13 | RHOG = 0.95;
14 | RHOZ = 0.90;
15 | RA = 1;
16 | PA = 3.2;
17 | GAMQ = 0.5;
18 | GBAR = 1/0.85;
19 | SIG2Z = 0.9;
20 | SIG2G = 0.36;
21 | PSI1 = 1.5;
22 | PSI2 = 0.125;
23 | RHOR = 0.75;
24 | SIG2R = 0.4;
25 |
26 | shocks;
27 | var epsr = SIG2R;
28 | var epsz = SIG2Z;
29 | var epsg = SIG2G;
30 | end;
31 |
32 | %specify parameters for which to map sensitivity
33 | estimated_params;
34 | PSI1, uniform_pdf,,, 0,6; %draw uniformly from 0 to 6
35 | PSI2, uniform_pdf,,,-1,6; %draw uniformly from -1 to 6
36 | RHOR, uniform_pdf,,,-1,1; %draw uniformly from -1 to 1
37 | end;
38 | varobs y p r; % for analysis of BK conditions, it does not matter which variables are observed
39 | dynare_sensitivity(prior_range=0,stab=1,nsam=2000);
--------------------------------------------------------------------------------
/progs/dynare/arma11.mod:
--------------------------------------------------------------------------------
1 | % This file simulates an ARMA(1,1) model with Dynare and showcases
2 | % identification issue whenever coefficients are equal to each other
3 | % =========================================================================
4 | % Willi Mutschler (willi@mutschler.eu)
5 | % Version: Apri 25, 2024
6 | % =========================================================================
7 |
8 | % declare variables and parameters
9 | var x;
10 | varexo e;
11 | parameters THETA PHI;
12 |
13 | % declare model equations
14 | model;
15 | x - THETA*x(-1) = e - PHI*e(-1);
16 | end;
17 |
18 | % steady-state values for endogenous variables
19 | steady_state_model;
20 | x = 0;
21 | end;
22 |
23 | % calibration (note that if THETA=PHI we always get x=e)
24 | THETA = 0.4;
25 | PHI = 0.4;
26 |
27 | % variance of normally distributed shock
28 | shocks;
29 | var e = 1^2;
30 | end;
31 |
32 | % computations
33 | steady;
34 | stoch_simul(order=1,periods=200,irf=0);
35 |
36 | % plots
37 | options_.smpl = [51 150]; % select a subsample to plot
38 | options_.rplottype = 2; % possible values are 0, 1, 2
39 | rplot x e; % quick way to plot simulations in Dynare
40 | if THETA == PHI
41 | sgtitle('SERIES ARE THE SAME BECAUSE (THETA = PHI)')
42 | end
--------------------------------------------------------------------------------
/progs/dynare/nk2co_perm_infltarget_surprise.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Two-country New-Keynesian DSGE model with Zero-Lower-Bound on interest
3 | % rates and endogenous discount factor
4 | %
5 | % Deterministic Simulation:
6 | % inflation target increases permanently from 0% to 2% annually (0.5% quarterly)
7 | % =========================================================================
8 | % Willi Mutschler (willi@mutschler.eu)
9 | % Version: May 10, 2023
10 | % =========================================================================
11 |
12 | @#include "nk2co_common.mod"
13 |
14 | PIH = 1.005;
15 | endval;
16 | piH = 1.005;
17 | end;
18 | steady;
19 |
20 | perfect_foresight_setup(periods=500);
21 | perfect_foresight_solver;
22 |
23 | nk2co_do_plots('Increase in Inflation Target',40,oo_,M_);
--------------------------------------------------------------------------------
/progs/dynare/nk2co_perm_tax_announced.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Two-country New-Keynesian DSGE model with Zero-Lower-Bound on interest
3 | % rates and endogenous discount factor
4 | %
5 | % Deterministic Simulation:
6 | % pre-announced permanent tax increase from 0% to 10% in t=5,...
7 | % =========================================================================
8 | % Willi Mutschler (willi@mutschler.eu)
9 | % Version: May 10, 2023
10 | % =========================================================================
11 |
12 | @#include "nk2co_common.mod"
13 | taxval = 0.1; % increase in tax rate
14 |
15 | initval;
16 | eps_tauH = 0;
17 | end;
18 | steady;
19 | ys0 = oo_.steady_state; % store initial steady-state
20 |
21 | endval;
22 | eps_tauH = taxval;
23 | end;
24 | steady;
25 | ys1 = oo_.steady_state; % store terminal steady-state
26 |
27 | shocks;
28 | var eps_tauH;
29 | periods 1:5; % first 5 periods no tax increase
30 | values 0;
31 | end;
32 |
33 | perfect_foresight_setup(periods=100); % prepare perfect foresight simulation
34 | endo_simul_init = oo_.endo_simul; % store initial value matrix for endogenous
35 | exo_simul_init = oo_.exo_simul; % store initial value matrix for exogenous
36 |
37 | perfect_foresight_solver; % run solver
38 |
39 | nk2co_do_plots('Pre-Announced Permanent Tax Increase in HOME',40,oo_,M_);
--------------------------------------------------------------------------------
/progs/dynare/nk2co_temp_monpol_announced.mod:
--------------------------------------------------------------------------------
1 | % Two-country New-Keynesian DSGE model with Zero-Lower-Bound on interest
2 | % rates and endogenous discount factor
3 | %
4 | % Deterministic Simulation:
5 | % pre-announced sequence of temporary monetary policy shocks
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: May 10, 2023
9 | % =========================================================================
10 |
11 | @#include "nk2co_common.mod"
12 |
13 | shocks;
14 | var eps_rH;
15 | periods 4, 5:8;
16 | values 0.0075, 0.0025;
17 | end;
18 |
19 | perfect_foresight_setup(periods=100);
20 | perfect_foresight_solver;
21 |
22 | nk2co_do_plots('Pre-Announced Monetary Policy Shock in HOME',21,oo_,M_);
--------------------------------------------------------------------------------
/progs/dynare/nk2co_temp_monpol_surprise.mod:
--------------------------------------------------------------------------------
1 | % Two-country New-Keynesian DSGE model with Zero-Lower-Bound on interest
2 | % rates and endogenous discount factor
3 | %
4 | % Deterministic Simulation:
5 | % temporary monetary policy shock surprise
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: May 10, 2023
9 | % =========================================================================
10 |
11 | @#include "nk2co_common.mod"
12 |
13 | shocks;
14 | var eps_rH;
15 | periods 1;
16 | values 0.0015; % 15 basis points
17 | end;
18 |
19 | perfect_foresight_setup(periods=100);
20 | perfect_foresight_solver;
21 |
22 | nk2co_do_plots('Temporary Monetary Policy Shock in HOME',21,oo_,M_);
--------------------------------------------------------------------------------
/progs/dynare/nk_illustrate_perturbation.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % illustration of first-order perturbation, compares Dynare's solution
3 | % with manually computing it using:
4 | % - perturbation_solver_LRE:
5 | % based on full Jacobian without distinguishing variables types,
6 | % illustrative use of linear algebra functions
7 | % - perturbation_solver_dynare_order1:
8 | % illustrates exactly what Dynare does: distinguishing variable types,
9 | % getting rid of static variables, using efficient linear algebra functions
10 | % =========================================================================
11 | % Willi Mutschler (willi@mutschler.eu)
12 | % Version: June 13, 2023
13 | % =========================================================================
14 |
15 | @#include "nk.mod"
16 | shocks;
17 | var eps_a = 0.003^2;
18 | var eps_nu = 0.010^2;
19 | var eps_zeta = 0.005^2;
20 | end;
21 |
22 | stoch_simul(order=1,irf=30,periods=200);
23 |
24 | addpath('../matlab'); % add path that contains perturbation solver functions
25 |
26 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
27 | fprintf('\n Illustration Perturbation Solver: Linear Rational Expectations Model\n\n')
28 | [ghx_LRE, ghu_LRE, info_LRE] = perturbation_solver_LRE(M_, oo_, [], true);
29 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
30 |
31 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
32 | fprintf('\n Illustration Perturbation Solver: What Dynare Does (keeping static variables)\n\n')
33 | [ghx_dyn0, ghu_dyn0, info_dyn0] = perturbation_solver_dynare_order1(M_, oo_, [], true, true);
34 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
35 |
36 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
37 | fprintf('\n Illustration Perturbation Solver: What Dynare Does (getting rid of static variables)\n\n')
38 | [ghx_dyn, ghu_dyn, info_dyn] = perturbation_solver_dynare_order1(M_, oo_, [], false, true);
39 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
40 |
41 | rmpath('../matlab');
--------------------------------------------------------------------------------
/progs/dynare/nk_irfs_det.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % illustration of impulse response functions computed by deterministic
3 | % simulations with perfect_foresight_solver in the baseline New Keynesian
4 | % model with monopolistic competition, Calvo price frictions, and
5 | % investment adjustment costs.
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: June 13, 2023
9 | % =========================================================================
10 | @#include "nk.mod"
11 |
12 | %----------------------------------------------------------------
13 | % unit shock to technology
14 | %---------------------------------------------------------------
15 | steady;% start at steady-state
16 | shocks;
17 | var eps_a; periods 1; values 1;
18 | var eps_zeta; periods 1; values 0;
19 | var eps_nu; periods 1; values 0;
20 | end;
21 | perfect_foresight_setup(periods=50);
22 | perfect_foresight_solver(maxit=100);
23 | tit = 'eps_a';
24 | nk_irfs_det_do_plots;
25 | sgtitle('unit shock to technology');
26 |
27 | %----------------------------------------------------------------
28 | % contractionary monetary policy shock of 25 basis points
29 | %---------------------------------------------------------------
30 | steady;% start at steady-state
31 | shocks;
32 | var eps_a; periods 1; values 0;
33 | var eps_zeta; periods 1; values 0;
34 | var eps_nu; periods 1; values 0.25;
35 | end;
36 | perfect_foresight_setup(periods=50);
37 | perfect_foresight_solver(maxit=100);
38 | tit = 'eps_nu';
39 | nk_irfs_det_do_plots;
40 | sgtitle('contractionary monetary policy shock of 25 basis points')
41 |
42 | %----------------------------------------------------------------
43 | % initial preference shifter shock is set to -0.5 percentage points
44 | %---------------------------------------------------------------
45 | steady;% start at steady-state
46 | shocks;
47 | var eps_a; periods 1; values 0;
48 | var eps_zeta; periods 1; values 0.5; % note that in the mod file the sign in front of eps z is a minus
49 | var eps_nu; periods 1; values 0;
50 | end;
51 | perfect_foresight_setup(periods=50);
52 | perfect_foresight_solver(maxit=100);
53 | tit = 'eps_zeta';
54 | nk_irfs_det_do_plots;
55 | sgtitle('initial preference shifter shock is set to -0.5 percentage points');
--------------------------------------------------------------------------------
/progs/dynare/nk_irfs_det_do_plots.m:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % plotting routines for impulse response functions computed by deterministic
3 | % simulations with perfect_foresight_solver in the baseline New Keynesian
4 | % model with monopolistic competition, Calvo price frictions, and
5 | % investment adjustment costs.
6 | % =========================================================================
7 | options_.irf = 30;
8 | PLOTVARS = ["hat_y" "hat_c" "hat_iv" "hat_h" "hat_k" "hat_rnom_ann"...
9 | "hat_w" "hat_rk_ann" "hat_pi_ann" "hat_rreal_ann"...
10 | "hat_mc" "nu" "hat_a" "hat_zeta"];
11 | hh = dyn_figure(options_.nodisplay,'name',['Shock to ' tit]);
12 | x = 0:options_.irf;
13 | plt_nbr = 1;
14 | for j = 1:length(PLOTVARS)
15 | y = oo_.endo_simul(ismember(M_.endo_names,PLOTVARS(j)),3:(options_.irf+3));
16 | if ~iszero(y)
17 | subplot(4,3,plt_nbr);
18 | hold on;
19 | plot(x,y,'linewidth',2);
20 | title(PLOTVARS(j),'Interpreter','none');
21 | grid on;
22 | hold off;
23 | plt_nbr = plt_nbr+1;
24 | end
25 | end
--------------------------------------------------------------------------------
/progs/dynare/nk_irfs_stoch.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % illustration of impulse response functions computed by stochastic
3 | % simulations with stoch_simul in the baseline New Keynesian model with
4 | % monopolistic competition, Calvo price frictions, and investment
5 | % adjustment costs.
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: June 13, 2023
9 | % =========================================================================
10 |
11 | @#include "nk.mod"
12 |
13 | %----------------------------------------------------------------
14 | % shock variances
15 | %---------------------------------------------------------------
16 | shocks;
17 | var eps_a = 1^2; % unit shock to technology
18 | var eps_nu = 0.25^2; % 25 basis points
19 | var eps_zeta = 0.5^2; % initial shock is set to -0.5 percentage points
20 | % note: there needs to be a minus before eps_z!
21 | end;
22 |
23 | %----------------------------------------------------------------
24 | % generate IRFs
25 | %----------------------------------------------------------------
26 | stoch_simul(order=1,irf=30) hat_y hat_c hat_iv
27 | hat_h hat_k hat_rnom_ann
28 | hat_w hat_rk_ann hat_pi_ann
29 | hat_rreal_ann hat_mc nu hat_a hat_zeta;
--------------------------------------------------------------------------------
/progs/dynare/nk_var_typology.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % illustration of different types of variables in the baseline New Keynesian
3 | % model with monopolistic competition, Calvo price frictions, and investment
4 | % adjustment costs.
5 | % illustrates Dynare's model_info command and manually extracting different
6 | % types and groups of variables.
7 | % =========================================================================
8 | % Willi Mutschler (willi@mutschler.eu)
9 | % Version: June 13, 2023
10 | % =========================================================================
11 |
12 | @#include "nk.mod"
13 | model_info;
14 |
15 | % lead_lag_incidence matrix: which variables are used at t-1, t, and t+1
16 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
17 | fprintf('\n M_.lead_lag_incidence matrix: which variables are used at t-1, t, and t+1\n\n')
18 | disp(array2table(M_.lead_lag_incidence,...
19 | 'VariableNames',M_.endo_names,...
20 | 'RowNames',{'t-1','t','t+1'}));
21 | fprintf(' number in M_.lead_lag_incidence corresponds to column in dynamic Jacobian g1\n');
22 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
23 |
24 |
25 | % static variables: appear only at t, but not at t-1 and not at t+1
26 | endo_static_names = M_.endo_names(ismember(transpose(M_.lead_lag_incidence>0), [0 1 0],'rows'));
27 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
28 | fprintf('\n static variables: appear only at t, but not at t-1 and not at t+1\n\n')
29 | disp(endo_static_names')
30 | fprintf(' M_.nstatic = %d\n',M_.nstatic)
31 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
32 |
33 | % purely predetermined variables: appear at t-1 but not at t+1, possibly at t
34 | endo_pred_names = M_.endo_names(ismember(transpose(M_.lead_lag_incidence([1 3],:)>0), [1 0],'rows'));
35 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
36 | fprintf('\n purely predetermined variables: appear at t-1 but not at t+1, possibly at t\n\n')
37 | disp(endo_pred_names');
38 | fprintf(' M_.npred = %d\n',M_.npred)
39 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
40 |
41 | % purely forward looking variables: appear at t+1 but not at t-1, possibly at t
42 | endo_fwrd_names = M_.endo_names(ismember(transpose(M_.lead_lag_incidence([1 3],:)>0), [0 1],'rows'));
43 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
44 | fprintf('\n purely forward looking variables: appear at t+1 but not at t-1, possibly at t\n\n')
45 | disp(endo_fwrd_names');
46 | fprintf(' M_.nfwrd = %d\n',M_.nfwrd)
47 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
48 |
49 | % mixed variables: appear at t-1 and t+1, and possibly at t
50 | endo_mixed_names = M_.endo_names(ismember(transpose(M_.lead_lag_incidence([1 3],:)>0), [1 1],'rows'));
51 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
52 | fprintf('\n mixed variables: appear at t-1 and t+1, and possibly at t\n\n')
53 | disp(endo_mixed_names');
54 | fprintf(' M_.nboth = %d\n',M_.nboth)
55 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
56 |
57 | % state and jumper variables
58 | ystar = strcat(M_.endo_names(M_.lead_lag_incidence(1,:)>0),'_{t-1}');
59 | y0 = strcat(M_.endo_names(M_.lead_lag_incidence(2,:)>0),'_{t}');
60 | ystarstar = strcat(M_.endo_names(M_.lead_lag_incidence(3,:)>0),'_{t+1}');
61 | u0 = strcat(M_.exo_names,'_{t}');
62 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
63 | fprintf('\ny_t: all endogenous variables appear at t\n\n')
64 | disp(y0(:)')
65 | fprintf('\ny^{*}_{t-1}: state variables are predetermined and mixed variables (i.e. endogenous variables that appear at t-1):\n\n')
66 | disp(ystar(:)')
67 | fprintf('\ny^{**}_{t+1}: jumper variables are mixed and forward variables (i.e. endogenous variables that appear at t+1)\n\n')
68 | disp(ystarstar(:)')
69 | fprintf('\nu_t: shocks only appear at t\n\n')
70 | disp(u0(:)')
71 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
72 |
73 | % dynamic variables
74 | dynamic_names = [ystar;y0;ystarstar;u0];
75 | fprintf('%s\n',strjoin(repmat("*",1,100),''))
76 | fprintf('\ndynamic variables are endogenous variables that actually appear and exogenous variables:\n\n z_t = [ y^{*}_{t-1}'' y_t'' y^{**}_{t+1}'' u_t'']'':\n\n')
77 | disp(dynamic_names(:)')
78 | fprintf('\n%s\n\n',strjoin(repmat("*",1,100),''))
79 |
--------------------------------------------------------------------------------
/progs/dynare/rbc.mod:
--------------------------------------------------------------------------------
1 | % computes the steady-state of the RBC model with log utility
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler (willi@mutschler.eu)
4 | % Version: April 26, 2024
5 | % -------------------------------------------------------------------------
6 | var y c k n a r w iv;
7 | varexo eps_a;
8 | parameters BETTA DELT GAMA PSSI ALPH RHOA A;
9 |
10 | model;
11 | GAMA*c^(-1) = BETTA*GAMA*c(+1)^(-1)*(1-DELT+r(+1));
12 | w = - (-PSSI*(1-n)^(-1)) / (GAMA*c^(-1));
13 | k = (1-DELT)*k(-1) + iv;
14 | y = c + iv;
15 | y = a*k(-1)^ALPH*n^(1-ALPH);
16 | w = (1-ALPH)*y/n;
17 | r = ALPH*y/k(-1);
18 | log(a) = (1-RHOA)*log(steady_state(a)) + RHOA*log(a(-1)) + eps_a;
19 | end;
20 |
21 | BETTA=0.99; DELT=0.025; GAMA=1; PSSI=1.6; ALPH=0.35; RHOA=0.9; A=1;
22 |
23 | steady_state_model;
24 | a = A;
25 | r = 1/BETTA+DELT-1;
26 | k_n = ((ALPH*a)/r)^(1/(1-ALPH));
27 | w = (1-ALPH)*a*k_n^ALPH;
28 | iv_n = DELT*k_n;
29 | y_n = a*k_n^ALPH;
30 | c_n = y_n - iv_n;
31 | n = GAMA/PSSI*c_n^(-1)*w/(1+GAMA/PSSI*c_n^(-1)*w);
32 | c = c_n*n; iv = iv_n*n; k = k_n*n; y = y_n*n;
33 | end;
34 | steady;
35 |
36 | % this might help with understanding the M_.lead_lag_incidence matrix
37 | disp(array2table(M_.lead_lag_incidence,...
38 | 'VariableNames',M_.endo_names,'RowNames',{'t-1','t','t+1'}));
39 |
40 | % create steady-state vectors
41 | [I,~] = find(M_.lead_lag_incidence');
42 | y_ss = oo_.steady_state; % steady-state of endogenous variables
43 | zzz_ss = oo_.steady_state(I); % steady-state of dynamic variables
44 | ex_ss = transpose(oo_.exo_steady_state); % steady-state of exogenous variables
45 |
46 | % evaluate dynamic model residuals and Jacobian at steady-state
47 | [dynare_resid, dynare_g1] = feval([M_.fname,'.dynamic'], zzz_ss, ex_ss, M_.params, y_ss, 1);
48 | % evaluate static model residuals and Jacobian at steady-state
49 | [dynare_resid_static, dynare_g1_static] = feval([M_.fname,'.static'], y_ss, ex_ss, M_.params);
50 |
--------------------------------------------------------------------------------
/progs/dynare/rbcCRRA.mod:
--------------------------------------------------------------------------------
1 | % computes the steady-state of the RBC model with CRRA utility using a
2 | % helper function inside the steady_state_model block to numerically
3 | % compute labor in steady-state
4 | % -------------------------------------------------------------------------
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: April 25, 2024
7 | % -------------------------------------------------------------------------
8 |
9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 | % declare variables and parameters %
11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 | var y c k n a rk w iv uc un fn fk;
13 | varexo eps_a;
14 | parameters ALPHA BETA DELTA GAMMA PSI RHOA ETAC ETAL;
15 |
16 | %%%%%%%%%%%%%%%%%%%
17 | % model equations %
18 | %%%%%%%%%%%%%%%%%%%
19 | model;
20 | uc = GAMMA*c^(-ETAC);
21 | un = -PSI*(1-n)^(-ETAL);
22 | fn = (1-ALPHA)*a*(k(-1)/n)^ALPHA;
23 | fk = ALPHA*a*(k(-1)/n)^(ALPHA-1);
24 |
25 | uc = BETA*uc(+1)*(1-DELTA+rk(+1));
26 | w = - un/uc;
27 | w = fn;
28 | rk = fk;
29 | y = a*k(-1)^ALPHA*n^(1-ALPHA);
30 | k = (1-DELTA)*k(-1) + iv;
31 | y = c + iv;
32 | log(a) = RHOA*log(a(-1)) + eps_a;
33 | end;
34 |
35 | %%%%%%%%%%%%%%%%
36 | % steady-state %
37 | %%%%%%%%%%%%%%%%
38 | steady_state_model;
39 | a = 1;
40 | rk = 1/BETA+DELTA-1;
41 | k_n = ((ALPHA*a)/rk)^(1/(1-ALPHA));
42 | w = (1-ALPHA)*a*k_n^ALPHA;
43 | iv_n = DELTA*k_n;
44 | y_n = a*k_n^ALPHA;
45 | c_n = y_n - iv_n;
46 | n0 = 1/3; % initial guess
47 | n = rbcCRRASteadyStateHelperFunction(n0,PSI,ETAL,ETAC,GAMMA,c_n,w);
48 | c = c_n*n;
49 | iv = iv_n*n;
50 | k = k_n*n;
51 | y = y_n*n;
52 | uc = GAMMA*c^(-ETAC);
53 | un = -PSI*(1-n)^(-ETAL);
54 | fn = (1-ALPHA)*a*(k_n)^ALPHA;
55 | fk = ALPHA*a*(k_n)^(ALPHA-1);
56 | end;
57 |
58 | %%%%%%%%%%%%%%%%%%%%%%%%
59 | % calibration (simple) %
60 | %%%%%%%%%%%%%%%%%%%%%%%%
61 | ALPHA = 0.35;
62 | BETA = 0.9901;
63 | DELTA = 0.025;
64 | GAMMA = 1;
65 | PSI = 1.7333;
66 | RHOA = 0.9;
67 | ETAC = 2;
68 | ETAL = 1.5;
69 |
70 | %%%%%%%%%%%%%%%%
71 | % computations %
72 | %%%%%%%%%%%%%%%%
73 | steady;
74 |
--------------------------------------------------------------------------------
/progs/dynare/rbcCRRASteadyStateHelperFunction.m:
--------------------------------------------------------------------------------
1 | function n = rbcCRRASteadyStateHelperFunction(n0,PSI,ETAL,ETAC,GAMMA,c_n,w)
2 | % function n = rbcCRRASteadyStateHelperFunction(n0,PSI,ETAL,ETAC,GAMMA,c_n,w)
3 | % -------------------------------------------------------------------------
4 | % helper function for Dynare's steady_state_model block to compute
5 | % steady-state labor of the RBC model with CRRA utility
6 | % minimizes the residual in the labor market clearing equation
7 | % -------------------------------------------------------------------------
8 | % INPUTS:
9 | % n0 : initial guess for numerical optimizer
10 | % PSI, ETAL, ETAC, GAMMA: model parameters
11 | % c_n, w: already computed steady-state relationships (in steady_state_model block)
12 | % OUTPUTS:
13 | % n : numerically optimized value for steady-state labor
14 | % -------------------------------------------------------------------------
15 | % Willi Mutschler (willi@mutschler.eu)
16 | % Version: April 25, 2024
17 | % -------------------------------------------------------------------------
18 | if ETAC == 1 && ETAL == 1
19 | % closed-form expression
20 | n = GAMMA/PSI*c_n^(-1)*w/(1+GAMMA/PSI*c_n^(-1)*w);
21 | else
22 | % use numerical optimizer
23 | n = fsolve(@(x) w*GAMMA*c_n^(-ETAC) - PSI*(1-x)^(-ETAL)*x^ETAC , n0, optimset('Display','Final','TolX',1e-12,'TolFun',1e-12));
24 | end
--------------------------------------------------------------------------------
/progs/dynare/rbcLogutil.mod:
--------------------------------------------------------------------------------
1 | % computes the steady-state of the RBC model with log utility
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler (willi@mutschler.eu)
4 | % Version: April 26, 2024
5 | % -------------------------------------------------------------------------
6 |
7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 | % declare variables and parameters %
9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 | var y c k n a rk w iv uc un fn fk;
11 | varexo eps_a;
12 | parameters ALPHA BETA DELTA GAMMA PSI RHOA;
13 |
14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 | % calibration of parameters (simple) %
16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17 | % ALPHA = 0.35;
18 | % BETA = 0.9901;
19 | % DELTA = 0.025;
20 | % GAMMA = 1;
21 | % PSI = 1.7333;
22 | % RHOA = 0.9;
23 |
24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 | % calibration of parameters (flipping steady-state analytically) %
26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 | % target values
28 | K_Y = 10; % average capital productivity found in long-run averages of data
29 | IV_Y = 0.25; % average investment to ouput ratio found in long-run averages of data
30 | WN_Y = 0.65; % average share of labor income to total income
31 | N = 1/3; % 8h/24h working time
32 |
33 | % flip steady-state relationships to get parameters in terms of the target values
34 | ALPHA = 1-WN_Y; % labor demand in steady-state combined with Cobb-Douglas production function
35 | DELTA = IV_Y / K_Y; % capital accumulation in steady-state
36 | RK = ALPHA/K_Y; % capital demand in steady-state combined with Cobb-Douglas production function
37 | BETA = 1/(RK - DELTA + 1); % Euler equation in steady-state
38 | GAMMA = 1; % normalize GAMMA and calibrate PSI to get targeted lss
39 | A = 1; % tfp in steady-state
40 | K_N = ((ALPHA*A)/RK)^(1/(1-ALPHA));
41 | K = K_N*N;
42 | Y = K/K_Y;
43 | IV = DELTA*K;
44 | W = (1-ALPHA)*A*K_N^ALPHA;
45 | C = Y-IV;
46 | PSI = GAMMA*(C/N)^(-1)*W*(N/(1-N))^(-1); % flipped steady-state labor equation
47 |
48 | RHOA = 0.9; % does not affect the steady-state
49 |
50 | %%%%%%%%%%%%%%%%%%%
51 | % model equations %
52 | %%%%%%%%%%%%%%%%%%%
53 | model;
54 | uc = GAMMA*c^(-1);
55 | un = -PSI/(1-n);
56 | fn = (1-ALPHA)*a*(k(-1)/n)^ALPHA;
57 | fk = ALPHA*a*(k(-1)/n)^(ALPHA-1);
58 |
59 | uc = BETA*uc(+1)*(1-DELTA+rk(+1));
60 | w = - un/uc;
61 | w = fn;
62 | rk = fk;
63 | y = a*k(-1)^ALPHA*n^(1-ALPHA);
64 | k = (1-DELTA)*k(-1) + iv;
65 | y = c + iv;
66 | log(a) = RHOA*log(a(-1)) + eps_a;
67 | end;
68 |
69 | %%%%%%%%%%%%%%%%
70 | % steady-state %
71 | %%%%%%%%%%%%%%%%
72 | steady_state_model;
73 | a = 1;
74 | rk = 1/BETA+DELTA-1;
75 | K_N = ((ALPHA*a)/rk)^(1/(1-ALPHA));
76 | w = (1-ALPHA)*a*K_N^ALPHA;
77 | IV_N = DELTA*K_N;
78 | Y_N = a*K_N^ALPHA;
79 | C_N = Y_N - IV_N;
80 | n = GAMMA/PSI*C_N^(-1)*w/(1+GAMMA/PSI*C_N^(-1)*w);
81 | c = C_N*n;
82 | iv = IV_N*n;
83 | k = K_N*n;
84 | y = Y_N*n;
85 | uc = GAMMA*c^(-1);
86 | un = -PSI/(1-n);
87 | fn = (1-ALPHA)*a*(k/n)^ALPHA;
88 | fk = ALPHA*a*(k/n)^(ALPHA-1);
89 | end;
90 |
91 | %%%%%%%%%%%%%%%%
92 | % computations %
93 | %%%%%%%%%%%%%%%%
94 | steady;
95 |
96 | shocks;
97 | var eps_a = 1;
98 | end;
99 |
100 | stoch_simul(order=1,irf=30,periods=400) y c k n rk w iv a;
101 |
102 | %%%%%%%%%
103 | % plots %
104 | %%%%%%%%%
105 | figure('name','Simulated data')
106 | sgtitle('Simulated data')
107 | subplot(3,3,1); plot(oo_.endo_simul(ismember(M_.endo_names,'a' ),300:end), 'LineWidth',2); title('Productivity');
108 | subplot(3,3,2); plot(oo_.endo_simul(ismember(M_.endo_names,'y' ),300:end), 'LineWidth',2); title('Output');
109 | subplot(3,3,3); plot(oo_.endo_simul(ismember(M_.endo_names,'c' ),300:end), 'LineWidth',2); title('Consumption');
110 | subplot(3,3,4); plot(oo_.endo_simul(ismember(M_.endo_names,'k' ),300:end), 'LineWidth',2); title('Capital');
111 | subplot(3,3,5); plot(oo_.endo_simul(ismember(M_.endo_names,'iv'),300:end), 'LineWidth',2); title('Investment');
112 | subplot(3,3,6); plot(oo_.endo_simul(ismember(M_.endo_names,'rk'),300:end), 'LineWidth',2); title('Rental rate');
113 | subplot(3,3,7); plot(oo_.endo_simul(ismember(M_.endo_names,'n' ),300:end), 'LineWidth',2); title('Labor');
114 | subplot(3,3,8); plot(oo_.endo_simul(ismember(M_.endo_names,'w' ),300:end), 'LineWidth',2); title('Wage');
--------------------------------------------------------------------------------
/progs/latex/templateExamBiblio.bib:
--------------------------------------------------------------------------------
1 | @article{Aruoba.Fernandez-Villaverde_2015_ComparisonProgrammingLanguages,
2 | title = {A Comparison of Programming Languages in Macroeconomics},
3 | author = {Aruoba, S. Bora{\u g}an and {Fern{\'a}ndez-Villaverde}, Jes{\'u}s},
4 | year = {2015},
5 | journal = {Journal of Economic Dynamics and Control},
6 | volume = {58},
7 | pages = {265--273},
8 | doi = {10.1016/j.jedc.2015.05.009},
9 | abstract = {We solve the stochastic neoclassical growth model, the workhorse of modern macroeconomics, using C++14, Fortran 2008, Java, Julia, Python, Matlab, Mathematica, and R. We implement the same algorithm, value function iteration, in each of the languages. We report the execution times of the codes in a Mac and in a Windows computer and briefly comment on the strengths and weaknesses of each language.},
10 | annotation = {note the Update available at https://www.sas.upenn.edu/{\textasciitilde}jesusfv/Update\_March\_23\_2018.pdf}
11 | }
12 |
13 | @incollection{Christiano.Trabandt.Walentin_2010_DSGEModelsMonetary,
14 | title = {{{DSGE Models}} for {{Monetary Policy Analysis}}},
15 | booktitle = {Handbook of {{Monetary Economics}}},
16 | author = {Christiano, Lawrence J. and Trabandt, Mathias and Walentin, Karl},
17 | editor = {Friedman, Benjamin M. and Woodford, Michael},
18 | year = {2010},
19 | volume = {3},
20 | pages = {285--367},
21 | publisher = {Elsevier},
22 | doi = {10.1016/B978-0-444-53238-1.00007-7},
23 | abstract = {Monetary DSGE models are widely used because they fit the data well and they can be used to address important monetary policy questions. We provide a selective review of these developments. Policy analysis with DSGE models requires using data to assign numerical values to model parameters. The chapter describes and implements Bayesian moment matching and impulse response matching procedures for this purpose.},
24 | isbn = {978-0-444-53470-5}
25 | }
26 |
27 | @book{Heer.Maussner_2024_DynamicGeneralEquilibrium,
28 | title = {Dynamic {{General Equilibrium Modeling}}: {{Computational Methods}} and {{Applications}}},
29 | author = {Heer, Burkhard and Mau{\ss}ner, Alfred},
30 | year = {2024},
31 | series = {Springer {{Texts}} in {{Business}} and {{Economics}}},
32 | publisher = {Springer International Publishing},
33 | address = {Cham},
34 | doi = {10.1007/978-3-031-51681-8},
35 | abstract = {Offers an introduction to the use of numerical methods for solving dynamic general equilibrium models Provides algorithms and program codes on an accompanying website This is the 3rd completely revised and extended edition},
36 | isbn = {978-3-031-51681-8}
37 | }
--------------------------------------------------------------------------------
/progs/matlab/Brock_Mirman_ss.m:
--------------------------------------------------------------------------------
1 | function [SS,PARAMS,error_indicator] = Brock_Mirman_ss(SS,PARAMS,MODEL)
2 | % [SS,PARAMS,error_indicator] = Brock_Mirman_ss(SS,PARAMS,MODEL)
3 | % =========================================================================
4 | % computes the steady-state of the Brock and Mirman (1972) model analytically
5 | % =========================================================================
6 | % INPUTS
7 | % - SS : vector with initial steady-state values in declaration order
8 | % (usually empty, but might be useful for initial values
9 | % or to update endogenous parameters)
10 | % - params : vector with values for the parameters in declaration order
11 | % ----------------------------------------------------------------------
12 | % OUTPUTS
13 | % - SS : vector with computed steady-state values in declaration order
14 | % - params : vector with updated values for the parameters in declaration order
15 | % - error_indicator: 0 if no error when computing the steady-state
16 | % =========================================================================
17 | % Willi Mutschler (willi@mutschler.eu)
18 | % Version: June 12, 2023
19 | % =========================================================================
20 | error_indicator = 0; % initialize no error
21 |
22 | % read-out parameters
23 | ALPHA = MODEL.params(MODEL.param_names=="ALPHA");
24 | BETA = MODEL.params(MODEL.param_names=="BETA");
25 |
26 | % compute steady-state analytically
27 | a = 1;
28 | k = (ALPHA*BETA*a)^(1/(1-ALPHA));
29 | c = a*k^ALPHA-k;
30 |
31 | % write to output structure
32 | SS(MODEL.endo_names=="a",1) = a;
33 | SS(MODEL.endo_names=="k",1) = k;
34 | SS(MODEL.endo_names=="c",1) = c;
35 |
36 | end
--------------------------------------------------------------------------------
/progs/matlab/arma11CompareMATLABWithDynare.m:
--------------------------------------------------------------------------------
1 | % compare simulations of ARMA(1,1) between MATLAB and Dynare
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler (willi@mutschler.eu)
4 | % Version: April 25, 2024
5 | % -------------------------------------------------------------------------
6 |
7 | %% housekeeping
8 | clear global; clearvars; close all; clc;
9 |
10 | %% Dynare simulation
11 | % let's go into the folder with the mod file, run Dynare and return
12 | oldfolder = cd('../dynare'); % go to folder of arma11.mod
13 | dynare arma11
14 | cd(oldfolder); % go back
15 |
16 | % get values from Dynare
17 | % oo_.endo_simul contains simulations, it is of dimension [M_.endo_nbr by options_.periods]
18 | % oo_.exo_simul contains exogenous variables drawn from normal distributions, it is of dimenstion [options_.periods by M_.exo_nbr]
19 | x_from_Dynare = oo_.endo_simul(ismember(M_.endo_names,'x'),:); % row vector
20 | x_from_Dynare = x_from_Dynare(:); % column vector
21 | e_from_Dynare = oo_.exo_simul(:,ismember(M_.exo_names,'e')); % column vector
22 | std_dev = sqrt(M_.Sigma_e); % this is the standard error declared in the shocks block
23 | THETA = M_.params(ismember(M_.param_names,'THETA'));
24 | PHI = M_.params(ismember(M_.param_names,'PHI'));
25 | nobs = options_.periods;
26 |
27 | % get same shock series that was used in Dynare by using the same seed in initialization of random number generators
28 | set_dynare_seed('default');
29 | e_from_MATLAB = std_dev*randn(nobs,1); % randn draws standard normally distributed variables
30 | if isequal(e_from_MATLAB, e_from_Dynare)
31 | disp('shock series are equal');
32 | else
33 | fprintf('shock series are not equal\n') % fprintf is more flexible than disp, the \n prints a new line
34 | end
35 |
36 | %% MATLAB simulation
37 | x_from_MATLAB = arma11Simulate(THETA, PHI, e_from_MATLAB, 0);
38 |
39 | %% comparison
40 | if isequal(x_from_MATLAB, x_from_Dynare)
41 | fprintf('simulated series are the same\n');
42 | else
43 | fprintf('simulated series are not the same, the maximum absolute deviation is %e:\n',norm(x_from_MATLAB - x_from_Dynare,'Inf'));
44 | end
45 |
46 | % CONCLUSION
47 | % even though the difference is very small (1e-16 = 10^(-16)) and from a practical perspective irrelevant,
48 | % it seems that Dynare is doing something different --> we need to understand the order=1 perturbation solver
49 |
50 | %% exploding paths
51 |
52 | % MATLAB simulation
53 | THETA = 1.5;
54 | PHI = 0.4;
55 | x_exploding = arma11Simulate(THETA, PHI, e_from_MATLAB, 0);
56 |
57 | figure('Name','Exploding paths');
58 | subplot(2,1,1);
59 | plot(1:50, x_exploding(1:50), 'LineWidth',2);
60 | subplot(2,1,2);
61 | plot(51:100, x_exploding(51:100), 'LineWidth',2);
62 | sgtitle('exploding $x_t$','Interpreter','latex','FontSize',22);
63 |
64 | % Dynare simulation
65 | oldfolder = cd('../dynare'); % go to folder of arma11.mod
66 | M_.params(ismember(M_.param_names,'THETA')) = 1.5; % change parameter inside Dynare structure
67 | try
68 | % let's re-run the command Dynare uses for simulation without new preprocessing
69 | [info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, {});
70 | catch ME
71 | disp('Error Message:');
72 | disp(ME.message);
73 | end
74 | cd(oldfolder); % go back
75 |
76 | % CONCLUSION
77 | % in MATLAB we can easily generate exploding paths for ARMA(1,1),
78 | % but with Dynare we get an error: "Blanchard & Kahn conditions are not satisfied: no stable equilibrium."
79 | % again: we need to look into the order=1 perturbation solver.
--------------------------------------------------------------------------------
/progs/matlab/arma11Simulate.m:
--------------------------------------------------------------------------------
1 | function x = arma11Simulate(THETA, PHI, e, x0)
2 | % x = arma11Simulate(THETA, PHI, e, x0)
3 | % -------------------------------------------------------------------------
4 | % simulate univariate ARMA(1,1) model
5 | % x(t) - THETA * x(t-1) = e(t) - PHI * e(t-1) where e(t) ~ N(0,1)
6 | % -------------------------------------------------------------------------
7 | % INPUTS
8 | % THETA [scalar] AR coefficient
9 | % PHI [scalar] MA coefficient
10 | % e [nobs by 1] number of observations
11 | % x0 [scalar] initial value for simulation
12 | % -------------------------------------------------------------------------
13 | % Willi Mutschler (willi@mutschler.eu)
14 | % Version: April 25, 2024
15 | % -------------------------------------------------------------------------
16 | nobs = length(e);
17 | x = zeros(nobs, 1); % pre-allocate storage
18 | for t = 1:nobs
19 | if t == 1
20 | x(t) = THETA * x0 + e(t) - PHI * 0;
21 | else
22 | x(t) = THETA * x(t-1) + e(t) - PHI * e(t-1);
23 | end
24 | end
--------------------------------------------------------------------------------
/progs/matlab/dlyapdoubling.m:
--------------------------------------------------------------------------------
1 | function SIGy = dlyapdoubling(A,SIGu)
2 | % SIGy = dlyapdoubling(A,SIGu)
3 | % -------------------------------------------------------------------------
4 | % solves the Lyapunov equation SIGy = A*SIGy*A' + SIGu using the doubling algorithm
5 | % -------------------------------------------------------------------------
6 | % INPUT
7 | % - A : square matrix [n x n] (usually autoregressive or state-space matrix)
8 | % - SIGu : square matrix (n x n] (usually covariance matrix of shocks)
9 | % -------------------------------------------------------------------------
10 | % OUTPUT
11 | % - SIGy: square matrix (usually covariance matrix) [n x n] that solves the Lyapunov equation
12 | % -------------------------------------------------------------------------
13 | % Willi Mutschler, April 26, 2024
14 | % willi@mutschler.eu
15 | % -------------------------------------------------------------------------
16 |
17 | max_iter = 500;
18 | A_old = A;
19 | SIGu_old = SIGu;
20 | SIGy_old = eye(size(A));
21 | difference = .1;
22 | index1 = 1;
23 | tol = 1e-25;
24 | while (difference > tol) && (index1 < max_iter)
25 | SIGy = A_old*SIGy_old*transpose(A_old) + SIGu_old;
26 | difference = max(abs(SIGy(:)-SIGy_old(:)));
27 | SIGu_old = A_old*SIGu_old*transpose(A_old) + SIGu_old;
28 | A_old = A_old*A_old;
29 | SIGy_old = SIGy;
30 | index1 = index1 + 1;
31 | end
32 |
33 | end %function end
--------------------------------------------------------------------------------
/progs/matlab/matrixAlgebraCholesky.m:
--------------------------------------------------------------------------------
1 | % illustration how to decompose a covariance matrix such that
2 | % SIGu = W*SIGe*W'
3 | % using the Cholesky decomposition
4 | % -------------------------------------------------------------------------
5 | % Willi Mutschler, April 26, 2024
6 | % willi@mutschler.eu
7 | % -------------------------------------------------------------------------
8 | clearvars; clc; close all; % housekeeping
9 |
10 | SIGu = [2.25 0 0;
11 | 0 1 0.5;
12 | 0 0.5 0.74];
13 | P = chol(SIGu,'lower');
14 | % Note that P = W*SIGe^(1/2)
15 | SIGe_sqrt = diag(P);
16 | SIGe = diag(SIGe_sqrt.^2);
17 | % Find W which is solution to equation W*SIGe^(1/2) = P
18 | % - A\B (mldivide) solves A*x = B
19 | % - A/B (mrdivide) solves x*B = A <-- we want this to get W
20 | W = P/diag(SIGe_sqrt);
21 | isequal(W*SIGe*W',SIGu)
--------------------------------------------------------------------------------
/progs/matlab/matrixAlgebraCompareLyapunovSolvers.m:
--------------------------------------------------------------------------------
1 | % compares two different ways (Kronecker formula and doubling algorithm)
2 | % to compute the solution of the Lyapunov equation
3 | % SIGy = A*SIGy*A' + SIGu
4 | % -------------------------------------------------------------------------
5 | % Willi Mutschler, April 26, 2024
6 | % willi@mutschler.eu
7 | % -------------------------------------------------------------------------
8 | clearvars; clc; close all;
9 |
10 | A = [0.5, 0, 0;
11 | 0.1, 0.1, 0.3;
12 | 0, 0.2, 0.3];
13 | SIGu = [2.25 0 0; 0 1 0.5; 0 0.5 0.74];
14 |
15 | vecSIGy = (eye(size(A,1)^2)-kron(A,A)) \ SIGu(:);
16 | SIGy_kron = reshape(vecSIGy,size(A));
17 | SIGy_dlyap = dlyapdoubling(A,SIGu);
18 |
19 | fprintf('The maximum absolute difference of entries is %d\n',norm(abs(SIGy_kron-SIGy_dlyap),'Inf'));
--------------------------------------------------------------------------------
/progs/matlab/matrixAlgebraEigenvalues.m:
--------------------------------------------------------------------------------
1 | % illustration how to compute Eigenvalues of a matrix
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler, April 26, 2024
4 | % willi@mutschler.eu
5 | % -------------------------------------------------------------------------
6 | clearvars; clc; close all; % housekeeping
7 | A = [0.5, 0, 0;
8 | 0.1, 0.1, 0.3;
9 | 0, 0.2, 0.3];
10 | EV_A = eig(A);
11 | if all(abs(EV_A)<1)
12 | fprintf('All Eigenvalues are inside the unit circle\n');
13 | end
--------------------------------------------------------------------------------
/progs/matlab/matrixAlgebraKroneckerFormula.m:
--------------------------------------------------------------------------------
1 | % show that vec(D*E*F) = kron(F',D)*vec(E) using MATLAB's symbolic toolbox
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler, April 26, 2024
4 | % willi@mutschler.eu
5 | % -------------------------------------------------------------------------
6 | clearvars; clc; close all;
7 |
8 | %% Some basics on the symbolic toolbox
9 | syms x % create symbolic variable
10 | % note that matlab does not simplify or expand by default! example:
11 | f1 = (x - 2)^2;
12 | f2 = x^2 - 4*x + 4;
13 | expand(f1)
14 | simplify(f2)
15 | isequal(f1,f2)
16 | isequal(expand(f1),f2)
17 | isequal(f1,simplify(f2)) % note that simplify usually takes longer than expand
18 |
19 | %% Show that vec(D*E*F) = kron(F',D)*vec(E)
20 | dim = randi([1 10],1,4); % generate 4 random integers between 1 and 10 as dimensions
21 | % create symbolic matrices
22 | D = sym('d',[dim(1) dim(2)]);
23 | E = sym('e',[dim(2) dim(3)]);
24 | F = sym('f',[dim(3) dim(4)]);
25 | DEF = D*E*F; % check whether matrix product is defined
26 | vecDEF = DEF(:); %vectorization
27 |
28 | % correct: compare expanded symbolic expressions
29 | if isequal(expand(vecDEF),expand(kron(transpose(F),D)*E(:)))
30 | fprintf('Expanded expressions are identical\n');
31 | else
32 | error('Expanded expressions are not identical');
33 | end
--------------------------------------------------------------------------------
/progs/matlab/numericalOptimizationExamples.m:
--------------------------------------------------------------------------------
1 | % illustration and comparison of different numerical optimizers
2 | % on the Rosenbrock and Rastrigin functions
3 | % -------------------------------------------------------------------------
4 | % Willi Mutschler (willi@mutschler.eu)
5 | % Version: May 15, 2024
6 | % -------------------------------------------------------------------------
7 |
8 | % plot Rosenbrock function
9 | figure('Name','Rosenbrock function');
10 | fsurf(@(x,y) ((1-x).^2)+(100*((y-(x.^2)).^2)),[-3 3 -2 5],'ShowContours','on')
11 | title('Rosenbrock function')
12 | xlabel('x')
13 | ylabel('y')
14 |
15 | % plot Rastrigin function
16 | figure('Name','Rastrigin function');
17 | fsurf(@(x,y) 20 + x.^2 + y.^2 - 10*(cos(2*pi*x)+cos(2*pi*y)),'ShowContours','on')
18 | title('Rastrigin function')
19 | xlabel('x')
20 | ylabel('y')
21 |
22 | % common options for optimizers
23 | optim_options = optimset('Display','iter','TolX',1e-7,'TolFun',1e-7,'MaxFunEvals',200000,'MaxIter',200000);
24 | optim_options_swarm = optimoptions('particleswarm','Display','iter','TolFun',1e-7);
25 |
26 | % define objective function
27 | obj_rosenbrock = @(x) ((1-x(1)).^2)+(100*((x(2)-(x(1).^2)).^2));
28 | obj_rastrigin = @(x) 20 + x(1).^2 + x(2).^2 - 10*(cos(2*pi*x(1))+cos(2*pi*x(2)));
29 |
30 | % initialize
31 | x0 = randi([-5,5],2,1); % draw initial values randomly
32 | xopt_rosenbrock = nan(2,7); xopt_rastrigin = nan(2,7); % storage for optimal x
33 | fval_rosenbrock = nan(7,1); fval_rastrigin = nan(7,1); % storage for function values
34 |
35 | % optimize with fsolve
36 | [xopt_rosenbrock(:,1),fval_rosenbrock(1)] = fsolve(obj_rosenbrock,x0,optim_options );
37 | [xopt_rastrigin(:,1),fval_rastrigin(1)] = fsolve(obj_rastrigin,x0,optim_options );
38 |
39 | % optimize with fminunc
40 | [xopt_rosenbrock(:,2),fval_rosenbrock(2)] = fminunc(obj_rosenbrock,x0,optim_options );
41 | [xopt_rastrigin(:,2),fval_rastrigin(2)] = fminunc(obj_rastrigin,x0,optim_options );
42 |
43 | % optimize with fminsearch
44 | [xopt_rosenbrock(:,3),fval_rosenbrock(3)] = fminsearch(obj_rosenbrock,x0,optim_options);
45 | [xopt_rastrigin(:,3),fval_rastrigin(3)] = fminsearch(obj_rastrigin,x0,optim_options);
46 |
47 | % optimize with fmincon
48 | [xopt_rosenbrock(:,4),fval_rosenbrock(4)] = fmincon(obj_rosenbrock,x0,[],[],[],[],[],[],[],optim_options);
49 | [xopt_rastrigin(:,4),fval_rastrigin(4)] = fmincon(obj_rastrigin,x0,[],[],[],[],[],[],[],optim_options);
50 |
51 | % optimize with simulannealbnd
52 | [xopt_rosenbrock(:,5),fval_rosenbrock(5)] = simulannealbnd(obj_rosenbrock,x0,[],[],optim_options);
53 | [xopt_rastrigin(:,5),fval_rastrigin(5)] = simulannealbnd(obj_rastrigin,x0,[],[],optim_options);
54 |
55 | % optimize with patternsearch
56 | [xopt_rosenbrock(:,6),fval_rosenbrock(6)] = patternsearch(obj_rosenbrock,x0,[],[],[],[],[],[],[],optim_options);
57 | [xopt_rastrigin(:,6),fval_rastrigin(6)] = patternsearch(obj_rastrigin,x0,[],[],[],[],[],[],[],optim_options);
58 |
59 | % optimize with particleswarm
60 | [xopt_rosenbrock(:,7),fval_rosenbrock(7)] = particleswarm(obj_rosenbrock,2,[],[],optim_options_swarm);
61 | [xopt_rastrigin(:,7),fval_rastrigin(7)] = particleswarm(obj_rastrigin,2,[],[],optim_options_swarm);
62 |
63 | %% sort and display results
64 | optim_names = ["fsolve","fminunc","fminsearch","fmincon","simulannealbnd","patternsearch","particleswarm"];
65 | [~,idx_best_rosenbrock] = sort(fval_rosenbrock); [~,idx_best_rastrigin] = sort(fval_rastrigin);
66 |
67 | fprintf('RESULTS ROSENBROCK\n')
68 | disp(array2table([xopt_rosenbrock(:,idx_best_rosenbrock);fval_rosenbrock(idx_best_rosenbrock)'],...
69 | 'RowNames',{'x','y','f'},'VariableNames',optim_names(idx_best_rosenbrock)));
70 |
71 | fprintf('RESULTS RASTRIGIN\n')
72 | disp(array2table([xopt_rastrigin(:,idx_best_rastrigin);fval_rastrigin(idx_best_rastrigin)'],...
73 | 'RowNames',{'x','y','f'},'VariableNames',optim_names(idx_best_rastrigin)));
--------------------------------------------------------------------------------
/progs/matlab/preprocessingComparisonRBC.m:
--------------------------------------------------------------------------------
1 | % comparison of preprocessing in Dynare and MATLAB of basic RBC model
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler (willi@mutschler.eu)
4 | % Version: April 26, 2024
5 | % -------------------------------------------------------------------------
6 |
7 | clearvars;
8 |
9 | %% Dynare preprocessing
10 | oldfolder = cd('../dynare'); % go to folder of rbc.mod
11 | dynare rbc
12 | cd(oldfolder);
13 |
14 | %% MATLAB preprocessing
15 | preprocessingRBC;
16 | matlab_resid = rbc_dynamic_resid(zzz_ss,ex_ss,M_.params,y_ss);
17 | matlab_resid_static = rbc_static_resid(y_ss,ex_ss,M_.params);
18 | matlab_g1 = rbc_dynamic_g1(zzz_ss,ex_ss,M_.params,y_ss);
19 | matlab_g1_static = rbc_static_g1(y_ss,ex_ss,M_.params);
20 |
21 | %% comparison
22 | matlab_resid - dynare_resid
23 | matlab_resid_static - dynare_resid_static
24 | matlab_g1 - dynare_g1
25 | matlab_g1_static - dynare_g1_static
--------------------------------------------------------------------------------
/progs/matlab/quickTourMatlab.m:
--------------------------------------------------------------------------------
1 | % -------------------------------------------------------------------------
2 | % Illustration of MATLAB's basic matrix operations, logical operators, and
3 | % indexing.
4 | % -------------------------------------------------------------------------
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: October 19, 2023
7 | % -------------------------------------------------------------------------
8 |
9 | % 1)
10 | x = [-1; 0; 1; 4; 9; 2; 1; 4.5; 1.1; -0.9];
11 | y = [1, 1, 2, 2, 3, 3, 4, 4, 5, nan]';
12 |
13 | % 2
14 | length(x) == length(y)
15 | size(x,1) == size(y,1)
16 |
17 | % 3
18 | x < y
19 | x < 0
20 | x+3 >= 0
21 | y < 0
22 |
23 | % 4
24 | all(x+3>=0) && all(y>0)
25 |
26 | % 5
27 | all(x+3>=0) || all(y>0)
28 |
29 | % 6
30 | any(y>0)
31 |
32 | % 7
33 | x+y
34 | try
35 | x*y
36 | catch ME
37 | disp(ME.message);
38 | end
39 | x * y'
40 | x' * y
41 | y / x
42 | x / y
43 |
44 | % 8
45 | x .* y
46 | y ./ x
47 |
48 | % 9
49 | log(x)
50 | exp(x)
51 |
52 | % 10
53 | any(sqrt(x)>=2)
54 |
55 | % 11
56 | a = sum(x)
57 | b = sum(y.^2,'omitnan')
58 |
59 | % 12
60 | sum(x.*y.^2,'omitnan')
61 |
62 | % 13
63 | sum(x>0)
64 |
65 | % 14
66 | x.^y
67 | x.^(1/y)
68 | log(exp(y))
69 | y*[-1,1]
70 | x+[-1,0,1]
71 | sum(y*[-1,1],1,'omitnan')
72 |
73 | % 15
74 | X = [1 4 7;
75 | 2 5 8;
76 | 3 6 9];
77 |
78 | transpose(X)
79 | X'
80 | size(X)
81 | det(X)
82 |
83 | % 16
84 | trace(X)
85 | sum(diag(X))
86 |
87 | % 17
88 | X
89 | X([1 5 9])=[7 8 9]
90 | X
91 |
92 | % 18
93 | eigvalX = eig(X);
94 | if all(eigvalX>0)
95 | fprintf('X is positive definite\n')
96 | elseif all(eigvalX>=0)
97 | fprintf('X is positive semi-definite\n')
98 | elseif all(eigvalX<0)
99 | fprintf('X is negative definite\n')
100 | elseif all(eigvalX<=0)
101 | fprintf('X is negative semi-definite\n')
102 | else
103 | fprintf('X is neither positive nor negative (semi-)definite\n')
104 | end
105 |
106 | % 19
107 | invX = inv(X);
108 | eig(invX)
109 | 1./eigvalX % these are the same eigenvalues
110 |
111 | % 20
112 | a = [1;3;2];
113 | a'*X
114 | a'.*X
115 | X*a
116 |
117 | % 21
118 | a'*X*a
119 |
120 | % 22
121 | I = eye(3);
122 | X = reshape(1:9,3,3);
123 | Y = [X I]
124 | Z = [X;I]
125 |
126 | % 23
127 | x1 = 1:9
128 | x2 = repmat([0 1],1,4)
129 | x3 = repmat(1,1,8)
130 | x4 = repmat([-1 1],1,3)
131 | x5 = 1980:5:2010
132 | x6 = 0:0.01:1
133 |
134 | % 24
135 | linspace(-pi,pi,500)
136 |
137 | % 25
138 | 1:10+1
139 | (1:10)+1
140 | 1:(10+1)
141 |
142 | % 26
143 | x = [1 1.1 9 7 1 4 4 1]';
144 | y = [1 2 3 4 4 3 2 nan]';
145 | z = [true true false false true false false false];
146 |
147 | % 27
148 | x(2:5)
149 | x(4:end-2)
150 | x([1 5 8])
151 | x(repmat(1:3,1,4))
152 | y(z)
153 | y(~z)
154 | y(x>2)
155 | y(x==1)
156 | x(~isnan(y))
157 | y(~isnan(y))
158 |
159 | % 28
160 | x2 = x;
161 | x2(x2==4) = -4;
162 | x2
163 |
164 | % 29
165 | x2(x2==1) = nan;
166 | x2
167 |
168 | % 30
169 | x2(z) = [];
170 | x2
171 |
172 | % 31
173 | M = reshape([1:12 12:-1:1],4,6);
174 |
175 | % 32
176 | M(1,3)
177 | M(:,5)
178 | M(2,:)
179 | M(2:3,3:4)
180 | M(2:4,4)
181 | M(M>5)
182 | M(:,M(1,:)<=5)
183 | M(M(:,2)>6,:)
184 | M(M(:,2)>6,4:6)
185 |
186 | % 33
187 | find(M(:,5)>3*M(:,6))
188 |
189 | % 34
190 | sum(M>7,'all')
191 |
192 | % 35
193 | sum(M(2,:) < M(1,:))
194 |
195 | % 36
196 | sum( M(:,2:end) > M(:,1:end-1) ,'all')
--------------------------------------------------------------------------------
/progs/matlab/rbcCRRASteadyState.m:
--------------------------------------------------------------------------------
1 | function [SS,PARAMS,error_indicator] = rbcCRRASteadyState(SS,PARAMS)
2 | % [SS,PARAMS,error_indicator] = rbcCRRASteadyState(SS,PARAMS)
3 | % -------------------------------------------------------------------------
4 | % computes the steady-state of the RBC model with CRRA utility using a
5 | % numerical optimizer to compute steady-state labor
6 | % -------------------------------------------------------------------------
7 | % INPUTS
8 | % - SS : structure with initial steady-state values, fieldnames are variable names
9 | % - PARAMS : structure with values for the parameters, fieldnames are parameter names
10 | % -------------------------------------------------------------------------
11 | % OUTPUTS
12 | % - SS : structure with computed steady-state values, fieldnames are variable names
13 | % - PARAMS : structure with updated values for the parameters, fieldnames are parameter names
14 | % - error_indicator: 0 if no error occured when computing the steady-state
15 | % -------------------------------------------------------------------------
16 | % Willi Mutschler (willi@mutschler.eu)
17 | % Version: April 26, 2024
18 | % -------------------------------------------------------------------------
19 | error_indicator = 0; % initialize no error
20 |
21 | % read-out parameters
22 | ALPHA = PARAMS.ALPHA;
23 | BETA = PARAMS.BETA;
24 | DELTA = PARAMS.DELTA;
25 | GAMMA = PARAMS.GAMMA;
26 | PSI = PARAMS.PSI;
27 | RHOA = PARAMS.RHOA;
28 | ETAC = PARAMS.ETAC;
29 | ETAL = PARAMS.ETAL;
30 |
31 | % compute steady-state analytically as much as possible
32 | a = 1;
33 | rk = 1/BETA+DELTA-1;
34 | k_n = ((ALPHA*a)/rk)^(1/(1-ALPHA));
35 | if k_n <= 0
36 | error_indicator = 1; % violation of non-negativity constraint
37 | end
38 | w = (1-ALPHA)*a*k_n^ALPHA;
39 | iv_n = DELTA*k_n;
40 | y_n = a*k_n^ALPHA;
41 | c_n = y_n - iv_n;
42 | if c_n <= 0
43 | error_indicator = 1; % violation of non-negativity constraint
44 | end
45 | if (ETAC == 1 && ETAL == 1)
46 | % closed-form expression for l available
47 | n = GAMMA/PSI*c_n^(-1)*w/(1+GAMMA/PSI*c_n^(-1)*w);
48 | else
49 | % no closed-form solution and we therefore use a numerical optimizer
50 | if error_indicator == 0
51 | n0 = SS.n; % initial guess
52 | % 'findN' is a nested function within this file that calculates a numerical solution for n
53 | % The function is referenced here using the @ symbol to pass it as a function handle.
54 | % One could also place the 'findN' function in a separate file findN.m and call it directly.
55 | [n,~,exitflag] = fsolve(@findN,n0,optimset('Display','off','TolX',1e-12,'TolFun',1e-12));
56 | if exitflag <= 0
57 | error_indicator = 1;
58 | end
59 | else
60 | n = NaN;
61 | end
62 | end
63 | c = c_n*n;
64 | iv = iv_n*n;
65 | k = k_n*n;
66 | y = y_n*n;
67 | uc = GAMMA*c^(-1);
68 | ul = -PSI/(1-n);
69 | fn = (1-ALPHA)*a*(k/n)^ALPHA;
70 | fk = ALPHA*a*(k/n)^(ALPHA-1);
71 |
72 | % write to output structure
73 | SS.y = y;
74 | SS.c = c;
75 | SS.k = k;
76 | SS.n = n;
77 | SS.a = a;
78 | SS.rk = rk;
79 | SS.w = w;
80 | SS.iv = iv;
81 | SS.uc = uc;
82 | SS.ul = ul;
83 | SS.fn = fn;
84 | SS.fk = fk;
85 |
86 | %% Auxiliary function 'findN' used in optimization
87 | % This function computes an error term (residual) based on several parameters and variables.
88 | % Some variables ('w', 'GAMMA', 'c_n', 'ETAC', 'PSI', 'ETAL') are not explicitly passed as input arguments;
89 | % instead, these variables inherit their values from the surrounding scope of the script,
90 | % allowing them to be used directly within this function as if they were local variables.
91 | function residual = findN(N)
92 | residual = w*GAMMA*c_n^(-ETAC) - PSI*(1-N)^(-ETAL)*N^ETAC;
93 | end
94 |
95 | end
--------------------------------------------------------------------------------
/progs/matlab/rbcCRRASteadyStateTest.m:
--------------------------------------------------------------------------------
1 | % computes the steady-state of the RBC model with CRRA utility
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler (willi@mutschler.eu)
4 | % Version: April 26, 2024
5 | % -------------------------------------------------------------------------
6 |
7 | % calibration
8 | PARAMS.ALPHA = 0.35;
9 | PARAMS.BETA = 0.9901;
10 | PARAMS.DELTA = 0.025;
11 | PARAMS.GAMMA = 1;
12 | PARAMS.PSI = 1.7333;
13 | PARAMS.RHOA = 0.9;
14 | PARAMS.ETAC = 2;
15 | PARAMS.ETAL = 1.5;
16 |
17 | SS.n = 1/3; % initial guess for labor
18 |
19 | % compute steady-state
20 | [SS,PARAMS,error_indicator] = rbcCRRASteadyState(SS,PARAMS);
21 | if ~error_indicator
22 | disp(SS);
23 | else
24 | error('steady-state could not be computed')
25 | end
--------------------------------------------------------------------------------
/progs/matlab/rbcLogutilSteadyState.m:
--------------------------------------------------------------------------------
1 | function [SS,PARAMS,error_indicator] = rbcLogutilSteadyState(SS,PARAMS)
2 | % [SS,PARAMS,error_indicator] = rbcLogutilSteadyState(SS,PARAMS)
3 | % -------------------------------------------------------------------------
4 | % computes the steady-state of the RBC model with log utility analytically,
5 | % inputs and outputs are stored into structures
6 | % -------------------------------------------------------------------------
7 | % INPUTS
8 | % - SS : structure with initial steady-state values, fieldnames are variable names (usually empty, but might be useful for initial values or to update endogenous parameters)
9 | % - params : structure with values for the parameters, fieldnames are parameter names
10 | % ----------------------------------------------------------------------
11 | % OUTPUTS
12 | % - SS : structure with computed steady-state values, fieldnames are variable names
13 | % - params : structure with updated values for the parameters, fieldnames are parameter names
14 | % - error_indicator: 0 if no error when computing the steady-state
15 | % -------------------------------------------------------------------------
16 | % Willi Mutschler (willi@mutschler.eu)
17 | % Version: April 26, 2024
18 | % -------------------------------------------------------------------------
19 | error_indicator = 0; % initialize no error
20 |
21 | % read-out parameters
22 | ALPHA = PARAMS.ALPHA;
23 | BETA = PARAMS.BETA;
24 | DELTA = PARAMS.DELTA;
25 | GAMMA = PARAMS.GAMMA;
26 | PSI = PARAMS.PSI;
27 | RHOA = PARAMS.RHOA; % does not influence steady-state
28 |
29 | % compute steady-state analytically
30 | a = 1;
31 | rk = 1/BETA+DELTA-1;
32 | k_n = ((ALPHA*a)/rk)^(1/(1-ALPHA));
33 | if k_n <= 0 % here we can impose our non-negativity constraints to rule out certain steady-states
34 | error_indicator = 1;
35 | end
36 | w = (1-ALPHA)*a*k_n^ALPHA;
37 | iv_n = DELTA*k_n;
38 | y_n = a*k_n^ALPHA;
39 | c_n = y_n - iv_n;
40 | if c_n <= 0
41 | error_indicator = 1;
42 | end
43 | n = GAMMA/PSI*c_n^(-1)*w/(1+GAMMA/PSI*c_n^(-1)*w); % closed-form expression for n
44 |
45 | c = c_n*n;
46 | iv = iv_n*n;
47 | k = k_n*n;
48 | y = y_n*n;
49 | uc = GAMMA*c^(-1);
50 | un = -PSI/(1-n);
51 | fn = (1-ALPHA)*a*(k/n)^ALPHA;
52 | fk = ALPHA*a*(k/n)^(ALPHA-1);
53 |
54 | % write to output structure
55 | SS.y = y;
56 | SS.c = c;
57 | SS.k = k;
58 | SS.n = n;
59 | SS.a = a;
60 | SS.rk = rk;
61 | SS.w = w;
62 | SS.iv = iv;
63 | SS.uc = uc;
64 | SS.un = un;
65 | SS.fn = fn;
66 | SS.fk = fk;
67 |
68 | end
--------------------------------------------------------------------------------
/progs/matlab/rbcLogutilSteadyStateTest.m:
--------------------------------------------------------------------------------
1 | % computes the steady-state of the RBC model with log utility
2 | % -------------------------------------------------------------------------
3 | % Willi Mutschler (willi@mutschler.eu)
4 | % Version: April 26, 2024
5 | % -------------------------------------------------------------------------
6 |
7 | % calibration
8 | PARAMS.ALPHA = 0.35;
9 | PARAMS.BETA = 0.9901;
10 | PARAMS.DELTA = 0.025;
11 | PARAMS.GAMMA = 1;
12 | PARAMS.PSI = 1.7333;
13 | PARAMS.RHOA = 0.9;
14 | SS = []; % no need for initial values
15 |
16 | % compute steady-state
17 | [SS,PARAMS,error_indicator] = rbcLogutilSteadyState(SS,PARAMS);
18 | if ~error_indicator
19 | disp(SS);
20 | else
21 | error('steady-state could not be computed')
22 | end
--------------------------------------------------------------------------------
/progs/matlab/templateMatlabExample.m:
--------------------------------------------------------------------------------
1 | % reshape example
2 | x = reshape(eye(3,3),3*3,1);
3 | % cool solver
4 | dlyap(A,RHS);
--------------------------------------------------------------------------------
/progs/matlab/writeOut.m:
--------------------------------------------------------------------------------
1 | function writeOut(Output, nameOfFunction, nameOfOutput, is_static, dynamic_names, endo_names, exo_names, param_names)
2 | % writeOut(Output, nameOfFunction, nameOfOutput, is_static, dynamic_names, endo_names, exo_names, param_names)
3 | % -------------------------------------------------------------------------
4 | % helper function to create MATLAB script files for the residuals and
5 | % Jacobian of dynamic and static model equations of DSGE models, created
6 | % with MATLAB's symbolic toolbox
7 | % -------------------------------------------------------------------------
8 | % INPUTS
9 | % - Output [symbolic matrix] symbolic matrix that will be
10 | % written out into a script file
11 | % either residuals or Jacobian of
12 | % dynamic or static model equations
13 | % - nameOfFunction [string array] name of function that'll be created
14 | % - nameOfOutput [string array] name of output variable
15 | % - is_static [boolean] indicator whether Output is based on
16 | % static or dynamic model equations
17 | % - dynamic_names [string array] names of dynamic variables
18 | % - endo_names [string array] names of endogenous variables
19 | % - exo_names [string array] names of exogenous variables
20 | % - param_names [string array] names of parameters
21 | % -------------------------------------------------------------------------
22 | % OUTPUTS
23 | % - creates script file that are MATLAB funcions within current folder
24 | % for fast evaluation of residuals or Jacobian of static or dynamic model
25 | % equations of a DSGE model
26 | % -------------------------------------------------------------------------
27 | % Willi Mutschler (willi@mutschler.eu)
28 | % Version: Aprix 26, 2024
29 | % -------------------------------------------------------------------------
30 |
31 | filename = strcat(nameOfFunction,'.m');
32 | % delete old version of file (if it exists)
33 | if exist(filename,'file') > 0
34 | delete(filename);
35 | end
36 | fileID = fopen(filename,'w');
37 | if is_static
38 | fprintf(fileID,'function %s = %s(endo_vars,exo_vars,params)\n',nameOfOutput,nameOfFunction);
39 | fprintf(fileID,'\n%% Evaluate numerical values for endogenous variables\n');
40 | for j = 1:size(endo_names,1)
41 | fprintf(fileID,'%s = endo_vars(%d);\n',endo_names(j),j);
42 | end
43 | else
44 | fprintf(fileID,'function %s = %s(dynamic_vars,exo_vars,params,steady_state)\n',nameOfOutput,nameOfFunction);
45 | fprintf(fileID,'\n%% Evaluate numerical values for dynamic variables\n');
46 | for j = 1:size(dynamic_names,1)
47 | fprintf(fileID,'%s = dynamic_vars(%d);\n',dynamic_names(j),j);
48 | end
49 | end
50 |
51 | fprintf(fileID,'\n%% Evaluate numerical values for exogenous variables\n');
52 | for j = 1:size(exo_names,1)
53 | fprintf(fileID,'%s = exo_vars(%d);\n',exo_names(j),j);
54 | end
55 |
56 | fprintf(fileID,'\n%% Evaluate numerical values for parameters from params\n');
57 | for j = 1:size(param_names,1)
58 | fprintf(fileID,'%s = params(%d);\n',param_names(j),j);
59 | end
60 |
61 | if ~is_static
62 | fprintf(fileID,'\n%% Evaluate numerical values for steady-state variables\n');
63 | for j = 1:size(endo_names,1)
64 | fprintf(fileID,'%s_stst = steady_state(%d);\n',endo_names(j),j);
65 | end
66 | end
67 |
68 | fprintf(fileID,'\n%% Initialize %s\n',nameOfOutput);
69 | fprintf(fileID,'%s = zeros(%d, %d);',nameOfOutput,size(Output,1),size(Output,2));
70 |
71 | fprintf(fileID,'\n%% Evaluate non-zero entries in %s\n',nameOfOutput);
72 | [nonzero_row,nonzero_col,nonzero_vals] = find(Output);
73 | for j = 1:size(nonzero_vals,1)
74 | fprintf(fileID,'%s(%d,%d) = %s;\n',nameOfOutput,nonzero_row(j),nonzero_col(j),char(nonzero_vals(j)));
75 | end
76 |
77 | fprintf(fileID,'\nend %% function end \n');
78 | fclose(fileID);
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_calib_environmental_policy.inc:
--------------------------------------------------------------------------------
1 | g 0.0794823224003145
2 | ALPHA 0.3333333333333333
3 | BETA 0.99
4 | DELTA_K 0.025
5 | GAMMA_I 15
6 | PHI 1
7 | THETA 6
8 | XI 0.75
9 | A 1.248007701187076
10 | MU_L 19.84126984149098
11 | IOTA_PI 3
12 | DELTA_M 0.002099999999999991
13 | VARPHI 0.45
14 | PHI_1 0.18
15 | PHI_2 2.8
16 | GAMMA_0 0.001395
17 | GAMMA_1 -6.6722e-06
18 | GAMMA_2 1.4647e-08
19 | RHO_A 0.95
20 | RHO_G 0.97
21 | RHO_ETA 0.15
22 | TARGET_PIE 1
23 | TARGET_M 766.6558064000003
24 | TARGET_ZSHARE 0.1739721701532527
25 | ZSTAR 1.329885967199995
26 | TARGET_INTENSITY 0.368936062504494
27 | CARBON_TAX 0.05120654715574728
28 | a 1.248007701187076
29 | c 0.5320520577871346
30 | ca_y 0.001482501822329579
31 | dp 1
32 | iv 0.1465264843106447
33 | k 5.861059372425788
34 | l 0.1974245331855177
35 | m 766.6558064000003
36 | mc 0.8333333333333334
37 | pstar 1
38 | pz 0.05120654715574728
39 | rnom 1.01010101010101
40 | rk 0.03510101010101019
41 | t 0.06513981781594491
42 | u 0.1801421165017708
43 | w 2.084129546432339
44 | x 4.504904856280751
45 | y 0.7591863596597772
46 | z 0.2800912262399988
47 | eta 1
48 | Gamma_m 0.004888656333543587
49 | Theta 5.541368554480118
50 | pie 1
51 | Psi 0.8129588948994557
52 | Omega 0.1129022974221727
53 | q 1
54 | welf -101.7685035729705
55 | TARGET_GSHARE 0.1046940864900863
56 | eps_a 0
57 | eps_g 0
58 | eps_eta 0
59 |
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_calib_no_policy.inc:
--------------------------------------------------------------------------------
1 | l 0.2
2 | ALPHA 0.3333333333333333
3 | BETA 0.99
4 | DELTA_K 0.025
5 | GAMMA_I 15
6 | PHI 1
7 | THETA 6
8 | XI 0.75
9 | A 1.248007701187076
10 | IOTA_PI 3
11 | DELTA_M 0.002099999999999991
12 | VARPHI 0.45
13 | PHI_1 0.18
14 | PHI_2 2.8
15 | GAMMA_0 0.001395
16 | GAMMA_1 -6.6722e-06
17 | GAMMA_2 1.4647e-08
18 | RHO_A 0.95
19 | RHO_G 0.97
20 | RHO_ETA 0.15
21 | TARGET_PIE 1
22 | TARGET_GSHARE 0.102158273389097
23 | TARGET_M 800
24 | TARGET_ZSHARE 0.20840121
25 | ZSTAR 1.329885967199995
26 | TARGET_INTENSITY 0.45
27 | CARBON_TAX 0
28 | a 1.248007701187076
29 | c 0.5446218287939278
30 | ca_y 0
31 | dp 1
32 | g 0.0794823224003145
33 | iv 0.1539270328057544
34 | k 6.157081312230175
35 | m 800
36 | mc 0.8333333333333334
37 | pstar 1
38 | pz 0
39 | rnom 1.01010101010101
40 | rk 0.03510101010101019
41 | t 0.0794823224003145
42 | u 0
43 | w 2.161197733333324
44 | x 4.623208506755177
45 | y 0.7780311839999967
46 | z 0.3501140327999985
47 | eta 1
48 | Gamma_m 0.00543132
49 | Theta 5.547850208106213
50 | pie 1
51 | Psi 0.8333333333333334
52 | Omega 0
53 | q 1
54 | welf -100.4489014124508
55 | MU_L 19.84126984149098
56 | eps_a 0
57 | eps_g 0
58 | eps_eta 0
59 |
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_environmental_regime.inc:
--------------------------------------------------------------------------------
1 | %-------------------------------------------------------------------------%
2 | % environmental regime
3 | %-------------------------------------------------------------------------%
4 | @#ifdef NO_POLICY
5 | [name='A(26) abatement effort']
6 | u = 0;
7 | @#else
8 | [name='A(26) abatement effort']
9 | VARPHI * pz = PHI_1 * PHI_2 * u^(PHI_2-1);
10 | @#endif
11 |
12 | @#ifdef NO_POLICY
13 | [name='environmental policy regime: no policy (p.6 bottom)']
14 | pz = 0;
15 | @#endif
16 |
17 | @#ifdef CAP_AND_TRADE
18 | [name='environmental policy regime: cap-and-trade (p.6 bottom)']
19 | z = TARGET_ZSHARE*DELTA_M*TARGET_M;
20 | @#endif
21 |
22 | @#ifdef INTENSITY_TARGET
23 | [name='environmental policy regime: intensity target (p.7 top)']
24 | z = TARGET_INTENSITY*y;
25 | @#endif
26 |
27 | @#ifdef TAX_POLICY
28 | [name='environmental policy regime: tax policy (p.7 top)']
29 | pz = CARBON_TAX;
30 | @#endif
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_cap_and_trade.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: May 5, 2023
7 | % =========================================================================
8 |
9 | @#define CAP_AND_TRADE = 1
10 | @#include "ann_dio_2015_symdecls.inc"
11 | @#include "ann_dio_2015_modeleqs.inc"
12 |
13 | %-------------------------------------------------------------------------%
14 | % calibration
15 | %-------------------------------------------------------------------------%
16 | load_params_and_steady_state('ann_dio_2015_calib_environmental_policy.inc');
17 | steady;
18 |
19 | %-------------------------------------------------------------------------%
20 | % computation: impulse response function
21 | %-------------------------------------------------------------------------%
22 | SIGMA_A = 1;%0.0045;
23 | SIGMA_G = 1;%0.0053;
24 | SIGMA_ETA = 0;%0.0024;
25 | shocks;
26 | var eps_a = SIGMA_A^2;
27 | var eps_g = SIGMA_G^2;
28 | var eps_eta = SIGMA_ETA^2;
29 | end;
30 | stoch_simul(order=1,irf=21,nograph) y c iv l mc z u pz;
31 | %stoch_simul(order=2,pruning,irf=21,nograph) y c iv l mc z u pz;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_cap_and_trade/Output/ann_dio_2015_irfs_cap_and_trade_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_cap_and_trade/Output/ann_dio_2015_irfs_cap_and_trade_results.mat
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_cap_and_trade/checksum:
--------------------------------------------------------------------------------
1 | 11597213666492544387
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_intensity_target.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: May 5, 2023
7 | % =========================================================================
8 |
9 | @#define INTENSITY_TARGET = 1
10 | @#include "ann_dio_2015_symdecls.inc"
11 | @#include "ann_dio_2015_modeleqs.inc"
12 |
13 | %-------------------------------------------------------------------------%
14 | % calibration
15 | %-------------------------------------------------------------------------%
16 | load_params_and_steady_state('ann_dio_2015_calib_environmental_policy.inc');
17 | steady;
18 |
19 | %-------------------------------------------------------------------------%
20 | % computation: impulse response function
21 | %-------------------------------------------------------------------------%
22 | SIGMA_A = 1;%0.0045;
23 | SIGMA_G = 1;%0.0053;
24 | SIGMA_ETA = 0;%0.0024;
25 | shocks;
26 | var eps_a = SIGMA_A^2;
27 | var eps_g = SIGMA_G^2;
28 | var eps_eta = SIGMA_ETA^2;
29 | end;
30 | stoch_simul(order=1,irf=21,nograph) y c iv l mc z u pz;
31 | %stoch_simul(order=2,pruning,irf=21,nograph) y c iv l mc z u pz;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_intensity_target/Output/ann_dio_2015_irfs_intensity_target_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_intensity_target/Output/ann_dio_2015_irfs_intensity_target_results.mat
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_intensity_target/checksum:
--------------------------------------------------------------------------------
1 | 13367851277821045022
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_no_policy.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: May 5, 2023
7 | % =========================================================================
8 | @#define NO_POLICY = 1
9 | @#include "ann_dio_2015_symdecls.inc"
10 | @#include "ann_dio_2015_modeleqs.inc"
11 |
12 | %-------------------------------------------------------------------------%
13 | % calibration
14 | %-------------------------------------------------------------------------%
15 | load_params_and_steady_state('ann_dio_2015_calib_no_policy.inc');
16 | steady;
17 |
18 | %-------------------------------------------------------------------------%
19 | % computation: impulse response function
20 | %-------------------------------------------------------------------------%
21 | SIGMA_A = 1;%0.0045;
22 | SIGMA_G = 1;%0.0053;
23 | SIGMA_ETA = 0;%0.0024;
24 | shocks;
25 | var eps_a = SIGMA_A^2;
26 | var eps_g = SIGMA_G^2;
27 | var eps_eta = SIGMA_ETA^2;
28 | end;
29 | stoch_simul(order=1,irf=21,nograph) y c iv l mc z u pz;
30 | %stoch_simul(order=2,pruning,irf=21,nograph) y c iv l mc z u pz;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_no_policy/Output/ann_dio_2015_irfs_no_policy_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_no_policy/Output/ann_dio_2015_irfs_no_policy_results.mat
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_no_policy/checksum:
--------------------------------------------------------------------------------
1 | 4126562966068353385
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_tax_policy.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: May 5, 2023
7 | % =========================================================================
8 | @#define TAX_POLICY = 1
9 | @#include "ann_dio_2015_symdecls.inc"
10 | @#include "ann_dio_2015_modeleqs.inc"
11 |
12 | %-------------------------------------------------------------------------%
13 | % calibration
14 | %-------------------------------------------------------------------------%
15 | load_params_and_steady_state('ann_dio_2015_calib_environmental_policy.inc');
16 | steady;
17 |
18 | %-------------------------------------------------------------------------%
19 | % computation: impulse response function
20 | %-------------------------------------------------------------------------%
21 | SIGMA_A = 1;%0.0045;
22 | SIGMA_G = 1;%0.0053;
23 | SIGMA_ETA = 0;%0.0024;
24 | shocks;
25 | var eps_a = SIGMA_A^2;
26 | var eps_g = SIGMA_G^2;
27 | var eps_eta = SIGMA_ETA^2;
28 | end;
29 | stoch_simul(order=1,irf=21,nograph) y c iv l mc z u pz;
30 | %stoch_simul(order=2,pruning,irf=21,nograph) y c iv l mc z u pz;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_tax_policy/Output/ann_dio_2015_irfs_tax_policy_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_tax_policy/Output/ann_dio_2015_irfs_tax_policy_results.mat
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_irfs_tax_policy/checksum:
--------------------------------------------------------------------------------
1 | 3610470253901138395
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_modeleqs.inc:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % common declarations and equations
5 | % =========================================================================
6 | % Willi Mutschler (willi@mutschler.eu)
7 | % Version: May 5, 2023
8 | % =========================================================================
9 | model;
10 | @#include "ann_dio_2015_environmental_regime.inc"
11 | %-------------------------------------------------------------------------%
12 | % common model equations
13 | %-------------------------------------------------------------------------%
14 | [name='A(17) bond holding']
15 | rnom^(-1) = BETA / pie(+1) * c / c(+1);
16 | [name='A(18) labor supply']
17 | MU_L * l^PHI = 1/c * w;
18 | [name='A(19) investment decision']
19 | BETA * ( rk(+1) + GAMMA_I * ( iv(+1)/k(+1) - DELTA_K ) * (iv(+1)/k(+1))^2 ) - q * c(+1) / c + BETA * (1-DELTA_K)*q(+1) = 0;
20 | [name='A(20) capital decision']
21 | q - 1 - GAMMA_I * ( iv/k - DELTA_K) * (iv/k) - GAMMA_I/2 * ( iv/k - DELTA_K )^2 = 0;
22 | [name='A(21) aggregate demand']
23 | y = c + iv + g + ca_y*y + GAMMA_I/2* ( ( iv/k - DELTA_K )^2 ) * iv;
24 | [name='A(22) capital accumulation']
25 | k(+1) = (1-DELTA_K)*k + iv;
26 | [name='A(23) damage function']
27 | Gamma_m = GAMMA_0 + GAMMA_1*m + GAMMA_2*m^2;
28 | [name='A(23) aggregate supply with damage function']
29 | y = (1 - Gamma_m) * a * k^ALPHA * l^(1-ALPHA) * dp^(-1);
30 | [name='A(24) labor demand']
31 | (1-ALPHA) * y/l * Psi = w;
32 | [name='A(25) capital demand']
33 | ALPHA * y/k * Psi = rk;
34 | [name='A(27) recursive price setting']
35 | pstar = THETA/(THETA-1) * (x + Omega) / Theta;
36 | [name='A(28) recursive price setting auxiliary sum 1']
37 | x = c^(-1)*Psi*y + XI*BETA*pie(+1)^THETA*x(+1);
38 | [name='A(29) recursive price setting auxiliary sum 2']
39 | Theta = c^(-1)*y + XI*BETA*pie(+1)^(THETA-1)*Theta(+1);
40 | [name='A(30) recursive price setting auxiliary sum 3']
41 | Omega = c^(-1)*( PHI_1*u^PHI_2 + pz*(1-u)*VARPHI )*y + XI*BETA*pie(+1)^THETA*Omega(+1);
42 | [name='A(31) optimal reset price law of motion']
43 | 1 = XI*pie^(THETA-1) + (1-XI)*pstar^(1-THETA);
44 | [name='A(32) price efficiency distortion law of motion']
45 | dp = (1-XI)*pstar^(-THETA) + XI*pie^THETA*dp(-1);
46 | [name='A(33) overall marginal costs']
47 | mc = Psi + PHI_1*u^PHI_2 + pz*(1-u)*VARPHI;
48 | [name='A(34) emissions']
49 | z = (1-u) * VARPHI * y * dp;
50 | [name='A(35) pollution stock']
51 | m = (1-DELTA_M)*m(-1) + z + ZSTAR;
52 | [name='A(36) abatement cost ratio']
53 | ca_y = PHI_1 * u^PHI_2 * dp;
54 | [name='A(37) government budget constraint']
55 | t + pz*z = g;
56 | [name='A(38) monetary rule']
57 | rnom = steady_state(rnom) * (pie/TARGET_PIE)^IOTA_PI * eta;
58 | [name='A(38) total factor productivity']
59 | log(a) = (1-RHO_A)*log(A) + RHO_A*log(a(-1)) + eps_a;
60 | [name='A(39) public spending rule']
61 | log(g) = (1-RHO_G)*log(TARGET_GSHARE*steady_state(y)) + RHO_G*log(g(-1)) + eps_g;
62 | [name='A(40) monetary policy shock']
63 | log(eta) = RHO_ETA*log(eta(-1)) + eps_eta;
64 | [name='(14) recursive welfare (lifetime utility)']
65 | welf = ( log(c) - MU_L*l^(1+PHI)/(1+PHI) ) + BETA*welf(+1);
66 | end;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_moms_cap_and_trade.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % =========================================================================
5 | % Willi Mutschler (willi@mutschler.eu)
6 | % Version: May 5, 2023
7 | % =========================================================================
8 |
9 | @#define CAP_AND_TRADE = 1
10 | @#include "ann_dio_2015_symdecls.inc"
11 | @#include "ann_dio_2015_modeleqs.inc"
12 |
13 | %-------------------------------------------------------------------------%
14 | % calibration
15 | %-------------------------------------------------------------------------%
16 | load_params_and_steady_state('ann_dio_2015_calib_environmental_policy.inc');
17 | steady;
18 |
19 | %-------------------------------------------------------------------------%
20 | % computation: impulse response function
21 | %-------------------------------------------------------------------------%
22 | SIGMA_A = 0.0045;
23 | SIGMA_G = 0.0053;
24 | SIGMA_ETA = 0.0024;
25 | shocks;
26 | var eps_a = SIGMA_A^2;
27 | var eps_g = SIGMA_G^2;
28 | var eps_eta = SIGMA_ETA^2;
29 | end;
30 | stoch_simul(order=2,pruning,irf=21,nograph) y c iv l mc z u pz;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_steadystate_helper.m:
--------------------------------------------------------------------------------
1 | function [u,pz,Psi,ca_y,y,c,l,k,iv,w] = ann_dio_2015_steadystate_helper(z,Gamma_m,rk,mc,dp,g, DELTA_K,ALPHA,PHI,MU_L,A,VARPHI,PHI_1,PHI_2)
2 | x0(1,1) = 0.2; % l
3 | x0(2,1) = 0.7; % y
4 | x0(3,1) = 0.8; % Psi
5 | x0(4,1) = 6; % k
6 | x0(5,1) = 0.8; % u
7 |
8 | options = optimset('Display','iter','TolX',1e-6);
9 | [ss,fval,exitflag] = fsolve(@obj,x0,options,...
10 | z,Gamma_m,rk,mc,dp,g,...
11 | DELTA_K,ALPHA,PHI,MU_L,A,VARPHI,PHI_1,PHI_2);
12 |
13 | function f = obj(x, z,Gamma_m,rk,mc,dp,g, DELTA_K,ALPHA,PHI,MU_L,A,VARPHI,PHI_1,PHI_2)
14 | l = x(1);
15 | y = x(2);
16 | Psi = x(3);
17 | k = x(4);
18 | u = x(5);
19 |
20 | pz = PHI_1*PHI_2*u^(PHI_2-1)/VARPHI; % environmental policy regime in steady-state
21 | WL_C = MU_L*l^(PHI+1); % labor supply in steady-state
22 | iv = k*DELTA_K; % capital accumulation in steady-state
23 | ca = PHI_1*u^PHI_2*y*dp; % abatement cost in steady-state
24 | c = y-iv-g-ca; % aggregate demand in steady-state
25 | w = WL_C*c/l;
26 | ca_y = ca/y;
27 | f(1) = WL_C*c - (1-ALPHA)*Psi*y; % labor demand in steady-state
28 | f(2) = y - (1-Gamma_m)*A*k^ALPHA*l^(1-ALPHA)*dp^(-1); % aggregate supply in steady-state
29 | f(3) = ALPHA*Psi*y/k - rk; % capital demand in steady-state
30 | f(4) = mc - ( Psi + PHI_1*u^PHI_2 + pz*(1-u)*VARPHI ); % overall marginal costs in steady-state
31 | f(5) = z - (1-u)*VARPHI*y*dp; % emissions in steady-state
32 | end
33 |
34 | end
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_symdecls.inc:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % common declarations and equations
5 | % =========================================================================
6 | % Willi Mutschler (willi@mutschler.eu)
7 | % Version: May 5, 2023
8 | % =========================================================================
9 |
10 | %-------------------------------------------------------------------------%
11 | % declare variables and parameters
12 | %-------------------------------------------------------------------------%
13 | var
14 | a // total factor productivity
15 | c // consumption
16 | ca_y // abatement cost ratio
17 | dp // price efficiency distortion
18 | g // public consumption
19 | iv // investment
20 | k // capital
21 | l // labor
22 | m // pollution stock
23 | mc // overall marginal costs
24 | pstar // reset price
25 | pz // unit cost of emissions (in real terms)
26 | rnom // nominal interest rate
27 | rk // real rental rate of capital
28 | t // lump-sum taxes
29 | u // abatement effort
30 | w // real wage
31 | x // recursive price setting auxiliary sum 1
32 | y // output
33 | z // emissions
34 | eta // monetary policy shock
35 | Gamma_m // damage function
36 | Theta // recursive price setting auxiliary sum 2
37 | pie // inflation
38 | Psi // marginal cost component related to capital and labor
39 | Omega // recursive price setting auxiliary sum 3
40 | q // tobin''s q
41 | welf // recursive welfare
42 | ;
43 |
44 | predetermined_variables k; // paper uses beginning-of-period timing for capital
45 |
46 | varexo
47 | eps_a // innovation to total factor productivity
48 | eps_g // innovation to public spending rule
49 | eps_eta // innovation to monetary policy shock
50 | ;
51 |
52 | parameters
53 | ALPHA // bias towards capital in production
54 | BETA // discount factor
55 | DELTA_K // depreciation rate of capital
56 | GAMMA_I // capital adjustment cost
57 | PHI // inverse Frisch elasticity
58 | THETA // Dixit-Stiglitz price elasticity
59 | XI // Calvo probability
60 | A // target for steady-state technology
61 | MU_L // utility weight for labor
62 | IOTA_PI // interest rate inflation sensitivity
63 | DELTA_M // pollution decay
64 | VARPHI // emissions per unit of output
65 | PHI_1 // abatement cost function coefficient 1
66 | PHI_2 // abatement cost function coefficient 2
67 | GAMMA_0 // damage function intercept coefficient
68 | GAMMA_1 // damage function linear coefficient
69 | GAMMA_2 // damage function quadratic coefficient
70 | RHO_A // persistence total factor productivity process
71 | RHO_G // persistence government consumption rule
72 | RHO_ETA // persistence monetary policy shock
73 |
74 | TARGET_PIE // target for inflation
75 | TARGET_GSHARE // target for government consumption to output ratio
76 | TARGET_M // target for steady-state pollution stock
77 | TARGET_ZSHARE // target for steady-state emissions
78 | ZSTAR // target for steady-state emissions rest of the world
79 | TARGET_INTENSITY // steady-state emissions to output ratio
80 | CARBON_TAX // steady-state carbon tax
81 | ;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl2_environmental_policy.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Annicchiarico and Di Dio (2015) - Environmental policy and macroeconomic
3 | % dynamics in a new Keynesian model
4 | % steady-state of environmental policy model variant
5 | % replicates table 2 right column
6 | % =========================================================================
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: May 5, 2023
9 | % =========================================================================
10 | @#define CAP_AND_TRADE = 1 // pick any policy
11 |
12 | @#include "ann_dio_2015_symdecls.inc"
13 | % switch types to access old g in steady_state_model block
14 | change_type(parameters) g ;
15 | change_type(var) TARGET_GSHARE;
16 |
17 | @#include "ann_dio_2015_modeleqs.inc"
18 |
19 | %-------------------------------------------------------------------------%
20 | % calibration via new steady-state
21 | %-------------------------------------------------------------------------%
22 | load_params_and_steady_state('ann_dio_2015_calib_no_policy.inc'); % start from no policy calibration
23 |
24 | steady_state_model;
25 | z_old = TARGET_ZSHARE*DELTA_M*TARGET_M; % get old emissions from parameters
26 | z = (1-0.2)*z_old; % new emissions target as outlined in the calibration section
27 | TARGET_M = (z + ZSTAR)/DELTA_M; % update parameter
28 | TARGET_ZSHARE = z/(DELTA_M*TARGET_M); % update parameter
29 | m = TARGET_M; % new pollution stock
30 | Gamma_m = GAMMA_0 + GAMMA_1*m + GAMMA_2*m^2; % damage function in steady-state
31 | a = A; % tfp in steady-state
32 | eta = 1; % monetary policy shock in steady-state
33 | pie = TARGET_PIE; % monetary policy rule in steady-state
34 | q = 1; % investment Euler equation in steady-state
35 | rk = 1/BETA -q*(1-DELTA_K); % capital Euler equation in steady-state
36 | rnom = pie/BETA; % bond Euler equation in steady-state
37 | pstar = ( (1-XI*pie^(THETA-1)) / (1-XI) )^(1/(1-THETA)); % law of motion optimal reset price in steady-state
38 | dp = (1-XI)*pstar^(-THETA) / (1-XI*pie^THETA); % law of motion price dispersion in steady-state
39 | x_plus_Omega_over_Theta = (THETA-1)/THETA*pstar; % recursive price setting in steady-state
40 | mc = (1-XI*BETA*pie^THETA)/(1-XI*BETA*pie^(THETA-1)) * x_plus_Omega_over_Theta; % recursive price setting in steady-state combined with overall marginal costs
41 | [u,pz,Psi,ca_y,y,c,l,k,iv,w] = ann_dio_2015_steadystate_helper(z,Gamma_m,rk,mc,dp,g, DELTA_K,ALPHA,PHI,MU_L,A,VARPHI,PHI_1,PHI_2);
42 | x = c^(-1)*Psi*y/(1-XI*BETA*pie^THETA); % recursive price setting auxiliary sum 1 in steady-state
43 | Theta = c^(-1)*y/(1-XI*BETA*pie^(THETA-1)); % recursive price setting auxiliary sum 2 in steady-state
44 | Omega = c^(-1)*(PHI_1*u^PHI_2+pz*(1-u)*VARPHI)*y/(1-XI*BETA*pie^THETA); % recursive price setting auxiliary sum 3 in steady-state
45 | t = g - pz*z; % fiscal budget in steady-state
46 | welf = ( log(c) - MU_L*l^(1+PHI)/(1+PHI) ) / (1-BETA); % recursive welfare in steady-state
47 | TARGET_GSHARE = g/y; % update parameter
48 | TARGET_INTENSITY = z/y;
49 | CARBON_TAX = pz;
50 | end;
51 | steady;
52 | save_params_and_steady_state('ann_dio_2015_calib_environmental_policy.inc');
53 |
54 | %-------------------------------------------------------------------------%
55 | % check calibration: replicate table 2 for environmental policy case
56 | %-------------------------------------------------------------------------%
57 | fprintf('\n\nCHECK CALIBRATION\n');
58 | varlist_tbl2 = varlist_indices({'y','c','iv','l','mc','z','m','u','pz','ca_y','Gamma_m','welf'},M_.endo_names);
59 | tbl2 = array2table(oo_.steady_state(varlist_tbl2),...
60 | 'RowNames', M_.endo_names(varlist_tbl2),...
61 | 'VariableNames',{'Table 2'});
62 | format long; disp(tbl2); format short;
63 | fprintf(' steady-state public consumption to GDP ratio: %f\n', oo_.steady_state(M_.endo_names=="TARGET_GSHARE"));
64 | fprintf(' steady-state private consumption to GDP ratio: %f\n', oo_.steady_state(M_.endo_names=="c")/oo_.steady_state(M_.endo_names=="y"));
65 | fprintf('\n\n');
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/as_irf_a.mod:
--------------------------------------------------------------------------------
1 | @#define CAP_AND_TRADE
2 | @#include "ann_dio_2015_symdecls.inc"
3 | @#include "ann_dio_2015_modeleqs.inc"
4 |
5 | % calibration
6 | %load_params_and_steady_state('ann_dio_2015_calib_no_policy.inc');
7 | load_params_and_steady_state('ann_dio_2015_calib_environmental_policy.inc');
8 | steady;
9 |
10 | shocks;
11 | var eps_a = 1;
12 | var eps_g = 1;
13 | var eps_eta = 1;
14 | end;
15 | stoch_simul(order=1,irf=21) y c iv l mc z u pz;
--------------------------------------------------------------------------------
/progs/replications/Annicchiarico_DiDio_2015/fig1_fig2.m:
--------------------------------------------------------------------------------
1 | %% no policy
2 | dynare ann_dio_2015_irfs_no_policy;
3 | for jvar = 1:size(var_list_,1)
4 | for jexo = 1:2
5 | no_policy.(M_.exo_names{jexo}).(var_list_{jvar}) = oo_.irfs.(sprintf('%s_%s',var_list_{jvar},M_.exo_names{jexo}))./oo_.steady_state(M_.endo_names==string(var_list_{jvar}));
6 | end
7 | end
8 | clearvars -except no_policy;
9 |
10 | %% cap and trade
11 | dynare ann_dio_2015_irfs_cap_and_trade;
12 | for jvar = 1:size(var_list_,1)
13 | for jexo = 1:2
14 | cap_and_trade.(M_.exo_names{jexo}).(var_list_{jvar}) = oo_.irfs.(sprintf('%s_%s',var_list_{jvar},M_.exo_names{jexo}))./oo_.steady_state(M_.endo_names==string(var_list_{jvar}));
15 | end
16 | end
17 | clearvars -except no_policy cap_and_trade;
18 |
19 | %% intensity target
20 | dynare ann_dio_2015_irfs_intensity_target;
21 | for jvar = 1:size(var_list_,1)
22 | for jexo = 1:2
23 | intensity_target.(M_.exo_names{jexo}).(var_list_{jvar}) = oo_.irfs.(sprintf('%s_%s',var_list_{jvar},M_.exo_names{jexo}))./oo_.steady_state(M_.endo_names==string(var_list_{jvar}));
24 | end
25 | end
26 | clearvars -except no_policy cap_and_trade intensity_target;
27 |
28 | %% tax policy
29 | dynare ann_dio_2015_irfs_tax_policy;
30 | for jvar = 1:size(var_list_,1)
31 | for jexo = 1:2
32 | tax_policy.(M_.exo_names{jexo}).(var_list_{jvar}) = oo_.irfs.(sprintf('%s_%s',var_list_{jvar},M_.exo_names{jexo}))./oo_.steady_state(M_.endo_names==string(var_list_{jvar}));
33 | end
34 | end
35 | clearvars -except no_policy cap_and_trade intensity_target tax_policy var_list_;
36 |
37 | %% figures
38 | TITLES = ["Output", "Consumption", "Investment", "Labor",...
39 | "Marginal Cost", "Emissions", "Abatement Effort", "Permit Price"];
40 |
41 | fig_1a = figure(name='Impulse responses to a technology shock (a)');
42 | for ip = 1:size(var_list_,1)
43 | subplot(2,4,ip)
44 | hold on;
45 | plot(0:1:20, no_policy.eps_a.(var_list_{ip}),'b' ,'LineWidth',1.5);
46 | plot(0:1:20, cap_and_trade.eps_a.(var_list_{ip}),'b:','LineWidth',1.5);
47 | title(TITLES(ip))
48 | legend('no policy','cap-and-trade','Location','SouthWest','fontsize',8);
49 | set(gca,'FontSize',12)
50 | end
51 |
52 | fig_1b = figure(name='Impulse responses to a technology shock (b)');
53 | for ip = 1:size(var_list_,1)
54 | subplot(2,4,ip)
55 | hold on;
56 | plot(0:1:20, intensity_target.eps_a.(var_list_{ip}),'b' ,'LineWidth',1.5);
57 | plot(0:1:20, tax_policy.eps_a.(var_list_{ip}),'b:*','LineWidth',1.5);
58 | title(TITLES(ip))
59 | legend('intensity target','tax','Location','SouthWest','fontsize',8);
60 | set(gca,'FontSize',12)
61 | end
62 |
63 | fig_2a = figure(name='Impulse responses to a government consumption shock (a)');
64 | for ip = 1:size(var_list_,1)
65 | subplot(2,4,ip)
66 | hold on;
67 | plot(0:1:20, no_policy.eps_g.(var_list_{ip}),'b' ,'LineWidth',1.5);
68 | plot(0:1:20, cap_and_trade.eps_g.(var_list_{ip}),'b:','LineWidth',1.5);
69 | title(TITLES(ip))
70 | legend('no policy','cap-and-trade','Location','SouthWest','fontsize',8);
71 | set(gca,'FontSize',12)
72 | end
73 |
74 | fig_2b = figure(name='Impulse responses to a government consumption shock (b)');
75 | for ip = 1:size(var_list_,1)
76 | subplot(2,4,ip)
77 | hold on;
78 | plot(0:1:20, intensity_target.eps_g.(var_list_{ip}),'b' ,'LineWidth',1.5);
79 | plot(0:1:20, tax_policy.eps_g.(var_list_{ip}),'b:*','LineWidth',1.5);
80 | title(TITLES(ip))
81 | legend('intensity target','tax','Location','SouthWest','fontsize',8);
82 | set(gca,'FontSize',12)
83 | end
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/as_fig11.mod:
--------------------------------------------------------------------------------
1 | @#define LOGUTILITY=1
2 | @#include "ascari_sbordone_2014_common.mod"
3 | @#include "ascari_sbordone_2014_calib_common.inc"
4 |
5 | VARPHI = 1;
6 | % monetary policy according to footnote 67
7 | PHI_PI = 2;
8 | PHI_Y = 0.5/4;
9 | RHO_I = 0.8;
10 |
11 | %specify parameters for which to map sensitivity
12 | set_param_value('TREND_INFLATION',6);
13 | estimated_params;
14 | PHI_PI, uniform_pdf,,, 0,6; %draw uniformly from 0 to 6
15 | PHI_Y, uniform_pdf,,,-1,6; %draw uniformly from -1 to 6
16 | end;
17 | varobs log_y log_pi log_r; % for analysis of BK conditions, it does not matter which variables are observed
18 | dynare_sensitivity(prior_range=0,stab=1,nsam=3000);
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/as_fig14.mod:
--------------------------------------------------------------------------------
1 | @#define LOGUTILITY=1
2 | @#include "ascari_sbordone_2014_common.mod"
3 | @#include "ascari_sbordone_2014_calib_common.inc"
4 |
5 | VARPHI = 1;
6 | % monetary policy according to footnote 67
7 | PHI_PI = 2;
8 | PHI_Y = 0.5/4;
9 | RHO_I = 0.8;
10 |
11 | steady;
12 |
13 | shocks;
14 | var eps_nu = 1; % 1 percent monetary policy shock, because interest rate is in logs
15 | var eps_a = 0;
16 | var eps_zeta = 0;
17 | end;
18 |
19 | TREND_INFLATION=0;
20 | stoch_simul(order=1,irf=7,irf_plot_threshold=0,nograph) log_y log_pi log_r log_s log_i nu;
21 | irf_0_trend_infl = oo_.irfs;
22 |
23 | TREND_INFLATION=2;
24 | stoch_simul(order=1,irf=7,irf_plot_threshold=0,nograph) log_y log_pi log_r log_s log_i nu;
25 | irf_2_trend_infl = oo_.irfs;
26 |
27 | TREND_INFLATION=4;
28 | stoch_simul(order=1,irf=7,irf_plot_threshold=0,nograph) log_y log_pi log_r log_s log_i nu;
29 | irf_4_trend_infl = oo_.irfs;
30 |
31 | TREND_INFLATION=6;
32 | stoch_simul(order=1,irf=7,irf_plot_threshold=0,nograph) log_y log_pi log_r log_s log_i nu;
33 | irf_6_trend_infl = oo_.irfs;
34 |
35 |
36 | figure('Name','Figure 14: Impulse Response Functions to a 1 Percent Positive Monetary Policy Shock ')
37 | subplot(2,2,1)
38 | plot(0:options_.irf,[0 irf_0_trend_infl.log_y_eps_nu],'k-',...
39 | 0:options_.irf,[0 irf_2_trend_infl.log_y_eps_nu],'b--',...
40 | 0:options_.irf,[0 irf_4_trend_infl.log_y_eps_nu],'r-.',...
41 | 0:options_.irf,[0 irf_6_trend_infl.log_y_eps_nu],'*-');
42 | ylim([-2.5 0.5]);
43 | title('Output');
44 | subplot(2,2,2)
45 | plot(0:options_.irf,[0 irf_0_trend_infl.log_pi_eps_nu],'k-',...
46 | 0:options_.irf,[0 irf_2_trend_infl.log_pi_eps_nu],'b--',...
47 | 0:options_.irf,[0 irf_4_trend_infl.log_pi_eps_nu],'r-.',...
48 | 0:options_.irf,[0 irf_6_trend_infl.log_pi_eps_nu],'*-');
49 | ylim([-0.80 0]);
50 | title('Inflation');
51 | subplot(2,2,3)
52 | plot(0:options_.irf,[0 irf_0_trend_infl.log_r_eps_nu],'k-',...
53 | 0:options_.irf,[0 irf_2_trend_infl.log_r_eps_nu],'b--',...
54 | 0:options_.irf,[0 irf_4_trend_infl.log_r_eps_nu],'r-.',...
55 | 0:options_.irf,[0 irf_6_trend_infl.log_r_eps_nu],'*-');
56 | ylim([0 1.4]);
57 | title('Real Interest Rate');
58 | subplot(2,2,4)
59 | hh = plot(0:options_.irf,[0 irf_0_trend_infl.log_s_eps_nu],'k-',...
60 | 0:options_.irf,[0 irf_2_trend_infl.log_s_eps_nu],'b--',...
61 | 0:options_.irf,[0 irf_4_trend_infl.log_s_eps_nu],'r-.',...
62 | 0:options_.irf,[0 irf_6_trend_infl.log_s_eps_nu],'*-');
63 | ylim([-0.8 0]);
64 | title('Price Dispersion');
65 | legend(hh,'\pi=0%','\pi=2%','\pi=4%','\pi=6%');
66 |
67 |
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_calib_common.inc:
--------------------------------------------------------------------------------
1 | % fix labor to 1/3 to compute labor disutility parameter under benchmark of
2 | % zero trend inflation steady-state with Frisch elasticity of 1
3 | N_SS = 1/3;
4 | BETA_SS = 0.99;
5 | ALPHA_SS = 0;
6 | THETA_SS = 0.75;
7 | VAREPSILON_SS = 10;
8 | SIGMA_SS = 1;
9 | VARPHI_SS = 1;
10 | VARRHO_SS = 0;
11 | TREND_INFLATION_SS = 0;
12 | PIBAR = (1+0/100)^(1/4); % set to reflect quarterly inflation
13 | PSTAR_SS = ((1-THETA_SS*PIBAR^((VAREPSILON_SS-1)*(1-VARRHO_SS)))/(1-THETA_SS))^(1/(1-VAREPSILON_SS));
14 | S_SS = (1-THETA_SS)/(1-THETA_SS*PIBAR^((VAREPSILON_SS*(1-VARRHO_SS))/(1-ALPHA_SS)))*PSTAR_SS^(-VAREPSILON_SS/(1^-ALPHA_SS));
15 | Y_SS = (N_SS/S_SS)^(1-ALPHA_SS);
16 | A_SS = 1;
17 | PHI_SS = Y_SS^(1-SIGMA_SS)/(1-THETA_SS*BETA_SS*PIBAR^((VAREPSILON_SS-1)*(1-VARRHO_SS)));
18 | PSI_SS = PSTAR_SS^(1+VAREPSILON_SS*ALPHA_SS/(1-ALPHA_SS))*PHI_SS/(VAREPSILON_SS/((VAREPSILON_SS-1)*(1-ALPHA_SS)));
19 | W_SS = PSI_SS*(1-THETA_SS*BETA_SS*PIBAR^((VAREPSILON_SS*(1-VARRHO_SS))/(1-ALPHA_SS)))/(A_SS^(-1/(1-ALPHA_SS))*Y_SS^(1/(1-ALPHA_SS)-SIGMA_SS));
20 | D_N = W_SS/(N_SS^VARPHI_SS*Y_SS^SIGMA_SS);
21 |
22 | % actual calibration set according to footnote 36
23 | BETA = 0.99;
24 | ALPHA = 0;
25 | THETA = 0.75;
26 | VAREPSILON = 10;
27 | @#ifdef LOGUTILITY
28 | SIGMA = 1;
29 | @#else
30 | SIGMA = 2;
31 | @#endif
32 | RHO_NU = 0;
33 | RHO_A = 0;
34 | RHO_ZETA = 0;
35 |
36 | VARRHO = 0;
37 | TREND_INFLATION = 0; % initialize
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11.mod:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %%%%%% Generate Figure 11: The Determinacy Region and Trend Inflation
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | @#define LOGUTILITY=1
5 | @#include "ascari_sbordone_2014_common.mod"
6 | @#include "ascari_sbordone_2014_calib_common.inc"
7 | VARPHI = 1;
8 | % monetary policy according to footnote 67
9 | PHI_PI = 2;
10 | PHI_Y = 0.5/4;
11 | RHO_I = 0;
12 |
13 | % phi_pi_vec = linspace(0,5,200);
14 | % phi_y_vec = linspace(-1,5,200);
15 | % [phi_pi_mat,phi_y_mat] = ndgrid(phi_pi_vec,phi_y_vec);
16 | % trend_inflation_vector = [0,2,4,6,8];
17 | % Z_plot_total = zeros(size(phi_pi_mat));
18 | % for trend_inflation_iter=1:length(trend_inflation_vector)
19 | % set_param_value('TREND_INFLATION',trend_inflation_vector(trend_inflation_iter));
20 | % info_mat=NaN(size(phi_pi_mat));
21 | % for phi_pi_iter=1:length(phi_pi_vec)
22 | % for phi_y_iter=1:length(phi_y_vec)
23 | % set_param_value('PHI_PI',phi_pi_mat(phi_pi_iter,phi_y_iter));
24 | % set_param_value('PHI_Y',phi_y_mat(phi_pi_iter,phi_y_iter));
25 | % [dr,info] = resol(0,M_,options_,oo_);
26 | % info_mat(phi_pi_iter,phi_y_iter) = info(1);
27 | % end
28 | % end
29 | % Z_plot = zeros(size(info_mat));
30 | % Z_plot(info_mat==0) = 1;
31 | % figure
32 | % contourf(phi_pi_mat,phi_y_mat,Z_plot,1)
33 | % Z_plot_total(info_mat==0) = trend_inflation_iter;
34 | % xlabel('\phi_\pi')
35 | % ylabel('\phi_y')
36 | % title([num2str(trend_inflation_vector(trend_inflation_iter)) '%'])
37 | % end
38 | %
39 | % figure('Name','Figure 11: The Determinacy Region and Trend Inflation')
40 | % contourf(phi_pi_mat,phi_y_mat,Z_plot_total,5);
41 | % colormap(hot);
42 |
43 | estimated_params;
44 | PHI_PI,uniform_pdf,(0+6)/2,sqrt(12)^(-1)*(6-0);
45 | PHI_Y,uniform_pdf,((-1)+6)/2,sqrt(12)^(-1)*(6-(-1));
46 | end;
47 |
48 | varobs log_y log_pi; //some observables must be specified for sensitivity command, inessential for results
49 | options_.nograph=0; %enable graphs again
50 |
51 | trend_inflation_vector = [0,2,4,6,8];
52 | for trend_inflation_iter=1:length(trend_inflation_vector)
53 | set_param_value('TREND_INFLATION',trend_inflation_vector(trend_inflation_iter));
54 | dynare_sensitivity(prior_range=0,stab=1,nsam=5000);
55 | end
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/Output/ascari_sbordone_2014_fig11_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/Output/ascari_sbordone_2014_fig11_results.mat
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/checksum:
--------------------------------------------------------------------------------
1 | 13295204270845232378
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/gsa/ascari_sbordone_2014_fig11_prior.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/gsa/ascari_sbordone_2014_fig11_prior.mat
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/gsa/prior_ok.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/gsa/prior_ok.mat
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/prior/definition.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig11/prior/definition.mat
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig13.log:
--------------------------------------------------------------------------------
1 | Starting Dynare (version 5.4).
2 | Calling Dynare with arguments: none
3 | Starting preprocessing of the model file ...
4 | Found 19 equation(s).
5 | Evaluating expressions...done
6 | Computing static model derivatives (order 1).
7 | Computing dynamic model derivatives (order 1).
8 | Processing outputs ...
9 | done
10 | Preprocessing completed.
11 |
12 | [Warning: Some of the parameters have no value (YBAR, IBAR) when using steady. If these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able to solve the model. Note that simul,
13 | perfect_foresight_setup, and perfect_foresight_solver do not automatically call the steady state file.]
14 |
15 | STEADY-STATE RESULTS:
16 |
17 | log_y -2.19722
18 | log_i -4.59512
19 | log_pi 0
20 | log_n -2.19722
21 | log_w -0.105361
22 | log_pstar 0
23 | log_psi 1.25138
24 | log_phi 1.35674
25 | log_mc -0.105361
26 | log_r 0.0100503
27 | log_s 0
28 | log_a 0
29 | zeta 0
30 | nu 0
31 | log_atilde 0
32 | utility -309.722
33 | log_average_markup 0.105361
34 | log_marginal_markup 0.105361
35 | log_price_adjustment_gap 0
36 | [Warning: Aggregate variance and sum of variances by shocks differ by more than 0.01 %]
37 | [> In th_autocovariances (line 206)
38 | In disp_th_moments (line 40)
39 | In stoch_simul (line 210)
40 | In ascari_sbordone_2014_fig13.driver (line 428)
41 | In dynare (line 278)]
42 | Total computing time : 0h00m00s
43 | Note: warning(s) encountered in MATLAB/Octave code
44 |
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig13/Output/ascari_sbordone_2014_fig13_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig13/Output/ascari_sbordone_2014_fig13_results.mat
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig13/checksum:
--------------------------------------------------------------------------------
1 | 4418662995297134513
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig14.log:
--------------------------------------------------------------------------------
1 | Starting Dynare (version 5.4).
2 | Calling Dynare with arguments: none
3 | Starting preprocessing of the model file ...
4 | Found 19 equation(s).
5 | Evaluating expressions...done
6 | Computing static model derivatives (order 1).
7 | Computing dynamic model derivatives (order 1).
8 | Processing outputs ...
9 | done
10 | Preprocessing completed.
11 |
12 | [Warning: Some of the parameters have no value (YBAR, IBAR) when using steady. If these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able to solve the model. Note that simul,
13 | perfect_foresight_setup, and perfect_foresight_solver do not automatically call the steady state file.]
14 |
15 | STEADY-STATE RESULTS:
16 |
17 | log_y -1.09861
18 | log_i -4.59512
19 | log_pi 0
20 | log_n -1.09861
21 | log_w -0.105361
22 | log_pstar 0
23 | log_psi 1.25138
24 | log_phi 1.35674
25 | log_mc -0.105361
26 | log_r 0.0100503
27 | log_s 0
28 | log_a 0
29 | zeta 0
30 | nu 0
31 | log_atilde 0
32 | utility -154.861
33 | log_average_markup 0.105361
34 | log_marginal_markup 0.105361
35 | log_price_adjustment_gap 0
36 | Total computing time : 0h00m00s
37 | Note: warning(s) encountered in MATLAB/Octave code
38 |
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig14.mod:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %%%%%% Replicate Figure 14: Impulse Response Functions to a 1 Percent Positive Monetary Policy Shock
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | @#define LOGUTILITY=1
5 | @#include "ascari_sbordone_2014_common.mod"
6 | @#include "ascari_sbordone_2014_calib_common.inc"
7 | VARPHI = 1;
8 | % monetary policy according to footnote 67
9 | PHI_PI = 2;
10 | PHI_Y = 0.5/4;
11 | RHO_I = 0.8;
12 | steady;
13 |
14 | shocks;
15 | var eps_nu; stderr 1; % 1 percent monetary policy shock as interest rate is in logs
16 | var eps_a; stderr 0;
17 | var eps_zeta; stderr 0;
18 | end;
19 |
20 | set_param_value('TREND_INFLATION',0)
21 | stoch_simul(irf=7,order=1,irf_plot_threshold=0,nograph,noprint) log_y log_pi log_r log_s log_i nu;
22 | irf_0_trend_infl=oo_.irfs;
23 | set_param_value('TREND_INFLATION',2)
24 | stoch_simul(irf=7,order=1,irf_plot_threshold=0,nograph,noprint) log_y log_pi log_r log_s log_i nu;
25 | irf_2_trend_infl=oo_.irfs;
26 | set_param_value('TREND_INFLATION',4)
27 | stoch_simul(irf=7,order=1,irf_plot_threshold=0,nograph,noprint) log_y log_pi log_r log_s log_i nu;
28 | irf_4_trend_infl=oo_.irfs;
29 | set_param_value('TREND_INFLATION',6)
30 | stoch_simul(irf=7,order=1,irf_plot_threshold=0,nograph,noprint) log_y log_pi log_r log_s log_i nu;
31 | irf_6_trend_infl=oo_.irfs;
32 |
33 | figure('Name','Figure 14: Impulse Response Functions to a 1 Percent Positive Monetary Policy Shock ')
34 | subplot(2,2,1)
35 | plot(0:options_.irf,[0 irf_0_trend_infl.log_y_eps_nu],'k-',...
36 | 0:options_.irf,[0 irf_2_trend_infl.log_y_eps_nu],'b--',...
37 | 0:options_.irf,[0 irf_4_trend_infl.log_y_eps_nu],'r-.',...
38 | 0:options_.irf,[0 irf_6_trend_infl.log_y_eps_nu],'*-');
39 | ylim([-2.5 0.5]);
40 | title('Output');
41 | subplot(2,2,2)
42 | plot(0:options_.irf,[0 irf_0_trend_infl.log_pi_eps_nu],'k-',...
43 | 0:options_.irf,[0 irf_2_trend_infl.log_pi_eps_nu],'b--',...
44 | 0:options_.irf,[0 irf_4_trend_infl.log_pi_eps_nu],'r-.',...
45 | 0:options_.irf,[0 irf_6_trend_infl.log_pi_eps_nu],'*-');
46 | ylim([-0.80 0]);
47 | title('Inflation');
48 | subplot(2,2,3)
49 | plot(0:options_.irf,[0 irf_0_trend_infl.log_r_eps_nu],'k-',...
50 | 0:options_.irf,[0 irf_2_trend_infl.log_r_eps_nu],'b--',...
51 | 0:options_.irf,[0 irf_4_trend_infl.log_r_eps_nu],'r-.',...
52 | 0:options_.irf,[0 irf_6_trend_infl.log_r_eps_nu],'*-');
53 | ylim([0 1.4]);
54 | title('Real Interest Rate');
55 | subplot(2,2,4)
56 | hh = plot(0:options_.irf,[0 irf_0_trend_infl.log_s_eps_nu],'k-',...
57 | 0:options_.irf,[0 irf_2_trend_infl.log_s_eps_nu],'b--',...
58 | 0:options_.irf,[0 irf_4_trend_infl.log_s_eps_nu],'r-.',...
59 | 0:options_.irf,[0 irf_6_trend_infl.log_s_eps_nu],'*-');
60 | ylim([-0.8 0]);
61 | title('Price Dispersion');
62 | legend(hh,'\pi=0%','\pi=2%','\pi=4%','\pi=6%');
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig14/Output/ascari_sbordone_2014_fig14_results.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wmutschl/Computational-Macroeconomics/674182846c2982b5df7bf4d472513886ea41f0bc/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig14/Output/ascari_sbordone_2014_fig14_results.mat
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig14/checksum:
--------------------------------------------------------------------------------
1 | 4418662995297134513
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig7.mod:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %%%%%% Figure 7: The Cost of Price Dispersion
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | @#define LOGUTILITY=1
5 | @#include "ascari_sbordone_2014_common.mod"
6 | @#include "ascari_sbordone_2014_calib_common.inc"
7 | VARPHI = 1;
8 | % monetary policy according to footnote 67
9 | PHI_PI = 2;
10 | PHI_Y = 0.5/4;
11 | RHO_I = 0.8;
12 | figure('Name','The Cost of Price Dispersion')
13 |
14 | trend_inflation_vector = [2,4];
15 | theta_vector = linspace(0.5,0.87,50);
16 | output_loss = NaN(length(theta_vector),2);
17 | for trend_inflation_iter=1:2
18 | set_param_value('TREND_INFLATION',trend_inflation_vector(trend_inflation_iter));
19 | for iter=1:length(theta_vector)
20 | set_param_value('THETA',theta_vector(iter));
21 | steady;
22 | output_loss(iter,trend_inflation_iter) = oo_.steady_state(strmatch('log_atilde',M_.endo_names,'exact'))*100;
23 | end
24 | end
25 | subplot(1,3,1)
26 | plot(theta_vector,output_loss(:,1)-output_loss(1,1),'-',...
27 | theta_vector,output_loss(:,2)-output_loss(1,2),'--'); % normalize relative to first value
28 | xlabel('\theta');
29 | ylim([-10 0]);
30 | xlim([0.5 0.9]);
31 |
32 | set_param_value('THETA',0.75);
33 | trend_inflation_vector = [2,4];
34 | varepsilon_vector = linspace(1.01,14,50);
35 | output_loss = NaN(length(varepsilon_vector),2);
36 | for trend_inflation_iter=1:2
37 | set_param_value('TREND_INFLATION',trend_inflation_vector(trend_inflation_iter));
38 | for iter=1:length(varepsilon_vector)
39 | set_param_value('VAREPSILON',varepsilon_vector(iter));
40 | steady;
41 | output_loss(iter,trend_inflation_iter) = oo_.steady_state(strmatch('log_atilde',M_.endo_names,'exact'))*100;
42 | end
43 | end
44 | subplot(1,3,2)
45 | plot(varepsilon_vector,output_loss(:,1)-output_loss(1,1),'-',...
46 | varepsilon_vector,output_loss(:,2)-output_loss(1,2),'--'); %normalize relative to first value
47 | xlabel('\epsilon');
48 | ylim([-2 0]);
49 | xlim([0 15]);
50 |
51 | set_param_value('THETA',0.75); % reset to baseline
52 | set_param_value('VAREPSILON',10); % reset to baseline
53 | trend_inflation_vector = 0:0.5:8;
54 | output_loss = NaN(length(trend_inflation_vector),1);
55 | for iter=1:length(trend_inflation_vector)
56 | set_param_value('TREND_INFLATION',trend_inflation_vector(iter));
57 | steady;
58 | output_loss(iter,1) = oo_.steady_state(strmatch('log_atilde',M_.endo_names,'exact'))*100;
59 | end
60 | subplot(1,3,3)
61 | plot(trend_inflation_vector,output_loss)
62 | xlabel('Trend Inflation');
63 | ylim([-8 0]);
64 | xlim([0 10]);
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_fig8.mod:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %%%%%% Generate Figure 8: Trend Inflation and Steady-State Variables
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | @#define LOGUTILITY=1
5 | @#include "ascari_sbordone_2014_common.mod"
6 | @#include "ascari_sbordone_2014_calib_common.inc"
7 | VARPHI = 1;
8 | % monetary policy according to footnote 67
9 | PHI_PI = 2;
10 | PHI_Y = 0.5/4;
11 | RHO_I = 0.8;
12 |
13 | verbatim;
14 | figure('Name','Trend Inflation and Steady-State Variables');
15 | trend_inflation_vector = 0:0.5:8;
16 | utility = NaN(length(trend_inflation_vector),1);
17 | output = NaN(length(trend_inflation_vector),1);
18 | marg_markup = NaN(length(trend_inflation_vector),1);
19 | ave_markup = NaN(length(trend_inflation_vector),1);
20 | price_adjust_gap = NaN(length(trend_inflation_vector),1);
21 | for iter=1:length(trend_inflation_vector)
22 | set_param_value('TREND_INFLATION',trend_inflation_vector(iter));
23 | steady;
24 | utility(iter,1) = oo_.steady_state(strmatch('utility',M_.endo_names,'exact'));
25 | output(iter,1) = oo_.steady_state(strmatch('log_y',M_.endo_names,'exact'));
26 | marg_markup(iter,1) = oo_.steady_state(strmatch('log_marginal_markup',M_.endo_names,'exact'));
27 | ave_markup(iter,1) = oo_.steady_state(strmatch('log_average_markup',M_.endo_names,'exact'));
28 | price_adjust_gap(iter,1) = oo_.steady_state(strmatch('log_price_adjustment_gap',M_.endo_names,'exact'));
29 | end
30 |
31 | subplot(1,3,1)
32 | plot(trend_inflation_vector,(output-output(1,1))*100);
33 | xlabel('Annualized Trend Inflation');
34 | ylabel('Steady-state output');
35 | subplot(1,3,2)
36 | plot(trend_inflation_vector,(ave_markup-ave_markup(1,1))*100,'-',...
37 | trend_inflation_vector,(marg_markup-marg_markup(1,1))*100,'--',...
38 | trend_inflation_vector,(price_adjust_gap-price_adjust_gap(1,1))*100,'.');
39 | xlabel('Annualized Trend Inflation');
40 | ylabel('SS price adj. gap, marg. and ave. markup');
41 | subplot(1,3,3)
42 | plot(trend_inflation_vector,(utility-utility(1,1))./abs(utility(1,1))*100);
43 | xlabel('Annualized Trend Inflation');
44 | ylabel('Steady-state welfare');
45 | end;
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_moments.log:
--------------------------------------------------------------------------------
1 | Starting Dynare (version 5.4).
2 | Calling Dynare with arguments: none
3 | Starting preprocessing of the model file ...
4 | Found 19 equation(s).
5 | Evaluating expressions...done
6 | Computing static model derivatives (order 1).
7 | Computing dynamic model derivatives (order 1).
8 | Processing outputs ...
9 | done
10 | Preprocessing completed.
11 |
12 | [Warning: Some of the parameters have no value (YBAR, IBAR) when using stoch_simul. If these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able to solve the model. Note that
13 | simul, perfect_foresight_setup, and perfect_foresight_solver do not automatically call the steady state file.]
14 | Output Standard Deviation: 1.298 2.845
15 | Inflation Standard Deviation: 0.413 0.847
16 | Total computing time : 0h00m00s
17 | Note: warning(s) encountered in MATLAB/Octave code
18 |
--------------------------------------------------------------------------------
/progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_moments.mod:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %%%%%% Replicate business cycle moments reported on page 717
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | @#define LOGUTILITY=1
5 | @#include "ascari_sbordone_2014_common.mod"
6 | @#include "ascari_sbordone_2014_calib_common.inc"
7 |
8 | VARPHI = 1;
9 | RHO_A = 0.95;
10 | RHO_I = 0;
11 | PHI_PI = 1.5;
12 | PHI_Y = 0.5/4;
13 |
14 | shocks;
15 | var eps_nu; stderr 0;
16 | var eps_a = 0.45^2;
17 | var eps_zeta; stderr 0;
18 | end;
19 |
20 | set_param_value('TREND_INFLATION',0);
21 | stoch_simul(irf=0,order=1,nograph,noprint) log_y log_pi;
22 | output_var_low_target = oo_.var(strmatch('log_y',var_list_,'exact'),strmatch('log_y',var_list_,'exact'));
23 | inflation_var_low_target = oo_.var(strmatch('log_pi',var_list_,'exact'),strmatch('log_pi',var_list_,'exact'));
24 | set_param_value('TREND_INFLATION',4);
25 | stoch_simul(irf=0,order=1,nograph,noprint) log_y log_pi;
26 | output_var_high_target=oo_.var(strmatch('log_y',var_list_,'exact'),strmatch('log_y',var_list_,'exact'));
27 | inflation_var_high_target=oo_.var(strmatch('log_pi',var_list_,'exact'),strmatch('log_pi',var_list_,'exact'));
28 | fprintf('Output Standard Deviation: \t %4.3f \t %4.3f\n',sqrt(output_var_low_target),sqrt(output_var_high_target));
29 | fprintf('Inflation Standard Deviation: \t %4.3f \t %4.3f\n',sqrt(inflation_var_low_target),sqrt(inflation_var_high_target))
30 |
--------------------------------------------------------------------------------
/progs/replications/Auray_Eyquem_2019/Auray_Eyquem_2019_plots.m:
--------------------------------------------------------------------------------
1 | function Auray_Eyquem_2019_plots(oo_,M_)
2 |
3 | HORIZON = 25;
4 | YLABEL = ["% dev.", "%", "level"];
5 |
6 | figure(name='IRF to 5 year war shock: Macro Variables');
7 | VARLIST_MACRO = ["y","c","inv","k","n","wr","nxy","s","pie"];
8 | VARTITLE_MACRO = ["GDP","Consumption","Investment","Capital Stock","Hours","Real Wage","Net exports to GDP","Terms of Trade","Inflation"];
9 | idxplot = 1;
10 | for j=1:length(VARLIST_MACRO)
11 | subplot(3,3,idxplot);
12 | if ismember(VARLIST_MACRO(j),["nxy"])
13 | plot(1:HORIZON,100*( oo_.endo_simul(M_.endo_names==VARLIST_MACRO(j),1:HORIZON) )...
14 | ,'-k','LineWidth',2);
15 | ylabel(YLABEL(2));
16 | else
17 | plot(1:HORIZON,100*( oo_.endo_simul(M_.endo_names==VARLIST_MACRO(j),1:HORIZON)./oo_.endo_simul(M_.endo_names==VARLIST_MACRO(j),1) -1 )...
18 | ,'-k','LineWidth',2);
19 | ylabel(YLABEL(1));
20 | end
21 | title(VARTITLE_MACRO(j));
22 | idxplot=idxplot+1;
23 | set(gca,'FontSize',14);
24 | end
25 |
26 | figure(name='IRF to 5 year war shock: Policy Variables');
27 | VARLIST_POLICY = ["br_y","mr","invg","g","taun","tauk"];
28 | VARTITLE_POLICY = ["Debt-to-GDP","Real balances","Public invt","Public consumption","Labor tax","Capital tax"];
29 | idxplot = 1;
30 | for j=1:length(VARLIST_POLICY)
31 | subplot(3,2,idxplot);
32 | if ismember(VARLIST_POLICY(j),["br_y"])
33 | plot(1:HORIZON,100*( oo_.endo_simul(M_.endo_names==VARLIST_POLICY(j),1:HORIZON) )...
34 | ,'-k','LineWidth',2);
35 | ylabel(YLABEL(2));
36 | elseif ismember(VARLIST_POLICY(j),["taun","tauk"])
37 | plot(1:HORIZON,100*( oo_.endo_simul(M_.endo_names==VARLIST_POLICY(j),1:HORIZON) )...
38 | ,'-k','LineWidth',2);
39 | ylabel(YLABEL(3));
40 | else
41 | plot(1:HORIZON,100*( oo_.endo_simul(M_.endo_names==VARLIST_POLICY(j),1:HORIZON)./oo_.endo_simul(M_.endo_names==VARLIST_POLICY(j),1) -1 )...
42 | ,'-k','LineWidth',2);
43 | ylabel(YLABEL(1));
44 | end
45 | title(VARTITLE_POLICY(j));
46 | idxplot=idxplot+1;
47 | set(gca,'FontSize',14);
48 | end
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_figures_both.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Replicates Figures 9 and 10 of
3 | % Eichenbaum, Rebelo, and Trabandt (2022, JEDC):
4 | % "Epidemics in the New Keynesian model"
5 | % -------------------------------------------------------------------------
6 | % Willi Mutschler (willi@mutschler.eu)
7 | % Version: May 18, 2023
8 | % =========================================================================
9 |
10 | @#include "ert_model_histval.mod"
11 |
12 | % calibation targets for shares of pi-terms in T-function in SIR model
13 | pi3_shr_target = 2/3; % share of T_0 jump due general infections
14 | pi1_shr_target = (1-pi3_shr_target)/2; % share of T_0 jump due to consumption-based infections
15 | pi2_shr_target = (1-pi3_shr_target)/2; % share of T_0 jump due to work-based infections
16 | [pi1_final,pi2_final,pi3_final] = ert_model_go_calibrate_pi(250,varepsilon,pir,pid,pi1_shr_target,pi2_shr_target,RplusD_target,c_ss,n_ss);
17 |
18 | % use set_param_value to update the parameters in the M_ structure
19 | % changes in pi1 and pi2 are very small, so no need for homotopy
20 | set_param_value('pi1',pi1_final);
21 | set_param_value('pi2',pi2_final);
22 |
23 | % homotopy over pi3 (otherwise the simulation does not converge)
24 | pi3_steps = [pi3_final/3:0.02:pi3_final,pi3_final];
25 | set_param_value('pi3',pi3_final/3); % set initial pi3 to one third of final value
26 |
27 | % re-run perfect_foresight_solver for increasing values of pi3 taking
28 | % previous simulation as initial guess for perfect foresight solver
29 | for pi3_j = pi3_steps
30 | fprintf('pi3 = %f\n',pi3_j);
31 | set_param_value('pi3',pi3_j);
32 | perfect_foresight_solver(maxit=100);
33 | end
34 |
35 | % create figures
36 | plot_also_flex_price_model = true;
37 | ert_model_plot_agg_results("both",M_,oo_,plot_also_flex_price_model);
38 | ert_model_plot_by_type_results("both",M_,oo_);
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_figures_demand.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Replicates Figures 5 and 6 of
3 | % Eichenbaum, Rebelo, and Trabandt (2022, JEDC):
4 | % "Epidemics in the New Keynesian model"
5 | % -------------------------------------------------------------------------
6 | % Willi Mutschler (willi@mutschler.eu)
7 | % Version: May 18, 2023
8 | % =========================================================================
9 |
10 | @#include "ert_model_histval.mod"
11 |
12 | % calibation targets for shares of pi-terms in T-function in SIR model
13 | pi3_shr_target = 2/3; % share of T_0 jump due general infections
14 | pi1_shr_target = (1-pi3_shr_target); % share of T_0 jump due to consumption-based infections
15 | pi2_shr_target = 0; % share of T_0 jump due to work-based infections
16 | [pi1_final,pi2_final,pi3_final] = ert_model_go_calibrate_pi(250,varepsilon,pir,pid,pi1_shr_target,pi2_shr_target,RplusD_target,c_ss,n_ss);
17 |
18 | % use set_param_value to update the parameters in the M_ structure
19 | % changes in pi1 and pi2 are very small, so no need for homotopy
20 | set_param_value('pi1',pi1_final);
21 | set_param_value('pi2',pi2_final);
22 |
23 | % homotopy over pi3 (otherwise the simulation does not converge)
24 | pi3_steps = [pi3_final/3:0.02:pi3_final,pi3_final];
25 | set_param_value('pi3',pi3_final/3); % set initial pi3 to one third of final value
26 |
27 | % re-run perfect_foresight_solver for increasing values of pi3 taking
28 | % previous simulation as initial guess for perfect foresight solver
29 | for pi3_j = pi3_steps
30 | fprintf('pi3 = %f\n',pi3_j);
31 | set_param_value('pi3',pi3_j);
32 | perfect_foresight_solver(maxit=100);
33 | end
34 |
35 | % create figures
36 | plot_also_flex_price_model = false;
37 | ert_model_plot_agg_results("demand",M_,oo_,plot_also_flex_price_model);
38 | ert_model_plot_by_type_results("demand",M_,oo_);
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_figures_supply.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Replicates Figures 7 and 8 of
3 | % Eichenbaum, Rebelo, and Trabandt (2022, JEDC):
4 | % "Epidemics in the New Keynesian model"
5 | % -------------------------------------------------------------------------
6 | % Willi Mutschler (willi@mutschler.eu)
7 | % Version: May 18, 2023
8 | % =========================================================================
9 |
10 | @#include "ert_model_histval.mod"
11 |
12 | % calibation targets for shares of pi-terms in T-function in SIR model
13 | pi3_shr_target = 2/3; % share of T_0 jump due general infections
14 | pi1_shr_target = 0; % share of T_0 jump due to consumption-based infections
15 | pi2_shr_target = (1-pi3_shr_target); % share of T_0 jump due to work-based infections
16 | [pi1_final,pi2_final,pi3_final] = ert_model_go_calibrate_pi(250,varepsilon,pir,pid,pi1_shr_target,pi2_shr_target,RplusD_target,c_ss,n_ss);
17 |
18 | % use set_param_value to update the parameters in the M_ structure
19 | % changes in pi1 and pi2 are very small, so no need for homotopy
20 | set_param_value('pi1',pi1_final);
21 | set_param_value('pi2',pi2_final);
22 |
23 | % homotopy over pi3 (otherwise the simulation does not converge)
24 | pi3_steps = [pi3_final/3:0.02:pi3_final,pi3_final];
25 | set_param_value('pi3',pi3_final/3); % set initial pi3 to one third of final value
26 |
27 | % re-run perfect_foresight_solver for increasing values of pi3 taking
28 | % previous simulation as initial guess for perfect foresight solver
29 | for pi3_j = pi3_steps
30 | fprintf('pi3 = %f\n',pi3_j);
31 | set_param_value('pi3',pi3_j);
32 | perfect_foresight_solver(maxit=100);
33 | end
34 |
35 | % create figures
36 | plot_also_flex_price_model = false;
37 | ert_model_plot_agg_results("supply",M_,oo_,plot_also_flex_price_model);
38 | ert_model_plot_by_type_results("supply",M_,oo_);
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_histval.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Includes the scenario "The impact of an epidemic" into the New Keynesian
3 | % Model of Eichenbaum, Rebelo, and Trabandt (2022, JEDC): "Epidemics in the
4 | % New Keynesian model" by specifying an initial condition such that
5 | % infections break out at time 0.
6 | % This mod file also includes some pretty printing of the initial matrices
7 | % created by Dynare.
8 | % -------------------------------------------------------------------------
9 | % Willi Mutschler (willi@mutschler.eu)
10 | % Version: May 18, 2023
11 | % =========================================================================
12 |
13 | @#include "ert_model_initval.mod"
14 |
15 | %-------------------------------------------------------------------------%
16 | % use histval for initial condition that infections break out at time 0
17 | %-------------------------------------------------------------------------%
18 | histval;
19 | % infections break out at time 0
20 | i(0) = varepsilon; i_flex(0) = varepsilon;
21 | s(0) = 1-varepsilon; s_flex(0) = 1-varepsilon;
22 |
23 | % most variables set at pre-infection steady-state
24 | y(0) = y_ss; y_flex(0) = y_ss;
25 | k(0) = k_ss; k_flex(0) = k_ss;
26 | n(0) = n_ss; n_flex(0) = n_ss;
27 | w(0) = w_ss; w_flex(0) = w_ss;
28 | x(0) = x_ss; x_flex(0) = x_ss;
29 | c(0) = c_ss; c_flex(0) = c_ss;
30 | r(0) = r_ss; r_flex(0) = r_ss;
31 | rk(0) = rk_ss; rk_flex(0) = rk_ss;
32 | ns(0) = ns_ss; ns_flex(0) = ns_ss;
33 | ni(0) = ni_ss; ni_flex(0) = ni_ss;
34 | nr(0) = nr_ss; nr_flex(0) = nr_ss;
35 | cs(0) = cs_ss; cs_flex(0) = cs_ss;
36 | ci(0) = ci_ss; ci_flex(0) = ci_ss;
37 | cr(0) = cr_ss; cr_flex(0) = cr_ss;
38 | dd(0) = dd_ss; dd_flex(0) = dd_ss;
39 | mc(0) = mc_ss; mc_flex(0) = mc_ss;
40 | rr(0) = rr_ss; rr_flex(0) = rr_ss;
41 | Rb(0) = Rb_ss; Rb_flex(0) = Rb_ss;
42 | tau(0) = tau_ss; tau_flex(0) = tau_ss;
43 | pop(0) = pop_ss; pop_flex(0) = pop_ss;
44 | pie(0) = pie_ss; pie_flex(0) = pie_ss;
45 | lami(0) = lami_ss; lami_flex(0) = lami_ss;
46 | lams(0) = lams_ss; lams_flex(0) = lams_ss;
47 | lamr(0) = lamr_ss; lamr_flex(0) = lamr_ss;
48 | lamtau(0) = lamtau_ss; lamtau_flex(0) = lamtau_ss;
49 | pbreve(0) = pbreve_ss; pbreve_flex(0) = pbreve_ss;
50 | lambtilde(0) = lambtilde_ss; lambtilde_flex(0) = lambtilde_ss;
51 | % recursive pricing variables have different steady-states
52 | F(0) = F_ss; F_flex(0) = F_flex_ss;
53 | Kf(0) = Kf_ss; Kf_flex(0) = Kf_flex_ss;
54 | end;
55 |
56 | perfect_foresight_setup(periods=500);
57 |
58 | % have a look at how variables for perfect foresight algorithm are initialized
59 | fprintf('\n\nINITIALIZATION OF PERFECT FORESIGHT ALGORITHM: oo_.steady_state\n')
60 | disp(array2table(oo_.steady_state', 'VariableNames',M_.endo_names));
61 | fprintf('\n\nINITIALIZATION OF PERFECT FORESIGHT ALGORITHM: M_.endo_histval\n')
62 | disp(array2table(M_.endo_histval', 'VariableNames',M_.endo_names));
63 | fprintf('\n\nINITIALIZATION OF PERFECT FORESIGHT ALGORITHM: oo_.endo_simul\n')
64 | disp(array2table(oo_.endo_simul(:,[1:3 options_.periods+2])',...
65 | 'VariableNames',M_.endo_names,...
66 | 'RowNames',["t=0","t=1","t=2",("t="+string(options_.periods+2))]'));
67 | fprintf('\n\nINITIALIZATION OF PERFECT FORESIGHT ALGORITHM: oo_.exo_simul\n')
68 | oo_.exo_simul
69 |
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_homotopy.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Illustrates homotopy over a parameter in a perfect foresight context.
3 | % Particularly, this is required to simulate the scenario "The impact of an
4 | % epidemic" in the New Keynesian Model of Eichenbaum, Rebelo, and Trabandt
5 | % (2022, JEDC): "Epidemics in the New Keynesian model".
6 | % -------------------------------------------------------------------------
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: May 18, 2023
9 | % =========================================================================
10 |
11 | @#include "ert_model_histval.mod"
12 |
13 | % changes in pi1 and pi2 are very small, so no need for homotopy
14 | set_param_value('pi1',2.568436063602094e-07);
15 | set_param_value('pi2',1.593556989906377e-04);
16 |
17 | % homotopy over pi3 (otherwise the simulation does not converge)
18 | pi3_final = 0.499739472034583;
19 | pi3_steps = [pi3_final/3:0.02:pi3_final,pi3_final];
20 | set_param_value('pi3',pi3_final/3); % set initial pi3 to one third of final value
21 |
22 | % re-run perfect_foresight_solver for increasing values of pi3 taking
23 | % previous simulation as initial guess for perfect foresight solver
24 | for pi3_j = pi3_steps
25 | fprintf('pi3 = %f\n',pi3_j);
26 | set_param_value('pi3',pi3_j);
27 | perfect_foresight_solver(maxit=100);
28 | end
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_initval.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Combines the sticky-price model equations and the flex-price model
3 | % equations of the New Keynesian Model of Eichenbaum, Rebelo, and Trabandt
4 | % (2022, JEDC): "Epidemics in the New Keynesian model" and uses an
5 | % initval block to compute the steady-state.
6 | % This also illustrates setting macro variables and the include directive
7 | % of Dynare's preprocessor.
8 | % -------------------------------------------------------------------------
9 | % Willi Mutschler (willi@mutschler.eu)
10 | % Version: May 18, 2023
11 | % =========================================================================
12 |
13 | @#define FLEX_PRICE_OUTPUT_GAP = 1
14 | @#include "ert_model_sticky.mod"
15 | @#include "ert_model_flex.inc"
16 |
17 | %-------------------------------------------------------------------------%
18 | % compute initial pre-infection steady-state
19 | %-------------------------------------------------------------------------%
20 | initval;
21 | % most variables in sticky- and flex-price economies have same steady-state
22 | y = y_ss; y_flex = y_ss;
23 | k = k_ss; k_flex = k_ss;
24 | n = n_ss; n_flex = n_ss;
25 | w = w_ss; w_flex = w_ss;
26 | x = x_ss; x_flex = x_ss;
27 | c = c_ss; c_flex = c_ss;
28 | s = s_ss; s_flex = s_ss;
29 | i = i_ss; i_flex = i_ss;
30 | r = r_ss; r_flex = r_ss;
31 | rk = rk_ss; rk_flex = rk_ss;
32 | ns = ns_ss; ns_flex = ns_ss;
33 | ni = ni_ss; ni_flex = ni_ss;
34 | nr = nr_ss; nr_flex = nr_ss;
35 | cs = cs_ss; cs_flex = cs_ss;
36 | ci = ci_ss; ci_flex = ci_ss;
37 | cr = cr_ss; cr_flex = cr_ss;
38 | dd = dd_ss; dd_flex = dd_ss;
39 | mc = mc_ss; mc_flex = mc_ss;
40 | rr = rr_ss; rr_flex = rr_ss;
41 | Rb = Rb_ss; Rb_flex = Rb_ss;
42 | tau = tau_ss; tau_flex = tau_ss;
43 | pop = pop_ss; pop_flex = pop_ss;
44 | pie = pie_ss; pie_flex = pie_ss;
45 | lami = lami_ss; lami_flex = lami_ss;
46 | lams = lams_ss; lams_flex = lams_ss;
47 | lamr = lamr_ss; lamr_flex = lamr_ss;
48 | lamtau = lamtau_ss; lamtau_flex = lamtau_ss;
49 | pbreve = pbreve_ss; pbreve_flex = pbreve_ss;
50 | lambtilde = lambtilde_ss; lambtilde_flex = lambtilde_ss;
51 | % recursive pricing variables have different steady-states
52 | F = F_ss; F_flex = F_flex_ss;
53 | Kf = Kf_ss; Kf_flex = Kf_flex_ss;
54 | end;
55 | resid;
56 | steady;
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_no_homotopy.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Illustrates that the scenario "The impact of an epidemic" in the New
3 | % Keynesian Model of Eichenbaum, Rebelo, and Trabandt (2022, JEDC):
4 | % "Epidemics in the New Keynesian model" has convergence issues due to the
5 | % large change in the infection probability of random meetings (pi3).
6 | % -------------------------------------------------------------------------
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: May 18, 2023
9 | % =========================================================================
10 |
11 | @#include "ert_model_histval.mod"
12 |
13 | % use set_param_value to update the parameters in the M_ structure
14 | set_param_value('pi1',2.568436063602094e-07);
15 | set_param_value('pi2',1.593556989906377e-04);
16 | set_param_value('pi3',0.499739472034583);
17 |
18 | % run perfect foresight simulation (feel free to abort it using CTRL+C)
19 | perfect_foresight_solver(maxit=20); % higher maxit does not help
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_plot_by_type_results.m:
--------------------------------------------------------------------------------
1 | function ert_model_plot_by_type_results(epidemic_type,M_,oo_)
2 | % function ert_model_plot_by_type_results(epidemic_type,M_,oo_)
3 | % -------------------------------------------------------------------------
4 | % create plots of consumption and hours by population type from the New Keynesian Model of
5 | % Eichenbaum, Rebelo, Trabandt (2022, JEDC): "Epidemics in the New Keynesian model"
6 | % based on plot_by_type_results.m from the original Dynare replication files
7 | % kindly provided by the authors (downloaded from Mathias Trabandt's homepage)
8 | % -------------------------------------------------------------------------
9 | % INPUTS
10 | % - epidemic_type [string] type of epidemic, possible values:
11 | % "demand", "supply", "both"
12 | % - M_ [structure] Dynare's model structure
13 | % - oo_ [structure] Dynare's results structure
14 | % -------------------------------------------------------------------------
15 | % Willi Mutschler (willi@mutschler.eu)
16 | % Version: May 18, 2023
17 | % =========================================================================
18 |
19 | % common settings for plots
20 | fsize = 12;
21 | horz = 100;
22 | time = 0:1:horz-1;
23 |
24 | % title for figure
25 | if epidemic_type == "demand"
26 | strtitle = "Response of consumption and hours when epidemic is a shock to demand";
27 | elseif epidemic_type == "supply"
28 | strtitle = "Response of consumption and hours when epidemic is a shock to supply";
29 | elseif epidemic_type == "both"
30 | strtitle = "Response of consumption and hours when epidemic is a shock to both demand and supply";
31 | end
32 | figure('name',strtitle,'units','normalized','outerposition',[0 0 0.75 0.75]);
33 |
34 | % Consumption by Type
35 | c_ss = oo_.steady_state(M_.endo_names=="c");
36 | cs = oo_.endo_simul(M_.endo_names=="cs",:);
37 | ci = oo_.endo_simul(M_.endo_names=="ci",:);
38 | cr = oo_.endo_simul(M_.endo_names=="cr",:);
39 | subplot(1,2,1);
40 | hold on;
41 | plot(time(1:end-1),100*(cs(2:horz)-c_ss)/c_ss,'r--','LineWidth',2);
42 | plot(time(1:end-1),100*(ci(2:horz)-c_ss)/c_ss,'k-.','LineWidth',2);
43 | plot(time(1:end-1),100*(cr(2:horz)-c_ss)/c_ss,'m:','LineWidth',2);
44 | plot(time(1:end-1),0*time(1:end-1),'b-','LineWidth',1);
45 | hold off
46 | box off;
47 | title('Consumption by Type','FontSize',fsize);
48 | ylabel('% Dev. from initial steady-state','FontSize',fsize);
49 | xlabel('Weeks','FontSize',fsize);
50 | set(gca,'FontSize',fsize);
51 | legend('Susceptibles','Infected','Recovered','Location','SouthEast');
52 | legend boxoff
53 |
54 | % Hours by Type
55 | n_ss = oo_.steady_state(M_.endo_names=="n");
56 | ns = oo_.endo_simul(M_.endo_names=="ns",:);
57 | ni = oo_.endo_simul(M_.endo_names=="ni",:);
58 | nr = oo_.endo_simul(M_.endo_names=="nr",:);
59 | subplot(1,2,2);
60 | hold on;
61 | plot(time(1:end-1),100*(ns(2:horz)-n_ss)/n_ss,'r--','LineWidth',2);
62 | plot(time(1:end-1),100*(ni(2:horz)-n_ss)/n_ss,'k-.','LineWidth',2);
63 | plot(time(1:end-1),100*(nr(2:horz)-n_ss)/n_ss,'m:','LineWidth',2);
64 | plot(time(1:end-1),0*time(1:end-1),'b-','LineWidth',1);
65 | hold off
66 | box off;
67 | title('Hours by Type','FontSize',fsize);
68 | ylabel('% Dev. from initial steady-state','FontSize',fsize);
69 | xlabel('Weeks','FontSize',fsize);
70 | set(gca,'FontSize',fsize);
71 | legend('Susceptibles','Infected','Recovered','Location','best');
72 | legend boxoff
73 |
74 | if epidemic_type == "demand"
75 | suptitle("Figure 6: " + strtitle);
76 | elseif epidemic_type == "supply"
77 | suptitle("Figure 8: " + strtitle);
78 | elseif epidemic_type == "both"
79 | suptitle("Figure 10: " + strtitle);
80 | end
--------------------------------------------------------------------------------
/progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_sticky_steady.mod:
--------------------------------------------------------------------------------
1 | % =========================================================================
2 | % Computes the steady-state of the sticky-price New Keynesian Model of
3 | % Eichenbaum, Rebelo, and Trabandt (2022, JEDC): "Epidemics in the New
4 | % Keynesian model".
5 | % This illustrates using the include directive of Dynare's preprocessor.
6 | % -------------------------------------------------------------------------
7 | % Willi Mutschler (willi@mutschler.eu)
8 | % Version: May 18, 2023
9 | % =========================================================================
10 |
11 | @#include "ert_model_sticky.mod"
12 |
13 | %-------------------------------------------------------------------------%
14 | % compute initial pre-infection steady-state
15 | %-------------------------------------------------------------------------%
16 | initval;
17 | y = y_ss;
18 | k = k_ss;
19 | n = n_ss;
20 | w = w_ss;
21 | rk = rk_ss;
22 | x = x_ss;
23 | c = c_ss;
24 | s = s_ss;
25 | i = i_ss;
26 | r = r_ss;
27 | ns = ns_ss;
28 | ni = ni_ss;
29 | nr = nr_ss;
30 | cs = cs_ss;
31 | ci = ci_ss;
32 | cr = cr_ss;
33 | tau = tau_ss;
34 | lambtilde = lambtilde_ss;
35 | lamtau = lamtau_ss;
36 | lami = lami_ss;
37 | lams = lams_ss;
38 | lamr = lamr_ss;
39 | dd = dd_ss;
40 | pop = pop_ss;
41 | pbreve = pbreve_ss;
42 | mc = mc_ss;
43 | rr = rr_ss;
44 | Rb = Rb_ss;
45 | pie = pie_ss;
46 | Kf = Kf_ss;
47 | F = F_ss;
48 | end;
49 | resid;
50 | steady;
--------------------------------------------------------------------------------
/week_10.notyet:
--------------------------------------------------------------------------------
1 | % !TEX root = week_10.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{week_10_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2024\\~\\Week 10}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/week_10.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{week_10_solution}[week_10_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/an_schorfheide_identif_bk.tex}\newpage
18 | \input{exercises/log_linearization.tex}\newpage
19 | \input{exercises/case_study_ascari_sbordone_2014.tex}\newpage
20 |
21 | \printbibliography%
22 |
23 | \newpage
24 |
25 | \appendix
26 |
27 | \section{Helper functions for New Keynesian Trend Inflation model}
28 |
29 | \subsection{ascari\_sbordone\_2014\_common.mod\label{app:ascari_sbordone_2014_common}}
30 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_common.mod}
31 |
32 | \subsection{ascari\_sbordone\_2014\_calib\_common.mod\label{app:ascari_sbordone_2014_calib_common}}
33 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Ascari_Sbordone_2014/ascari_sbordone_2014_calib_common.inc}
34 |
35 | \Closesolutionfile{week_10_solution}
36 | \ifDisplaySolutions%
37 | \newpage
38 | \appendix
39 | \section{Solutions}
40 | \input{week_10_solution}
41 | \fi
42 | \end{document}
--------------------------------------------------------------------------------
/week_11.notyet:
--------------------------------------------------------------------------------
1 | % !TEX root = week_11.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{week_11_solution}
4 | \newif\ifDisplaySolutions%\DisplaySolutionstrue
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2024\\~\\Week 11}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/week_11.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{week_11_solution}[week_11_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/case_study_annicchiarico_DiDio_2015.tex}\newpage
18 |
19 | \printbibliography
20 |
21 | \newpage
22 |
23 | \appendix
24 |
25 | \section{Helper functions for New Keynesian Environmental model}
26 |
27 | \subsection{ann\_dio\_2015\_symdecls.inc\label{app:ann_dio_2015_symdecls}}
28 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_symdecls.inc}
29 |
30 | \subsection{ann\_dio\_2015\_modeleqs.inc\label{app:ann_dio_2015_modeleqs}}
31 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_modeleqs.inc}
32 |
33 | \subsection{ann\_dio\_2015\_tbl1\_tbl2\_no\_policy.mod\label{app:ann_dio_2015_tbl1_tbl2_no_policy}}
34 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl1_tbl2_no_policy.mod}
35 |
36 | \subsection{ann\_dio\_2015\_tbl2\_environmental\_policy.mod\label{app:ann_dio_2015_tbl2_environmental_policy}}
37 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_tbl2_environmental_policy.mod}
38 |
39 | \subsection{ann\_dio\_2015\_steadystate\_helper.m\label{app:ann_dio_2015_steadystate_helper}}
40 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Annicchiarico_DiDio_2015/ann_dio_2015_steadystate_helper.m}
41 |
42 | \Closesolutionfile{week_11_solution}
43 | \ifDisplaySolutions
44 | \newpage
45 | \appendix
46 | \section{Solutions}
47 | \input{week_11_solution}
48 | \fi
49 | \end{document}
--------------------------------------------------------------------------------
/week_8.notyet:
--------------------------------------------------------------------------------
1 | % !TEX root = week_8.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{week_8_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2024\\~\\Week 8}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/week_8.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{week_8_solution}[week_8_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/case_study_eichenbaum_rebelo_trabandt_2022.tex}\newpage
18 |
19 | \printbibliography%
20 | \newpage
21 |
22 | \appendix
23 | \section{Helper functions for New Keynesian Epidemic model}
24 | \subsection{ert\_model\_sticky.mod\label{app:ert_model_sticky}}
25 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_sticky.mod}
26 |
27 | \subsection{ert\_model\_go\_calibrate\_pi.m\label{app:ert_model_go_calibrate_pi}}
28 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_go_calibrate_pi.m}
29 |
30 | \subsection{ert\_model\_plot\_agg\_results.m\label{app:ert_model_plot_agg_results}}
31 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_plot_agg_results.m}
32 |
33 | \subsection{ert\_model\_plot\_by\_type\_results.m\label{app:ert_model_plot_by_type_results}}
34 | \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily\scriptsize,title=\lstname]{progs/replications/Eichenbaum_Rebelo_Trabandt_2022/ert_model_plot_by_type_results.m}
35 |
36 | \Closesolutionfile{week_8_solution}
37 | \ifDisplaySolutions%
38 | \newpage
39 | \appendix
40 | \section{Solutions}
41 | \input{week_8_solution}
42 | \fi
43 | \end{document}
--------------------------------------------------------------------------------
/week_9.notyet:
--------------------------------------------------------------------------------
1 | % !TEX root = week_9.tex
2 | \input{exercises/_common_header.tex}
3 | \Newassociation{solution}{Solution}{week_9_solution}
4 | \newif\ifDisplaySolutions\DisplaySolutionstrue%
5 |
6 | \begin{document}
7 | \title{Computational Macroeconomics\\~\\Summer 2024\\~\\Week 9}
8 | \author{Willi Mutschler\\willi@mutschler.eu}
9 | \date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Computational-Macroeconomics/releases/latest/download/week_9.pdf}{GitHub}}
10 | \maketitle\thispagestyle{empty}
11 |
12 | \newpage
13 | \Opensolutionfile{week_9_solution}[week_9_solution]
14 | \tableofcontents\thispagestyle{empty}\newpage
15 |
16 | \setcounter{page}{1}
17 | \input{exercises/brock_mirman_policy_function.tex}\newpage
18 | \input{exercises/nk_simulations.tex}\newpage
19 |
20 | \printbibliography%
21 |
22 | \newpage
23 |
24 | \Closesolutionfile{week_9_solution}
25 | \ifDisplaySolutions%
26 | \newpage
27 | \appendix
28 | \section{Solutions}
29 | \input{week_9_solution}
30 | \fi
31 | \end{document}
--------------------------------------------------------------------------------