#Sampling Distribution of OLS Slope Coefficient # n=100 nreps=20 beta=.3 alpha=0 x=1:n plot(x,alpha+beta*x,ylab="y",col="blue") betabig=NULL for(iter in 1:nreps) { eps=10*rnorm(n) y=alpha+beta*x+eps fit=lsfit(x,y) abline(fit) betabig=c(betabig,fit$coefficient[2]) } betabig=as.numeric(betabig) title(main=paste("Sampling Distribution of Least Squares Line,",nreps,"replications alpha=0, beta=.3, Ave beta hat = ", round(mean(betabig),3),", SD beta hat =" , round(sqrt(var(betabig)),3)," Least Squares Lines (Black), True Line (Blue)")) #