Skip to content

Commit

Permalink
Added VAR estimation exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
wmutschl committed Nov 22, 2024
1 parent 658f0b2 commit 5f30514
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/dynare-6.2-matlab-r2024b-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ jobs:
matrixAlgebraKroneckerFormula;
matrixAlgebraRotation;
matrixAlgebraCholesky;
matrixAlgebraLyapunovComparison;
matrixAlgebraLyapunovComparison;
VARpDimensionsIllustration;
threeVariableVAROLS;
threeVariableVARML;
5 changes: 4 additions & 1 deletion .github/workflows/dynare-6.2-matlab-r2024b-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@ jobs:
matrixAlgebraKroneckerFormula;
matrixAlgebraRotation;
matrixAlgebraCholesky;
matrixAlgebraLyapunovComparison;
matrixAlgebraLyapunovComparison;
VARpDimensionsIllustration;
threeVariableVAROLS;
threeVariableVARML;
5 changes: 4 additions & 1 deletion .github/workflows/dynare-6.2-matlab-r2024b-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ jobs:
matrixAlgebraKroneckerFormula;
matrixAlgebraRotation;
matrixAlgebraCholesky;
matrixAlgebraLyapunovComparison;
matrixAlgebraLyapunovComparison;
VARpDimensionsIllustration;
threeVariableVAROLS;
threeVariableVARML;
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Please feel free to use this for teaching or learning purposes; however, taking


<details>
<summary> Week 6: Multivariate Time Series Concepts</summary>
<summary> Week 6: Multivariate Time Series Concepts, Estimating VAR with OLS and ML</summary>

### Goals

Expand All @@ -140,11 +140,12 @@ Familiarize yourself with
* multivariate notation and dimensions of vectors and matrices for VAR(p) models
* autocovariances, stability and covariance-stationarity in multivariate VAR(p) models
* the companion form of a VAR(p) model
* estimate VAR models with Ordinary Least Squares (OLS) and Maximum Likelihood (ML)

### To Do

