%steadhnn.m
%normal shocks
%Program to compute learning with productivity
% shocks. Agents estimate steady state with constant gain
% Used to generate data for Figures 14.1 and 14.2
% Generated data for figures are in eviews file
T=100000;
randn('seed',0);
t1=clock;
mod=max(1,round(T/1000));
S=round(T/mod);
nm=zeros(S,1);
xem=zeros(S,1);
eps=.25;
sig=.1;
capa=.0805;
a=.025;
alp=.9;
lam=.5;
k=40;
istar=19.5;
bet=1.007;
gam=0.04;
del=.15;
tau=0.15;
initn=2.3;
n=zeros(T,1);
xe=zeros(T+1,1);
xe(1)=(initn^(1+eps))/alp;
i=1;
for j=1:T;
n(j)=(alp*xe(j))^(1/(1+eps));
psi=capa*(max(istar,lam*k*n(j)/(1+a*lam*k*n(j))))^bet;
%nu=1+tau*(0.5-rand(1));
%nu shock here will have lognormal with mean one and same 
%variance as uniform [-tau,tau], i.e. (tau^2)/12

u=((log(1+(tau^2)/12))^0.5)*randn(1);
nu=exp(u-0.5*log(1+(tau^2)/12));

q=n(j)^alp*psi*nu;
x=((1-gam)*q)^(1-sig);
xe(j+1)=xe(j)+del*(x-xe(j));
m=j-mod*round(j/mod);
if m==0;
        nm(i)=n(j);
        xem(i)=xe(j);
        i=i+1;
end;
end;
t2=clock;
emin=etime(t2,t1)/60
i=i-1;
%plot(nm(1:i))
plot(n)
