%hysterfig.m
%Program to compute learning with productivity
% shocks. Agents estimate steady state with constant gain
% fiscal parameter gam follows cos wave. 25 full cycles
% Figure 14.4 of book
T=314159;
rand('state',0);
mod=max(1,round(T/4000+0.5));
S=round(T/mod);
nm=zeros(S,1);
gen=zeros(S,1);
%xem=zeros(S,1);
gamm=zeros(S,1);
eps=.25;
sig=.1;
capa=.085;
a=.025;
alp=.9;
lam=.5;
k=40;
istar=14.1935;
bet=1;
maxgam=0.12;
w=.0005;
del=.15;
tau=0.20;
initn=1.0;
n=zeros(T,1);
gam=zeros(T,1);
xe=zeros(T+1,1);
xe(1)=(initn^(1+eps))/alp;
i=1;
for j=1:T;
gam(j)=maxgam*(1+cos(w*j))/2;
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));
q=n(j)^alp*psi*nu;
x=((1-gam(j))*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);
	gen(i)=j;
%        xem(i)=xe(j);
        gamm(i)=gam(j);
        i=i+1;
end;
end;
i=i-1;
%plot(gamm(1:i),nm(1:i))
plot(gam,n)
title('Figure 14.4')
ylabel('Employment')
xlabel('Government share zeta')

