These are some notes for myself on econometrics in Mathematica.

## Set up the data

n = 100;

B0 = 1;

B1 = 2;

x = Table[Random[NormalDistribution[0, 1]], {n}];

\[Epsilon] = Table[Random[NormalDistribution[0, 1]], {n}];

y = B0 + B1*x + \[Epsilon];

ListPlot[Transpose[{x, y}]]

## Create the model matrix

iota = Table[1, {n}];

X = Transpose[{iota, x}];

k = Dimensions[X][[2]];

## Estimate coefficients

Bhat = Inverse[Transpose[X].X].Transpose[X].y

## Make predictions

yhat = X.Bhat;

ListPlot[{Transpose[{x, y}], Transpose[{x, yhat}]}]

### Compute the variance/covariance matrix

error = y - yhat;

sigma = Sqrt[Variance[error]]

sigma^2* Inverse[Transpose[X].X] // MatrixForm

## Regression statistics

### R squared

rsq = Variance[yhat]/Variance[y]