Skip to content

Commit

Permalink
Improved week10 and added solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
wmutschl committed Feb 15, 2024
1 parent f836c1e commit 46afafb
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 38 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,11 @@ jobs:
command: |
cd("progs/matlab")
BlanchardQuahLR
RWZSRLR
RWZSRLR
- name: Run week 10 scripts
uses: matlab-actions/run-command@v1
with:
command: |
cd("progs/matlab")
bootstrappingStdIRFs_RWZSRLR
gali1992
54 changes: 34 additions & 20 deletions exercises/svar_IS_LM.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\section[How Well Does the IS-LM Model Fit Postwar US Data]{How Well Does the IS-LM Model Fit Postwar US Data?\label{ex:svarISLM}}
Consider a quarterly model for \(y_t = (\Delta gnp_t, \Delta i_t, i_t-\Delta p_t, \Delta m_t - \Delta p_t)'\),
where \(gnp_t\) denotes the log of GNP, \(i_t\) the nominal yield on three-month Treasury Bills,
\(\Delta m_t\) the growth in M1 and \(\Delta p_t\) the inflation rate in the CPI.
\(\Delta m_t\) the growth in M1 and \(\Delta p_t\) the inflation rate in the CPI\@.
There are four shocks in the system: an aggregate supply (AS), a money supply (MS), a money demand (MD) and an aggregate demand (IS) shock.
Ignoring the lagged dependent variables for \textbf{expository} purposes (\(B_1=\cdots =B_p=0\)),
the unrestricted structural VAR model can be simply written as \(B_0 y_t = \varepsilon_t\). That is:
Expand All @@ -14,32 +14,46 @@
where \(b_{ij}\) denotes the \(ij\)th element of \(B_0\).
Consider the following identification restrictions:
\begin{itemize}
\item Money supply shocks do not have contemporaneous effects on output growth, i.e.
$$\frac{\partial \Delta gnp_t}{\partial \varepsilon_t^{MS}}=0$$
\item Money demand shocks do not have contemporaneous effects on output growth, i.e.
$$\frac{\partial \Delta gnp_t}{\partial \varepsilon_t^{MD}}=0$$
\item Monetary authority does not react contemporaneously to changes in the price level.\\Hint: compute from equation \eqref{eq:MS}:
$$\frac{\partial \Delta i_t}{\partial \Delta p_t}=0$$
\item Money supply shocks, money demand shocks and aggregate demand shocks do not have long-run effects on the log of real GNP:
$$\frac{\partial gnp_t}{\partial \varepsilon_t^{MS}}=0,\qquad \frac{\partial gnp_t}{\partial \varepsilon_t^{MD}}=0,\qquad \frac{\partial gnp_t}{\partial \varepsilon_t^{IS}}=0$$
\item The structural shocks are uncorrelated with covariance matrix $E(\varepsilon_t \varepsilon_t')=\Sigma_\varepsilon$.
\item Money supply shocks do not have contemporaneous effects on output growth, i.e.\
\begin{align*}
\frac{\partial \Delta gnp_t}{\partial \varepsilon_t^{MS}}=0
\end{align*}

\item Money demand shocks do not have contemporaneous effects on output growth, i.e.\
\begin{align*}
\frac{\partial \Delta gnp_t}{\partial \varepsilon_t^{MD}}=0
\end{align*}

\item Monetary authority does not react contemporaneously to changes in the price level.\\Hint: compute from equation~\eqref{eq:MS}:
\begin{align*}
\frac{\partial \Delta i_t}{\partial \Delta p_t}=0
\end{align*}

\item Money supply shocks, money demand shocks and aggregate demand shocks do not have long-run effects on the log of real GNP:
\begin{align*}
\frac{\partial gnp_t}{\partial \varepsilon_t^{MS}}=0,\qquad \frac{\partial gnp_t}{\partial \varepsilon_t^{MD}}=0,\qquad \frac{\partial gnp_t}{\partial \varepsilon_t^{IS}}=0
\end{align*}

\item The structural shocks are uncorrelated with covariance matrix \(E(\varepsilon_t \varepsilon_t')=\Sigma_\varepsilon \).
In other words, the variances are \textbf{not} normalized.
\end{itemize}
Solve the following exercises:
\begin{enumerate}
\item Derive the implied exclusion restrictions on the matrices $B_0$, $B_0^{-1}$ and $\Theta(1)$.
\item Derive the implied exclusion restrictions on the matrices \(B_0\), \(B_0^{-1}\) and \(\Theta(1)\).
\item Consider data given in the csv file \texttt{gali1992.csv}.
Estimate a VAR(4) model with a constant.
\item Estimate the structural impact matrix using a nonlinear equation solver,
i.e.\ the objective is to find the unknown elements of $B_0^{-1}$ and the diagonal elements of $\Sigma_\varepsilon$ such that
$$\begin{bmatrix}
vech(B_0^{-1} \Sigma_\varepsilon B_0^{-1'}-\hat{\Sigma}_u)\\
\text{short-run restrictions on }B_0 \text{ and } B_0^{-1} \\
\text{long-run restrictions on }\Theta(1)\\
\end{bmatrix}$$
i.e.\ the objective is to find the unknown elements of \(B_0^{-1}\) and the diagonal elements of \(\Sigma_\varepsilon \) such that
\begin{align*}
\begin{bmatrix}
vech(B_0^{-1} \Sigma_\varepsilon B_0^{-1'}-\hat{\Sigma}_u)\\
\text{short-run restrictions on~}B_0 \text{~and~} B_0^{-1} \\
\text{long-run restrictions on~}\Theta(1)\\
\end{bmatrix}
\end{align*}
is minimized.
Normalize the shocks such that the diagonal elements of $B_0^{-1}$ are positive.
\item Use the implied estimates of $B_0^{-1}$ and $\Sigma_\varepsilon$ to plot the structural impulse responses functions
Normalize the shocks such that the diagonal elements of \(B_0^{-1}\) are positive.
\item Use the implied estimates of \(B_0^{-1}\) and \(\Sigma_\varepsilon\) to plot the structural impulse responses functions
for (i) real GNP, (ii) the yield on Treasury Bills, (iii) the real interest rate and (iv) real money growth.
Add 68\% and 95\% confidence intervals using a bootstrap approach.
\end{enumerate}
Expand All @@ -51,7 +65,7 @@

\begin{solution}\textbf{Solution to \nameref{ex:svarISLM}}
\ifDisplaySolutions
\input{exercises/svar_IS_LM.tex}
\input{exercises/svar_IS_LM_solution.tex}
\fi
\newpage
\end{solution}
128 changes: 128 additions & 0 deletions exercises/svar_IS_LM_solution.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
\begin{enumerate}

\item First, let's rewrite the equations in matrix form:
\begin{align*}
\underbrace{%
\begin{bmatrix}
1 & b_{12} & b_{13} & b_{14}\\
b_{21} & 1 & b_{23} & b_{24}\\
b_{31} & b_{32} & 1 & b_{34}\\
b_{41} & b_{42} & b_{43} & 1
\end{bmatrix}}_{B_0}
\begin{bmatrix}
\Delta gnp_t\\
\Delta i_t\\
i_t - \Delta p_t\\
\Delta m_t - \Delta p_t
\end{bmatrix}
&=
\begin{bmatrix}
\varepsilon_t^{AS}\\
\varepsilon_t^{MS}\\
\varepsilon_t^{MD}\\
\varepsilon_t^{IS}
\end{bmatrix}
\\
\begin{bmatrix}
\Delta gnp_t\\
\Delta i_t\\
i_t - \Delta p_t\\
\Delta m_t - \Delta p_t
\end{bmatrix}
&=
\underbrace{%
\begin{bmatrix}
b^*_{11} & b^*_{12} & b^*_{13} & b^*_{14}\\
b^*_{21} & b^*_{22} & b^*_{23} & b^*_{24}\\
b^*_{31} & b^*_{32} & b^*_{33} & b^*_{34}\\
b^*_{41} & b^*_{42} & b^*_{43} & b^*_{44}
\end{bmatrix}}_{B^{-1}_0}
\begin{bmatrix}
\varepsilon_t^{AS}\\
\varepsilon_t^{MS}\\
\varepsilon_t^{MD}\\
\varepsilon_t^{IS}
\end{bmatrix}
\end{align*}
The long-run multiplier matrix is given by:
\begin{align*}
\Theta(1) = {A(1)}^{-1} B^{-1}_0
\end{align*}

Now let's derive the restrictions on the impact matrix \(B_0^{-1}\):
\begin{itemize}
\item Money supply shocks do not have contemporaneous effects on output growth, i.e.\
\begin{align*}
\frac{\partial \Delta gnp_t}{\partial \varepsilon_t^{MS}}= b^*_{12} = 0
\end{align*}

\item Money demand shocks do not have contemporaneous effects on output growth, i.e.\
\begin{align*}
\frac{\partial \Delta gnp_t}{\partial \varepsilon_t^{MD}}= b^*_{13} = 0
\end{align*}
\end{itemize}
Summarizing this yields two restrictions:
\begin{align*}
B_0^{-1} =
\begin{pmatrix}
* & 0 & 0 & *\\
* & * & * & *\\
* & * & * & *\\
* & * & * & *
\end{pmatrix}
\end{align*}

Next, let's derive the restrictions on the structural matrix \(B_0\):
\begin{itemize}
\item Monetary authority does not react contemporaneously to changes in the price level.
This can be computed directly from equation~\eqref{eq:MS}:
\begin{align*}
\frac{\partial \Delta i_t}{\partial \Delta p_t}= b_{23} + b_{24} = 0 \Leftrightarrow b_{23} = -b_{24}
\end{align*}
\end{itemize}
Summarizing this yields one restriction:
\begin{align*}
B_0 =
\begin{pmatrix}
1 & * & * & *\\
* & 1 & -b_{24} & b_{24}\\
* & * & 1 & *\\
* & * & * & 1
\end{pmatrix}
\end{align*}

\begin{itemize}
\item Money supply shocks, money demand shocks and aggregate demand shocks do not have long-run effects on the log of real GNP.
\end{itemize}
The restrictions on the long-run multiplier matrix are thus:
\begin{align*}
\Theta(1) =
\begin{pmatrix}
* & 0 & 0 & 0\\
* & * & * & *\\
* & * & * & *\\
* & * & * & *
\end{pmatrix}
\end{align*}
This yields three restrictions.

In total we have \(2+1+3=6\) restrictions, which is equal to the required number of \(K(K-1)/2=6\) of an exactly identified SVAR model.

Lastly, we need to keep in mind that the variance of the structural shocks is not normalized:
\begin{align*}
\Sigma_\varepsilon =
\begin{pmatrix}
\sigma_{11} & 0 & 0 & 0\\
0 & \sigma_{22} & 0 & 0\\
0 & 0 & \sigma_{33} & 0\\
0 & 0 & 0 & \sigma_{44}
\end{pmatrix}
\end{align*}

\item[2/3/4]
Here is the helper function to impose the restrictions:
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/gali1992_f.m}
The main code might look like this:
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/gali1992.m}

\end{enumerate}
33 changes: 17 additions & 16 deletions exercises/svar_bootstrap_std_irf.tex
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
\section[Bootstrapping Standard Deviations of Structural IRFs]{Bootstrapping Standard Deviations of Structural IRFs\label{ex:BootstrapStandardDeviationStructuralIRFs}}
Consider an exactly-identified structural VAR model subject to short- and/or long-run restrictions,
where the structural impulse response of variable $i$ to shock $j$ at horizon $h$ are simply denoted as $\theta \equiv \Theta_{ij,h}$.
As an exact closed-form solution for the asymptotic standard errors of $\theta$ are only available under restrictive assumptions,
where the structural impulse response of variable \(i\) to shock \(j\) at horizon \(h\) are simply denoted as \(\theta \equiv \Theta_{ij,h}\).
As an exact closed-form solution for the asymptotic standard errors of \(\theta \) are only available under restrictive assumptions,
we will rely on a numerical approximation using a bootstrap approach.
\begin{enumerate}
\item Reconsider an exercise (of your choice) from the lecture on SVAR models identified with exclusion restrictions and re-estimate the structural impulse response function.
\item Reconsider an exercise (of your choice) from the lecture on SVAR models identified with exclusion restrictions
and re-estimate the structural impulse response function.

\item Compute $\widehat{std}(\hat{\theta}^\ast)$ via a bootstrap approximation by following these steps:
\item Compute \(\widehat{std}(\hat{\theta}^\ast)\) via a bootstrap approximation by following these steps:
\begin{itemize}
\item Write a function \texttt{BootstrapGDP(VAR,opt)} which implements a standard residual-based bootstrap approach
\item Write a function \texttt{bootstrapDGP(VAR,opt)} which implements a standard residual-based bootstrap approach
using sampling with replacement techniques on the residuals.
Furthermore, the initial values should be drawn randomly in blocks.
Hint: Use the companion form to do the simulations.
\item Set bootstrap repetitions $B$ equal to 1000 (or higher)
and initialize a $K \times K \times H \times B$ array \texttt{THETAstar},
where the first dimension corresponds to variable $i=1,..,K$,
the second dimension to shock $j=1,...,K$,
the third dimension to the horizon of the IRFs $h=0,..,H$
and the fourth dimension to the bootstrap repetition $b=1.,...,B$.
\item For $b=1,...,B$ do the following (you may also try \texttt{parfor} instead of \texttt{for}
in order to make use of Matlab's parallel computing toolbox if installed):
\item Set bootstrap repetitions \(B\) equal to 1000 (or higher)
and initialize a \(K \times K \times H \times B\) array \texttt{THETAstar},
where the first dimension corresponds to variable \(i=1,\ldots,K\),
the second dimension to shock \(j=1,/ldots,K\),
the third dimension to the horizon of the IRFs \(h=0,\ldots,H\)
and the fourth dimension to the bootstrap repetition \(b=1.,\ldots,B\).
\item For \(b=1,\ldots,B\) do the following (you may also try \texttt{parfor} instead of \texttt{for}
in order to make use of Matlab's parallel computing toolbox -- if installed):
\begin{itemize}
\item Compute a bootstrap GDP $y_t^{b}$ using the function \texttt{BootstrapGDP(VAR,opt)}.
\item Compute a bootstrap DGP \(y_t^{b}\) using the function \texttt{bootstrapDGP(VAR,opt)}.
\item Estimate the reduced-form and structural impulse response function on this artificial dataset
with the same methodology, settings and identification restrictions as in the estimation of the original dataset.
\item Store the structural IRFs in \texttt{THETAstar} at position \texttt{(:,:,:,b)}.
\end{itemize}
\item Compute the standard deviation of the bootstrap structural IRFs using \texttt{std(THETAstar,0,4)}.
\end{itemize}

\item Plot approximate 68\% and 95\% confidence intervals for the structural impulse response functions according to the delta method:
\item Plot approximate 68\% and 95\% confidence intervals for the structural impulse response functions according to the Delta method:
\begin{align*}
\hat{\theta} \pm z_{\gamma/2} \widehat{std}(\hat{\theta}^\ast)
\end{align*}
where $z_{\gamma/2}$ is the $\gamma/2$ quantile of the standard normal distribution.
where \(z_{\gamma/2}\) is the \(\gamma/2\) quantile of the standard normal distribution.
\end{enumerate}

\paragraph{Readings}
Expand Down
9 changes: 9 additions & 0 deletions exercises/svar_bootstrap_std_irf_solution.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\begin{enumerate}

\item[1.] We will re-consider the \textcite{Rubio-Ramirez.Waggoner.Zha_2010_StructuralVectorAutoregressions} example.

\item[2./3.] The helper function to generate bootstrap DGPs might look like this:
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/bootstrapDGP.m}
The main script might look like this:
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/bootstrappingStdIRFs_RWZSRLR.m}
\end{enumerate}
2 changes: 1 addition & 1 deletion week_10.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% !TEX root = week_10.tex
\input{exercises/_common_header.tex}
\Newassociation{solution}{Solution}{week_10_solution}
\newif\ifDisplaySolutions%\DisplaySolutionstrue
\newif\ifDisplaySolutions\DisplaySolutionstrue

\begin{document}
\title{Quantitative Macroeconomics\\~\\Winter 2023/24\\~\\Week 10}
Expand Down

0 comments on commit 46afafb

Please sign in to comment.