Skip to content

Commit

Permalink
Added week 5 materials
Browse files Browse the repository at this point in the history
  • Loading branch information
wmutschl committed Nov 7, 2024
1 parent beb7a5e commit 76a19cb
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 81 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/dynare-6.2-matlab-r2024b-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ jobs:
AR4OLS;
AR4ML;
AR1MLLaplace;
- name: Run week 5 codes
uses: matlab-actions/run-command@v2
with:
command: |
addpath("Dynare-6.2-arm64/matlab");
cd("progs/matlab");
AR4LagSelection;
portmanteauTest;
bootstrapCIAR1;
12 changes: 11 additions & 1 deletion .github/workflows/dynare-6.2-matlab-r2024b-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@ jobs:
cd("progs/matlab");
AR4OLS;
AR4ML;
AR1MLLaplace;
AR1MLLaplace;
- name: Run week 5 codes
uses: matlab-actions/run-command@v2
with:
command: |
addpath("dynare/matlab");
cd("progs/matlab");
AR4LagSelection;
portmanteauTest;
bootstrapCIAR1;
12 changes: 11 additions & 1 deletion .github/workflows/dynare-6.2-matlab-r2024b-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ jobs:
cd("progs/matlab");
AR4OLS;
AR4ML;
AR1MLLaplace;
AR1MLLaplace;
- name: Run week 5 codes
uses: matlab-actions/run-command@v2
with:
command: |
addpath("D:\hostedtoolcache\windows\dynare-6.0\matlab");
cd("progs/matlab");
AR4LagSelection;
portmanteauTest;
bootstrapCIAR1;
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ Please feel free to use this for teaching or learning purposes; however, taking
</details>


<!---
<details>
<summary>Week 5: Information Criteria, Specification Tests, and Bootstrap</summary>

Expand All @@ -123,13 +121,15 @@ Please feel free to use this for teaching or learning purposes; however, taking

