% EXAMPLE TO SHOW THE OLS ESTIMATOR IS ASYMPTOTICALLY NORMAL % Load in Data clc; n = 51; M = importdata('matlabex10data.txt','\t',1); data = M.data; n = size(data,1); loops = 50000; % Name Variables year = data(:,1); undergrads = data(:,2); oilprice = data(:,3); seniors = data(:,4); % Redefine Variables y = undergrads; x = [ones(n,1) oilprice seniors]; [n,k] = size(x); % Initial OLS Regression b = inv(x'*x)*(x'*y); e = y - x*b; s2 = (e'*e)/(n-k); % Loop to Simulate Artifical Data and Calculate OLS theta = 1; bhat = zeros(k,loops); n2 = 40; for (i=1:1:loops); x2 = x(1:n2,:); y = x2*b + sqrt(s2)*((rand(n2,1)-0.5)/sqrt(1/12)); bhat(:,i) = inv(x2'*x2)*(x2'*y); end; % Sampling Distribution hold on; sx = inv(x2'*x2); bz = (bhat(2,:) - b(2))/(sqrt(s2)*sqrt(sx(2,2))); histogram(bz,100,'Normalization','pdf'); xvalues = linspace(-3,3,100); f = (1/sqrt(2*pi))*exp(-xvalues.^2/2); plot(xvalues,f);