Applied Exercises
1. Estimate a logit regression using MLE
In this exercise you will estimate a logit regression model using maximum likelihood.
Recall the log likelihood of the logit model from Section 1:
Using the dataset provided in Section 1, write a script that estimates the unknown parameter using
fminuncfminsearchfminbnd
Using the log likelihood, create a target function .m file that accepts the unknown parameter and the dataset as inputs and outputs the log likelihood for those parameter values.
In another script, select the options and starting values you want for each estimation function. Then use the optimization functions (1)-(3) to estimate the unknown parameter.
Bonus part: Set up your script using
switch-caseso that when you run the script, it begins by asking the user which method is desired. Hint: Use matlab'sinputfunction to ask the user which method to use.
2. Estimate an AR(1) regression using MLE
In this exercise you will estimate an AR(1) regression using Maximum Likelihood.
This task consists of two parts. In the first part you will simulate data from a stationary AR(1). In the second part you will use this data to estimate the AR(1) model by MLE and verify that you correctly estimated and .
Simulate data from a stationary AR(1) model building on the code example we covered in Part A of unit 4. Set and use and use 200 burn-in periods. Use the same parameter values that we used in the example. After you have simulated the data, export the vector containing the values into a .mat file using the
savecommand.Create a new script and load the .mat file you just generated. Write function file for the target function which calculates the likelihood given parameter values for and . Then, create a new script and use
fminuncto estimate and from the data on you just imported.
Note: Remember that you have to choose sensible starting values for the optimisation algorithm. Make sure these starting values are different from the true parameter values you used to generate the data.
Hint: Since is a variance, it should never take negative values. You can enforce this without having to rely on a constrained optimization routine. You can solve this by defining and optimize over instead of . Remember that when you compare your estimated parameter values to the ones you used to generate the data that you should compare to and not .
Theory
Consider the following stable AR(1) model
We would like to estimate the unknown parameters by maximum likelihood. Therefore we would like to find the values of and which maximize the following log-likelihood.
3. Solving an optimal consumption problem
In this exercise you will solve an optimal consumption problem using MATLABs numerical solvers.
Consider a consumer who solves the following consumption () vs. leisure () problem
subject to the budget constraint where is the wage.
Write a Matlab program that solves this problem for given parameter values of , , , and . In particular
Start by reducing the problem to a one-dimensional problem in either or .
First solve the one-dimensional problem using the
fzerofunction.Then solve the one-dimensional problem using the
fminuncfunction.
Last updated
Was this helpful?