* [x] review the solutions of [last week's exercises](https://github.com/wmutschl/Quantitative-Macroeconomics/releases/latest/download/week_4.pdf) and write down all your questions
* [x] re-read Lütkepohl (2004) and quickly go through Kilian and Lütkepohl (2007, Ch. 12.2); make note of all the aspects and concepts that you are still not familiar with or that you find difficult to understand
* [x] TRY (!!!) to do exercises 1 and 2 of the problem set for week 5; we will do exercise 3 in class (see this [video](https://youtu.be/Itf-8Cp4xHI))
* [x] Do exercise 1 of the problem set for week 5; we will do exercises 2 and 3 in class
* [x] participate in the Q&A sessions with all your questions and concerns
* [x] for immediate help: [schedule a meeting](https://schedule.mutschler.eu)
* [x] (optionally) fork the course repository on GitHub

</details>


<!---
<details>
<summary> Week 6: Multivariate Time Series Concepts</summary>
Expand Down
90 changes: 48 additions & 42 deletions exercises/bootstrap_ci_ar1.tex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
\section[Bootstrap Confidence Interval For AR(1) Coefficient]{Bootstrap Confidence Interval For AR(1) Coefficient\label{ex:BootstrapConfidenceIntervalARone}}
Consider the AR(1) model with constant
\section[Bootstrap Confidence Interval For AR{(1)} Coefficient]{Bootstrap Confidence Interval For AR{(1)} Coefficient\label{ex:BootstrapConfidenceIntervalARone}}
Consider the AR{(1)} model with constant
\begin{equation*}
y_{t}=c +\phi y_{t-1}+u_{t}
\end{equation*}
for \(t=1,\ldots ,T\) with iid error terms \(u_{t}\) and \(E(u_{t}|y_{t-1})=0\).
Usually, we construct a \( (1-\alpha)\% \)-confidence interval for \( \phi \) using the normal (or student's t) approximation:
Usually, we construct a \( (1-\alpha)\% \)-confidence interval for \( \phi \) using the normal (or Student's t) approximation:
\begin{equation*}
\left[ \hat{\phi}-z_{\alpha/2}\cdot SE(\hat{\phi});\ \hat{\phi}+z_{1-\alpha/2}\cdot SE(\hat{\phi})\right]
\end{equation*}
Expand All @@ -17,53 +17,59 @@
To this end, we are going to do a so-called \enquote{\emph{bootstrap}},
i.e.\ we recompute the t-statistics a large number of times on artificial data
generated from resampled residuals.\\

\begin{enumerate}
\item What is a \enquote{Bootstrap approximation}? Provide insight into the basic idea and possible applications of this statistical technique.
\item Write a program for the following:
\begin{itemize}
\item Simulate \(T=100\) observations with \(c=1\), \(\phi=0.8\)
and errors drawn from e.g.\ the exponential distribution such that \(E(u_t)=0\).
\item Estimate the model with OLS and calculate the t-statistic
\(\tau=\frac{\hat{\phi}}{SE(\hat{\phi})}\).
\item Store the OLS residuals in a vector
\(\hat{u} = (\hat{u}_{2},\ldots ,\hat{u}_{T})'\).
\item Set \(B=10000\) and initialize the output vector
\(\tau^{\ast} = (\tau_1^\ast,\ldots,\tau_B^\ast)\).
\item For \( b=1,\ldots,B \):
\begin{itemize}
\item Draw a sample \textbf{with replacement} from \(\hat{u}\)
and save it as \(u^{\ast} = u_{2}^{\ast},\ldots ,u_{T}^{\ast }\).
\item Initialize an artificial time series \( y_t^\ast \) with \(T\) observations
and set \(y_1^\ast = y_1\).
\item For \(t=2,\ldots ,T\) generate
\begin{align*}
y_{t}^{\ast }=\hat{c}+\hat{\phi}y^\ast_{t-1}+u_{t}^{\ast }
\end{align*}
\item On this artificial dataset estimate an AR(1) model.
Denote the estimated OLS coefficient \(\phi^\ast\)
and corresponding estimated standard deviation \(SE(\phi^\ast)\).
Store the following t-statistic in your output vector at position \(b\):
\begin{align*}
\tau^\ast = \frac{\phi^\ast - \hat{\phi}}{SE(\phi^\ast)}
\end{align*}
\end{itemize}
\item Sort the output vector such that \(\tau_{(1)}^\ast \leq \cdots \leq \tau_{(B)}^\ast\).
\item The \enquote{\emph{bootstrap approximate}} confidence interval for \(\phi\) is then given by
\begin{align*}
\left[ \hat{\phi}-\tau_{((1-\alpha /2)B)}^{\ast }\cdot SE(\hat{\phi});\ \hat{\phi}-\tau_{((\alpha/2)B)}^{\ast }\cdot SE(\hat{\phi})\right]
\end{align*}
Set \(\alpha=0.05\) and compare this with the normal approximation.
\item Redo the exercise for \(T=30\) and \(T=10000\). Comment on your findings.
\end{itemize}
\item
What is a \enquote{Bootstrap approximation}?
Provide insight into the basic idea and possible applications of this statistical technique.

\item
Write a program for the following:
\begin{itemize}
\item Simulate \(T=100\) observations with \(c=1\), \(\phi=0.8\)
and errors drawn from e.g.\ the exponential distribution such that \(E(u_t)=0\).
\item Estimate the model with OLS and calculate the t-statistic
\(\tau=\frac{\hat{\phi}}{SE(\hat{\phi})}\).
\item Store the OLS residuals in a vector
\(\hat{u} = (\hat{u}_{2},\ldots ,\hat{u}_{T})'\).
\item Set \(B=10000\) and initialize the output vector
\(\tau^{\ast} = (\tau_1^\ast,\ldots,\tau_B^\ast)\).
\item For \( b=1,\ldots,B \):
\begin{itemize}
\item Draw a sample \textbf{with replacement} from \(\hat{u}\)
and save it as \(u^{\ast} = u_{2}^{\ast},\ldots ,u_{T}^{\ast }\).
\item Initialize an artificial time series \( y_t^\ast \) with \(T\) observations
and set \(y_1^\ast = y_1\).
\item For \(t=2,\ldots ,T\) generate
\begin{align*}
y_{t}^{\ast }=\hat{c}+\hat{\phi}y^\ast_{t-1}+u_{t}^{\ast }
\end{align*}
\item On this artificial dataset estimate an AR{(1)} model.
Denote the estimated OLS coefficient \(\phi^\ast \)
and corresponding estimated standard deviation \(SE(\phi^\ast)\).
Store the following t-statistic in your output vector at position \(b\):
\begin{align*}
\tau^\ast = \frac{\phi^\ast - \hat{\phi}}{SE(\phi^\ast)}
\end{align*}
\end{itemize}
\item Sort the output vector such that \(\tau_{(1)}^\ast \leq \cdots \leq \tau_{(B)}^\ast \).
\item The \enquote{\emph{bootstrap approximate}} confidence interval for \(\phi \) is then given by
\begin{align*}
\left[ \hat{\phi}-\tau_{((1-\alpha /2)B)}^{\ast }\cdot SE(\hat{\phi});\ \hat{\phi}-\tau_{((\alpha/2)B)}^{\ast }\cdot SE(\hat{\phi})\right]
\end{align*}
Set \(\alpha=0.05\) and compare this with the normal approximation.
\item Redo the exercise for \(T=30\) and \(T=10000\). Comment on your findings.
\end{itemize}

\end{enumerate}

\paragraph{Readings}
\begin{itemize}
\item \textcite[Ch. 12]{Kilian.Lutkepohl_2017_StructuralVectorAutoregressive}
\item \textcite[Ch. 12]{Kilian.Lutkepohl_2017_StructuralVectorAutoregressive}
\end{itemize}

\begin{solution}\textbf{Solution to \nameref{ex:BootstrapConfidenceIntervalARone}}
\ifDisplaySolutions
\ifDisplaySolutions%
\input{exercises/bootstrap_ci_ar1_solution.tex}
\fi
\newpage
Expand Down
4 changes: 2 additions & 2 deletions exercises/bootstrap_ci_ar1_solution.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/bootstrapCIAR1.m}
For large $T$ the bootstrap CI are almost identical to the asymptotic CIs, for small $T$ they are narrower.
For large \(T\) the bootstrap CI are almost identical to the asymptotic CIs, for small \(T\) they are narrower.

No efficiency gain from imposing parametric assumptions even when that assumption is true,
whereas imposing the wrong parametric structure tends to undermine the accuracy of the bootstrap inference.

$\hookrightarrow$ Nonparametric approach is typically strictly preferred in practice.
\(\hookrightarrow \) Nonparametric approach is typically strictly preferred in practice.
30 changes: 20 additions & 10 deletions exercises/information_criteria_ar_p.tex
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
\section[Information Criteria For AR(p)]{Information Criteria For AR(p)\label{ex:InformationCriteriaARp}}
\section[Information Criteria For AR(p)]{Information Criteria For AR{(p)}\label{ex:InformationCriteriaARp}}
Consider the following information criteria to estimate the order \(p\) of an \(AR(p)\) model:
\begin{align*}
AIC(n) &= \log\tilde{\sigma}^2(n) + \frac{2}{T^{eff}}n\\
SIC(n) &= \log\tilde{\sigma}^2(n) + \frac{\log T^{eff}}{T^{eff}}n\\
AIC(n) &= \log\tilde{\sigma}^2(n) + \frac{2}{T^{eff}}n
\\
SIC(n) &= \log\tilde{\sigma}^2(n) + \frac{\log T^{eff}}{T^{eff}}n
\\
HQC(n) &= \log\tilde{\sigma}^2(n) + \frac{2\log \log T^{eff}}{T^{eff}}n
\end{align*}
where \(\tilde{\sigma}^2\) denotes the ML estimate of the variance term
based on the residuals \(\hat{u}_t(n)\) of the corresponding estimated \(AR(p)\) model.
\(n\) is the number of estimated parameters and \(T^{eff}=T-p^{\text{max}}\),
where \(p^{\text{max}}\) is the maximum number of lags to consider.

\begin{enumerate}
\item Provide intuition between the different criteria.

\item
Provide intuition between the different criteria.
Which one (asymptotically) over- or underestimates the correct order?
\item Write a function \texttt{nlag = lagOrderSelectionARp(\(y\),\(const\),\(pmax\),\(crit\))}

\item Write a function \texttt{nlag = lagOrderSelectionARp{(\(y\),\(const\),\(pmax\),\(crit\))}}
that computes the different order criteria for \(p = 1,\ldots ,p^{\text{max}}\)
using data vector \(y\) and possible constant term (\(const=1\))
or constant term and linear trend (\(const=2\)).
\(nlag\) should output the recommended lag according to criteria \(crit\),
\(nlag\) should output the recommended lag according to criteria \(crit\),
which takes a string (\('AIC'\), \('SIC'\) or \('HQC'\)) as input value.
\item Load the dataset of the simulated AR(4) process given in the CSV file \texttt{AR4.csv}.

\item
Load the dataset of the simulated AR{(4)} process given in the CSV file \texttt{AR4.csv}.
Which model is preferred according to the order selection criteria?
\item Simulate another stationary AR(4) processes with sample sizes \(T = 150\)

\item Simulate another stationary AR{(4)} processes with sample sizes \(T = 150\)
and redo the previous exercise.

\end{enumerate}

\paragraph{Readings}
\begin{itemize}
\item \textcite{Lutkepohl_2004_UnivariateTimeSeries}.
\item \textcite{Lutkepohl_2004_UnivariateTimeSeries}
\end{itemize}

\begin{solution}\textbf{Solution to \nameref{ex:InformationCriteriaARp}}
\ifDisplaySolutions
\ifDisplaySolutions%
\input{exercises/information_criteria_ar_p_solution.tex}
\fi
\newpage
Expand Down
22 changes: 13 additions & 9 deletions exercises/information_criteria_ar_p_solution.tex
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
\begin{enumerate}
\item The first term measures the fit of a model with order \(p\) and it is the same for all criteria.

\item
The first term measures the fit of a model with order \(p\) and it is the same for all criteria.
This term decreases for increasing order because there is no correction for degrees of freedom in the ML variance estimator.

The second term penalizes large AR orders.
How this term is effectively chosen distinguishes the different criteria.

The criteria have the following properties:
\begin{itemize}
\item AIC asymptotically overestimates the order with positive probability
\item HQC estimates the order consistently (\(plim~ \hat{p}= p\))
\item SIC is even strongly consistent (\(\hat{p} \overset{a.s.}{\rightarrow} p\)) under quite general conditions
(e.g.\ if the actual DGP is a finite-order AR process and the maximum order is larger than the true order).
\item AIC asymptotically overestimates the order with positive probability
\item HQC estimates the order consistently (\(plim~\hat{p}= p\))
\item SIC is even strongly consistent (\(\hat{p} \overset{a.s.}{\rightarrow} p\)) under quite general conditions
(e.g.\ if the actual DGP is a finite-order AR process and the maximum order is larger than the true order).
\end{itemize}
In practice, one often relies on the AIC as having too many lags is not as severe as having too few lags.
This is especially true in small samples.
Expand All @@ -19,8 +21,10 @@
one needs to use the same sample size across models with different orders.
In other words, the number of pre-sample values set aside for estimation is determined by the maximum order \(p^{\text{max}}\).


\item \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/lagOrderSelectionARp.m}
\item
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/lagOrderSelectionARp.m}

\item[3./4.]
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/AR4LagSelection.m}

\item[3./4.] \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/AR4LagSelection.m}
\end{enumerate}
38 changes: 25 additions & 13 deletions exercises/portmanteau_test.tex
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,38 @@
The null hypothesis of no residual autocorrelation is rejected for large values of the test statistic.

\begin{itemize}
\item Load quarterly data for the price index of US Gross National Product given in \texttt{gnpdeflator.csv}.
This is a chain-type price index with basis year 2005.
The data is seasonally adjusted and spans the period from 1954.Q4 to 2007.Q4.
\item Compute the inflation series.
That is, take the first difference of the log of gnpdeflator.
\item Use the Akaike information criteria to determine the lag length \(\hat{p}\).
\item Estimate two models with OLS:
(i) an \(AR(\hat{p})\) model and
(ii) an \(AR(1)\) model.
\item Set \(h=\hat{p}+10\) and compute \(Q_h\) as well as the corresponding p-value for both models.
\item Comment, based on your findings, whether the residuals are white noise.

\item
Load quarterly data for the price index of US Gross National Product given in \texttt{gnpdeflator.csv}.
This is a chain-type price index with basis year 2005.
The data is seasonally adjusted and spans the period from 1954.Q4 to 2007.Q4.

\item
Compute the inflation series.
That is, take the first difference of the log of gnpdeflator.

\item
Use the Akaike information criteria to determine the lag length \(\hat{p}\).

\item
Estimate two models with {OLS}:
(i) an \(AR(\hat{p})\) model and
(ii) an \(AR(1)\) model.

\item
Set \(h=\hat{p}+10\) and compute \(Q_h\) as well as the corresponding p-value for both models.

\item
Comment, based on your findings, whether the residuals are white noise.
\end{itemize}

\paragraph{Readings:}
\begin{itemize}
\item \textcite{Lutkepohl_2004_UnivariateTimeSeries}.
\item \textcite{Lutkepohl_2004_UnivariateTimeSeries}
\end{itemize}

\begin{solution}\textbf{Solution to \nameref{ex:PortmanteauTestResidualAutocorrelation}}
\ifDisplaySolutions
\ifDisplaySolutions%
\input{exercises/portmanteau_test_solution.tex}
\fi
\newpage
Expand Down
30 changes: 30 additions & 0 deletions week_5.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
% !TEX root = week_5.tex
\input{exercises/_common_header.tex}
\Newassociation{solution}{Solution}{week_5_solution}
\newif\ifDisplaySolutions\DisplaySolutionstrue%

\begin{document}
\title{Quantitative Macroeconomics\\~\\Winter 2024/25\\~\\Week 5}
\author{Willi Mutschler\\[email protected]}
\date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Quantitative-Macroeconomics/releases/latest/download/week_5.pdf}{GitHub}}
\maketitle\thispagestyle{empty}

\newpage
\Opensolutionfile{week_5_solution}[week_5_solution]
\tableofcontents\thispagestyle{empty}\newpage

\setcounter{page}{1}
\input{exercises/information_criteria_ar_p.tex}\newpage
\input{exercises/portmanteau_test.tex}\newpage
\input{exercises/bootstrap_ci_ar1.tex}\newpage
\printbibliography%
\newpage

\Closesolutionfile{week_5_solution}
\ifDisplaySolutions%
\newpage
\appendix
\section{Solutions}
\input{week_5_solution}
\fi
\end{document}

0 comments on commit 76a19cb

Please sign in to comment.