Applied exercises
This section provides some exercises that are meant to deepen your knowledge in the topics covered in this section and to gain experience solving real-world problems.
Last updated
Was this helpful?
This section provides some exercises that are meant to deepen your knowledge in the topics covered in this section and to gain experience solving real-world problems.
Last updated
Was this helpful?
In this exercise you will compute the OLS estimator on a simulated data set using basic MATLAB commands. Please refer to the theory section below for the necessary formulas.
Import the simulated data from olsdata.m and compute the OLS estimator using matrix expressions. Create a results matrix which stacks the estimated parameters and the values supplied in the vector beta_true
side by side. Are the estimated and the true values close?
Next, read up on MATLABs regress
function on the MATLAB documentation page on regress. Estimate the OLS coefficient using this function and compare the results to the ones you computed manually.
Let be a vector of data on the dependent variable and let be a matrix with data on the regressors where the first column is a vector of ones.
The OLS estimator of the regression coefficients is defined as .
In this exercise you will compute the log-likelihood of a logit model on a simulated data set using basic MATLAB commands. Please refer to the theory section below for the necessary formulas.
Import the simulated data from logitdata.m and calculate the value of the log-likelihood for different values of the parameter vector using matrix expressions.
Approximately, for which value of is the log-likelihood maximal?
Consider the following discrete choice logit model with no constant and one regressor
In this exercise you will estimate a factor model on a simulated data set using basic MATLAB commands. Please refer to the theory section below for the necessary formulas.
We will use the following factor model
where all variables are scalars and is a binary variable (i.e. it has 0/1 values).
The log-likelihood of the data given a value for the parameter vector is defined as
Read up on MATLABs eig
function on the MATLAB documentation page on eig. Use the eig
function to estimate the matrix of factors and loadings for the following dataset for .
Caution: By default, eig
sorts the eigenvalues and corresponding vectors in ascending order of magnitude of the eigenvalues. Make sure you extract the eigenvectors corresponding to the largest eigenvalues.
The estimation above is valid only under the assumption that the factors are orthogonal i.e. . Use MATLABs scatter(x,y)
command and verify graphically that the normalization holds for the estimated factors. In the scatter command, x
should be the first factor (i.e. the first column of ) and y
should be the second factor.
where is large vector of series which we would like to explain by a lower number of factors. is a vector of factors and an vector of idiosyncratic shocks. is a matrix of factor loadings of dimension . is the number of observations.
Under some normalizations, the factors and their factor loadings can be estimated by principal components using the following formulae.
where is a matrix and is a matrix. denotes the first eigenvectors of the matrix which correspond to the largest eigenvalues.