# Where should randomness come from in the Monte Carlo simulations?

Suppose that I want to check how good OLS works in some specific environment using Monte Carlo. I can simulate $Y=X\beta+\epsilon$. What should I do in Monte Carlo simulations, do I simulate the whole model on each replication, or do I simulate only $\epsilon$ in each replication, while $X$ is the same across all replications.

Generally you would have some distributional specification for $X$ and re-simulate $X$ on each monte carlo iteration as apposed to using the same $X$ on each iteration. This way the monte carlo simulation would apply to the entire population of $(y,X)$ as apposed to just one finite sample. Also, you have to have some specification for $\epsilon$. Lets say, $\epsilon \sim N(0,\sigma^2)$. Here is how I would do it in R (pseudo code).

b.estimates=matrix(NA,nrow=b,ncol=k) #k is the number of variables
for(i in 1:b)
{
#Simulate X here
e = rnorm(n,0,sd=sigma)
y= X%*%Beta +e
b.estimates[i,]=solve(t(X)%*%X)%*%t(X)%*%y
}


Hope that helps

• Thank you for your answer. I'm asking because I have a problem set, where professor asks to simulate $X$ ones and then to create randomness in Monte Carlo using $\epsilon$, that is in each iteration, only $\epsilon$ and $Y$ are resimulated. I was wondering whether this was just a particular problem, and whether I should do Monte Carlo this way in practice. Drawing $(\epsilon,X)$ in each iteration makes more sense to me as well. – Laimond Dec 7 '14 at 10:29