
clear all; close all;


n = 1000;
nsim = 50000;
sigma = 1;

beta = zeros(nsim,1);
beta0 = 2;
for j = 1:nsim
    x = randn(n,1);
    u = exprnd(1,n,1)-1; % generate n samples from an exponential distribution
    y = 1 + beta0*x+sigma*u;
    [b,se] = myols(y,[ones(n,1) x]);
    beta(j) = (b(2)-beta0)/se(2);
end

xi = (-5:0.01:5)';
figure(1)
hist(beta,40); 

figure(2), qqplot(beta);
title(['QQ plot of t-statistic versus N(0,1) when n= ' num2str(n)]);
ylabel('Quantiles of t-statistics');
xlabel('Quantiles of N(0,1)');
