Ordinary Least Squares

There are many econometric options in Matlab such as the Econometrics Toolbox, the Statistics Toolbox or manually entering the equations in by hand. In this section we will simulate an AR(1) process and then estimate its parameters using ordinary least squares. We compute our estimates by using both the statistics toolbox and manual entry.

Simulate an AR(1) Process

  • We simulate an AR(1) process exactly as described in the previous section

    \(y_{t} = c + \phi y_{t-1} + \epsilon_{t}\). The true parameters are:

\[\begin{split}c & = 5 \\ \phi &= 0.7 \\ \sigma &= 2\end{split}\]
_images/ols1.png

Discard Observations

  • We want to discard the first 200 observations so that initial values won’t influence our results. We also set X to equal the lagged values of Y
_images/ols2.png

Statistics Toolbox Approach

  • The statistics toolbox estimates a linear model with the function fitlm(X,y)
_images/ols3.png
  • fitlm() generates output:
_images/ols4.png

Solving Manually

  • Alternatively, we can enter the equations manually:
_images/ols6.png
  • Which generates output:
_images/ols5.png
  • You can see that the two different methods produce the same results