%BCA_Wedges  Use parameters from bca_steady and first-order conditions
%            for a prototype buciness cycle to back out 3 wedges (A, tauh,
%            taux). See details in the Appendix to:
%
%               Unmeasured Investment and the 1990s US Hours Boom
%               by Ellen McGrattan and Ed Prescott
                                                                                
%            Ellen McGrattan, 11-1-05
%            Revised, ERM, 8-6-07
                                                                                
%---------------------------------------------------------------------
% Parameters (for steady state parameters, run bca_steady.m first)
%

bca_params

bhat       = beta*(1+gamma)^(-sigma);
thet1      = 1-theta;
grate      = (1+eta)*(1+gamma);

% Load NIPA data 
%
load ../DATA/observables.dat
t          = observables(:,1);
gdp        = observables(:,2)*gdps;
T          = length(gdp);
y          = gdp;
c          = observables(:,4)*gdps;
x          = observables(:,5)*gdps;
h          = observables(:,7);
tauc       = observables(:,9);
taup       = taups*ones(T,1);
tauk       = tauks*ones(T,1);
taud       = tauds*ones(T,1);
taux       = tauxs*ones(T,1);

%
% Back out variables
%
g          = gdp-x-c;
k          = ks*ones(T,1);
kn         = k;
for i=1:T-1;
  kn(i)    = ((1-delta)*k(i)+x(i))/grate;
  k(i+1)   = kn(i);
end;
kn(T)      = ((1-delta)*k(T)+x(T))/grate;
tauh       = 1-psi*(1+tauc).*c.*h./(thet1*y.*(1-h));    
z          = (y./(k.^theta)).^(1/thet1)./h;
xwedge     = ones(T,1);
xtau       = (1+taux).*(1-taud)./(1+tauc);
dtau       = (1-taud).*taup./(1+tauc);
ptau       = (1-taup).*(1-taud)./(1+tauc);
uc         = c.^(-sigma).*(1-h).^(psi*(1-sigma)); 
r          = theta*y./k;
%xwedge backards
X(T)  = uc(T)*xtau(T);
for i=T-1:-1:1;
  X(i) = bhat*(1-delta)*X(i+1)+ ...
             bhat*uc(i+1)*ptau(i+1)*(r(i+1)-tauk(i+1))+ ...
             bhat*uc(i+1)*delta*dtau(i+1);
end;
xwedge     = uc.*xtau./X(:);
return

inputs      = [z,g,tauc,tauh,xwedge];
initial     = [kn,h];

save inputs.dat inputs  -ascii -double
save vinitial.dat initial  -ascii -double

