Dear Matlab, I am running Monte Carlo simulations to illustrate properties of the least squares estimator beta. I am using the following code:
% sample size n n=100;
% number of samples m m=1000;
for i=1:n x=4*randn(n,1); e=randn(n,1); y=alpha+beta*x+e; X=[ones(n,1) x]; beta_hatvec=(inv((X'*X)))*X'*y; beta_hat(1)=beta_hatvec(2); end
% compare to normal distribution histfit(beta_hat); mean(beta_hat<0.95)
However, after running I just obtain a blue bar at x=0 and the peak of the red line is also at x=0, while I would like to obtain a histogram similar to the figure attached (closer to x=1), to show that the distribution is not normal and there is a bias in my estimation. Could anyone explain me what am I doing wrong?