You only ever assign to the 1st element of beta_hat. I think you need to recheck your code.
1. if you are intending to do m samples of the beta coefficient, then you need to run the simulation m times and not n.
2. You probably mean to store to the ith element of beta_hat:
beta_hat(i)=beta_hatvec(2);
3. You should not use the inv() function to compute the coefficients. you can accomplish the same with:
beta_hatvec = (X'*X)\X'*y % The denominator for matrices can be seen as being the inverse.
doc mldivide
3b. You could also obtain the coefficients using polyfit (or fitlm of the Statistics and Machine Learning Toolbox) and avoid having to get low level with regression solutions.
4. I don't think mean(beta_hat<0.95) does what you expect. You are first creating a logical vector and taking the average of that. This is merely telling you the percentage of values which are less than 0.95. Maybe this is what you are looking for, but there are other ways of calculalting this which are more clear for someone reading your code.