* [x] Review the solutions of [last week's exercises](https://github.com/wmutschl/Quantitative-Macroeconomics/releases/latest/download/week_5.pdf) and write down all your questions
* [x] Read Kilian and Lütkepohl (2007, Ch. 2.2) and Lütkepohl (2005, Chapter 2 and Appendix A); make note of all the aspects and concepts that you are not familiar with or that you find difficult to understand
* [x] Read Kilian and Lütkepohl (2007, Ch. 2.2, 2.3) and Lütkepohl (2005, Chapter 2 and Appendix A); make note of all the aspects and concepts that you are not familiar with or that you find difficult to understand
* [x] Do exercise 1 of week 6
* [x] If you have questions, get in touch with me via email or (better) [schedule a meeting](https://schedule.mutschler.eu)

Expand All @@ -154,11 +155,10 @@ Familiarize yourself with
<!---
<details>
<summary> Week 7: Estimating VAR model with OLS and ML; The identification problem in SVAR models</summary>
<summary> Week 7: The identification problem in SVAR models</summary>
### Goals
* estimate VAR models with Ordinary Least Squares (OLS) and Maximum Likelihood (ML)
* understand the identification problem in SVAR models
### To Do
Expand Down
8 changes: 4 additions & 4 deletions exercises/matrix_algebra_solution.tex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
\begin{enumerate}
\item \lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/matrixAlgebraEigenvalues.m}
In the univariate AR{(1)} model we would check whether the autocorrelation coefficient is between -1 and 1,
i.e.\ whether \(|\phi| = |A|<1\) such that \(\sum_{j=0}^\infty {(AL)}^j=1/(1-AL)\)
In the univariate AR{(1)} model we would check whether the autocorrelation coefficient is between -1 and 1, i.e.\
whether \(|\phi| = |A|<1\) such that \(\sum_{j=0}^\infty {(AL)}^j=1/(1-AL)\)
where \(L\) is the lag operator.
In the multivariate case, we want to check the same thing,
i.e.| \(\sum_{j=0}^\infty {(AL)}^j={(1-AL)}^{-1}\).
In the multivariate case, we want to check the same thing, i.e.\
\(\sum_{j=0}^\infty {(AL)}^j={(1-AL)}^{-1}\).
Note that \(A\) is a square matrix and taking the power of a matrix is not a trivial task.
One convenient way to do so, is to consider an eigenvalue decomposition (if it exists):
\[A= Q \Lambda Q^{-1}\]
Expand Down
16 changes: 8 additions & 8 deletions exercises/ml_var_p.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\section[Maximum Likelihood Estimation of VAR(p)]{Maximum Likelihood Estimation of VAR(p)\label{ex:MaximumLikelihoodEstimationVARp}}
Consider the VAR(p) model with constant written in the more compact form
\section[Maximum Likelihood Estimation of VAR{(p)}]{Maximum Likelihood Estimation of VAR{(p)}\label{ex:MaximumLikelihoodEstimationVARp}}
Consider the VAR{(p)} model with constant written in the more compact form
\begin{align*}
y_t = [c, A_1, \ldots, A_p] Z_{t-1} + u_t = A Z_{t-1}+ u_t
\end{align*}
Expand All @@ -22,15 +22,15 @@
Comment on the asymptotic distribution.

\item Provide an expression for the ML estimator \(\widetilde{\Sigma_u}\) of the innovation covariance matrix.

\item Consider data given in \texttt{threeVariableVAR.csv} for \(y_t = (\Delta gnp_t,i_t,\Delta p_t)'\),
where \(gnp_t\) denotes the log of U.S. real GNP,
\(p_t\) the corresponding GNP deflator in logs,
and \(i_t\) the federal funds rate, averaged by quarter.
where \(gnp_t\) denotes the log of U.S. real GNP,
\(p_t\) the corresponding GNP deflator in logs,
and \(i_t\) the federal funds rate, averaged by quarter.
The estimation period is restricted to 1954q4 to 2007q4.
\begin{itemize}
\item Estimate the parameters with Maximum Likelihood.
\item Compare your estimation results to an OLS estimation.
\item Estimate the parameters with Maximum Likelihood.
\item Compare your estimation results to an OLS estimation.
\end{itemize}

\end{enumerate}
Expand Down
19 changes: 11 additions & 8 deletions exercises/ml_var_p_solution.tex
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
\begin{enumerate}
\item From the univariate case (and undergraduate econometrics),
we know that both estimators are identical;
hence, the asymptotic normal distribution holds as well.
\item
From the univariate case (and undergraduate econometrics),
we know that both estimators are identical;
hence, the asymptotic normal distribution holds as well.

\item Taking the derivative of the conditional log-likelihood function with respect to \(\Sigma_u\) yields:
\item
Taking the derivative of the conditional log-likelihood function with respect to \(\Sigma_u\) yields:
\begin{align*}
\widetilde{\Sigma}_u = \frac{\hat{U}\hat{U}'}{T}
\end{align*}
where \(\hat{U}\) are both the ML and OLS residuals (as \(\widetilde{A}=\widehat{A}\)).
Note that from previous exercises in the univariate case
we have already seen that the only difference to the OLS estimator of \(\Sigma_u\)
is given in the fact that for ML we don't correct the degrees of freedom,
but simply divide by the \textbf{effective} sample size used in the estimation \(T\).
we have already seen that the only difference to the OLS estimator of \(\Sigma_u\)
is given in the fact that for ML we don't correct the degrees of freedom,
but simply divide by the \textbf{effective} sample size used in the estimation \(T\).

\item See the previous exercise, as the \texttt{VARReducedForm} function also outputs the ML estimate of \(\Sigma_u\):
\item
See the previous exercise, as the \texttt{VARReducedForm} function also outputs the ML estimate of \(\Sigma_u\):
\lstinputlisting[style=Matlab-editor,basicstyle=\mlttfamily,title=\lstname]{progs/matlab/threeVariableVARML.m}

\end{enumerate}
14 changes: 7 additions & 7 deletions exercises/ols_var_p.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\section[Ordinary Least Squares Estimation of VAR(p)]{Ordinary Least Squares Estimation of VAR(p)\label{ex:OrdinaryLeastSquaresEstimationVARp}}
Consider the VAR(p) model with a constant written in the compact form
\section[Ordinary Least Squares Estimation of VAR{(p)}]{Ordinary Least Squares Estimation of VAR{(p)}\label{ex:OrdinaryLeastSquaresEstimationVARp}}
Consider the VAR{(p)} model with a constant written in the compact form
\begin{align*}
y_t = [c, A_1, \ldots, A_p] Z_{t-1} + u_t = A Z_{t-1}+ u_t
\end{align*}
Expand All @@ -9,7 +9,7 @@
ordinary least squares for each equation separately results in efficient estimators.
The OLS estimator is
\begin{align*}
\hat{A} = \left[ \hat{c}, \hat{A_1}, \ldots ,\hat{A_p}\right] = \left(\sum_{t=1}^{T}y_t Z_{t-1}'\right)\left(\sum_{t=1}^{T}Z_{t-1}Z_{t-1}'\right)^{-1} = Y Z'{(ZZ')}^{-1}
\hat{A} = \left[ \hat{c}, \hat{A_1}, \ldots ,\hat{A_p}\right] = \left(\sum_{t=1}^{T}y_t Z_{t-1}'\right){\left(\sum_{t=1}^{T}Z_{t-1}Z_{t-1}'\right)}^{-1} = Y Z'{(ZZ')}^{-1}
\end{align*}
where \(Y=[y_1, \ldots, y_T]\) and \(Z=[Z_0, \ldots, Z_{T-1}]\).
More precisely, stacking the columns of \(A = [c, A_1,\ldots ,A_p]\) in the vector \(\alpha = vec(A)\),
Expand All @@ -19,7 +19,7 @@
where \(\Sigma_{\hat{\alpha}} = plim(\frac{1}{T}ZZ')^{-1}\otimes \Sigma_u\), if the process is stable.
Under fairly general assumptions this estimator has an asymptotic normal distribution.
A sufficient condition for the consistency and asymptotic normality of \(\hat{A}\) would be
that \(u_t\) is a continuous iid random variable with four finite moments.
that \(u_t\) is a continuous white noise random variable with four finite moments.
A consistent estimator of the innovation covariance matrix \(\Sigma_u\) is, for example,
\begin{align*}
\hat{\Sigma}_u = \frac{\hat{U}\hat{U}'}{T-Kp-1}
Expand All @@ -33,8 +33,8 @@
In other words, asymptotically the usual t-statistics can be used for testing restrictions on individual coefficients
and for setting up confidence intervals.
\begin{enumerate}
\item What are the dimensions of \(y_t\), \(Y\), \(u_t\), \(U\), \(c\), \(A_1\), \ldots, \(A_p\), \(A\), \(\alpha\), \(Z_{t-1}\), \(Z\), \(\Sigma_u\) and \(\Sigma_{\hat{\alpha}}\).
\item Modify your \texttt{ARpOLS} function such that it is able to estimate VAR(p) models.
\item What are the dimensions of \(y_t\), \(Y\), \(u_t\), \(U\), \(c\), \(A_1\), \ldots, \(A_p\), \(A\), \(\alpha \), \(Z_{t-1}\), \(Z\), \(\Sigma_u\) and \(\Sigma_{\hat{\alpha}}\).
\item Modify your \texttt{ARpOLS} function such that it is able to estimate VAR{(p)} models.
Save the modified function as \texttt{VARReducedForm}.
\item Consider data given in \texttt{threeVariableVAR.csv} for \(y_t = (\Delta gnp_t,i_t,\Delta p_t)'\),
where \(gnp_t\) denotes the log of U.S. real GNP,
Expand All @@ -43,7 +43,7 @@
The estimation period is restricted to 1954q4 to 2007q4.
\begin{itemize}
\item Load the data and visualize it. Comment whether you think the data looks stationary.
\item Estimate a VAR(4) model using the \texttt{VARReducedForm} function.
\item Estimate a VAR{(4)} model using the \texttt{VARReducedForm} function.
Examine the stability of the estimated process
and the significance of the estimated parameters at a \(95\% \) level.
\end{itemize}
Expand Down
4 changes: 3 additions & 1 deletion week_6.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\begin{document}
\title{Quantitative Macroeconomics\\~\\Winter 2024/25\\~\\Week 6}
\author{Willi Mutschler\\[email protected]}
\date{Version: 1.0\\Latest version available on: \href{https://github.com/wmutschl/Quantitative-Macroeconomics/releases/latest/download/week_6.pdf}{GitHub}}
\date{Version: 1.1\\Latest version available on: \href{https://github.com/wmutschl/Quantitative-Macroeconomics/releases/latest/download/week_6.pdf}{GitHub}}
\maketitle\thispagestyle{empty}

\newpage
Expand All @@ -17,6 +17,8 @@
\input{exercises/matrix_algebra.tex}\newpage
\input{exercises/understanding_multivariate_concepts.tex}\newpage
\input{exercises/dimensions_and_var_one_representation.tex}\newpage
\input{exercises/ols_var_p.tex}\newpage
\input{exercises/ml_var_p.tex}\newpage
\printbibliography%
\newpage

Expand Down

0 comments on commit 5f30514

Please sign in to comment.