%MONTE_UR  Take ndraw realizations of shocks from RBC model with
%          unit root in technology estimated by MLE with US data.
%          Use them to get ndraw realizations of productivity and 
%          hours.  Apply SVAR filter to see if GR can detect the 
%          true impulse responses.
                                                                                
%          Ellen McGrattan, 3-17-04


randn('seed',1004)
ndraw = 1000;
for I=1:ndraw;
  drawq_ur;
  tem=[ys*cumprod(exp(Yt(:,1)))./exp(Yt(:,3)),exp(Yt(:,3))];
  save fakedat.dat tem -ascii
  fake_gr;
  for J=1:length(X2);
    X22(J,1) = (alpha.^[J-1:-1:0])*X2(1:J,2);
  end;
  Prd(:,I) = cumsum(X2(:,1))*100;
  Hrs(:,I) = X22*100;
end;
sHrs = sort(Hrs');
sPrd = sort(Prd');
mHrs = mean(sHrs);
mPrd = mean(sPrd);

lb   = round(.025*ndraw);
ub   = ndraw-round(.025*ndraw);
figure(1)
plot([sPrd(lb,:)',mPrd',sPrd(ub,:)'])
title('Monte Carlo: Impulse reponse of productivity to technology shock')
figure(2)
plot([sHrs(lb,:)',mHrs',sHrs(ub,:)'])
title('Monte Carlo: Impulse reponse of hours to technology shock')
