%%	lagMonte.m
%%	illustrate the estimation of a lagged dependent variable model in
%%	the presence of a moving average error

%%	Dick Startz
%%	January 1999

% Modified by Kyongwook Choi.

nTrials = 1000;
n = 100;
lambda = 0;
theta = .9;

lambdaHat = zeros(nTrials,1);

for i = 1:nTrials
   y = zeros(n,1);
   u = zeros(n,1);
	eps=randn(n,1);
   u(2:n) = eps(2:n) + theta*eps(1:n-1);	%%	note lag
   for j=2:n
   	y(j) = lambda*y(j-1) + u(j);
   end
   lambdaHat(i) = y(3:n)\y(2:n-1);		%% regress y on y(lagged)
end

% Note that there are two for..end command. 
% You should be careful to decide the location of the "end" command
% First part of for..end command dominates 1000 MC simulations, second part follows
% n=100.

hist(lambdaHat,20);
v= axis;
v(1:2) = [0 1];
axis(v);	%%set nice x-axis
title(['Lagged variable regression w/MA error \lambda=',num2str(lambda),...
      ' mean(\lambda^{hat})=',num2str(mean(lambdaHat))]);

