It is a way to test econometric theories via simulation.
How is it used in econometrics?
Suppose you are interested in checking what happens to OLS estimators if \(E[u|x]=0\) (the error term and \(x\) are not correlated) is violated.
Question
Can you use the real data to do this?
You generate data (you have control over how data are generated)
Pseudo random number generators (Pseudo RNG)
Algorithms for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers
Examples
Draw from a uniform distribution:
Numbers drawn using pseudo random number generators are not truly random
Demonstration
Question
What benefits does setting a seed have?
\(x \sim N(0, 1)\)
\(x \sim N(2, 2)\)
For each distribution, you have four different kinds of functions:
d
norm
: density functionp
norm
: distribution functionq
norm
: quantile functionr
norm
: random drawdnorm(x)
gives you the height of the density function at \(x\).
dnorm(-1)
and dnorm(2)
pnorm(x)
gives you the probability that a single random draw is less than \(x\).
qnorm(x)
, where \(0 < x < 1\), gives you a number \(\pi\), where the probability of observing a number from a single random draw is less than \(\pi\) with probability of \(x\).
We call the output of qnorm(x)
, \(x%\) quantile of the standard Normal distribution (because the default is mean = 0
and sd = 1
for rnorm()
).
Question
Why do the steps \(1-3\) many many times?
Question
Is sample mean really an unbiased estimator of the expected value?
That is, is \(E[\frac{1}{n}\sum_{i=1}^n x_i] = E[x]\), where \(x_i\) is an independent random draw from the same distribution,
R code
Verbally
For each of \(i\) in \(1:B\) \((1, 2, \dots, 1000)\), do print(i)
.
i
takes the value of 1, and then print(1)
i
takes the value of 2, and then print(2)
i
takes the value of 999, and then print(999)
i
takes the value of 1000, and then print(1000)
Compare your estimates with the true parameter
Model
\[\begin{aligned} y = \beta_0 + \beta_1 x + u \\ \end{aligned}\]Variance of the OLS estimator
True Variance of \(\hat{\beta_1}\): \(V(\hat{\beta_1}) = \frac{\sigma^2}{\sum_{i=1}^n (x_i-\bar{x})^2} = \frac{\sigma^2}{SST_X}\)
Its estimator: \(\widehat{V(\hat{\beta_1})} =\frac{\hat{\sigma}^2}{SST_X} = \frac{\sum_{i=1}^n \hat{u}_i^2}{n-2} \times \frac{1}{SST_X}\)
Question
Does the estimator really work? (Is it unbiased?)
True Variance
\[V(\hat{\beta}) = 4/112.07 = 0.0357\]
Check
Your Estimates of Variance of \(\hat{\beta_1}\)?
Using MC simulations, find out how the variation in \(x\) affects the OLS estimators
Model setup
\[\begin{align} y = \beta_0 + \beta_1 x_1 + u \\ y = \beta_0 + \beta_1 x_2 + u \end{align}\]