%RIntang     Start with levels for ym, yo, c, xm, xo, g, h, ho, tauc,
% _Steady    and tauh and back out some of the parameters for the
%            restricted 3-sector growth model with intangible capital
%            described in the Appendix to
%
%               Unmeasured Investment and the 1990s US Hours Boom
%               by Ellen McGrattan and Ed Prescott
                                                                                
%            Ellen McGrattan, 7-26-05
%            Revised, ERM, 8-13-07
%---------------------------------------------------------------------
% 1. Observed levels

GDPs       = 1;
cs         = .7626*GDPs;
xms        = .2377*GDPs;
xns        = .1325*GDPs;
yns        = .3379*GDPs;
hs         = .2751;
hns        = .0611;
tauc       = .0657;
tauh       = .3109;
kTs        = 1.74/1.047*GDPs;
NIPAbw     = .464/1.047*GDPs;
NIPAptax   = .025/1.047*GDPs;

%
% 2. Fixed parameters
%

beta       = .98;
eta        = .01;
gamma      = .02;
sigma      = 1.000001;
taup       = .35;
taud       = .15;
taux       = 0;
taug       = 0;
chi        = 1;
deltI      = 0;
bhat       = beta*(1+gamma)^(-sigma);
grate      = (1+eta)*(1+gamma);

%
% 3. Implied parameters
%

yms        = GDPs;
ybs        = GDPs-yns;
xTs        = xms-xns;
gs         = GDPs-cs-xms;
hbs        = hs-hns;
tauk       = NIPAptax/kTs;

deltT      = xTs/kTs+1-grate;
rT         = ((1-bhat*(1-deltT))*(1+taux)-bhat*taup*deltT+ ...
              bhat*(1-taup)*tauk)/ (bhat*(1-taup));
rI         = ((1-bhat*(1-deltI))*(taug+(1-chi)*(1-tauh)+ ...
              chi*(1-taup)*(1-taud)))/ (bhat*(1-taud)*(1-taup));

x0         = .6;
for i=1:20;
  lshare   = x0; 
  tybs     = (NIPAbw-(1-chi)*ybs)/(lshare-1+chi);
  xIs      = tybs-ybs;
  kIs      = xIs/(grate-1+deltI);
  res      = 1-lshare-(rT*kTs+rI*kIs)/tybs;

  lshare   = x0+.0001; 
  tybs     = (NIPAbw-(1-chi)*ybs)/(lshare-1+chi);
  xIs      = tybs-ybs;
  kIs      = xIs/(grate-1+deltI);
  dres     = (1-lshare-(rT*kTs+rI*kIs)/tybs-res)/.0001;

  x0       = x0-res/dres;
end;
lshare     = x0;
tybs       = (NIPAbw-(1-chi)*ybs)/(lshare-1+chi);
xIs        = tybs-ybs;
kIs        = xIs/(grate-1+deltI);
theta      = rT*kTs/tybs;
phi        = 1-lshare-theta;
psi        = (1-tauh)*lshare*(1-hs)*tybs/((1+tauc)*cs*hbs);
A          = tybs/(kTs^theta.*kIs.^phi.*hbs.^lshare);
z          = A.^(1/lshare);

% 4. Write out results
%
fid    = fopen('rintang_params.m','w');
fprintf(fid,'beta       = %11.8f;\n',beta);
fprintf(fid,'deltT      = %11.8f;\n',deltT);
fprintf(fid,'deltI      = %11.8f;\n',deltI);
fprintf(fid,'eta        = %11.8f;\n',eta);
fprintf(fid,'gamma      = %11.8f;\n',gamma);
fprintf(fid,'phi        = %11.8f;\n',phi);
fprintf(fid,'psi        = %11.8f;\n',psi);
fprintf(fid,'sigma      = %11.8f;\n',sigma);
fprintf(fid,'theta      = %11.8f;\n',theta);
fprintf(fid,'zs         = %11.8f;\n',z);
fprintf(fid,'gs         = %11.8f;\n',gs);
fprintf(fid,'taucs      = %11.8f;\n',tauc);
fprintf(fid,'tauhs      = %11.8f;\n',tauh);
fprintf(fid,'taups      = %11.8f;\n',taup);
fprintf(fid,'tauks      = %11.8f;\n',tauk);
fprintf(fid,'tauds      = %11.8f;\n',taud);
fprintf(fid,'tauxs      = %11.8f;\n',taux);
fprintf(fid,'taugs      = %11.8f;\n',taug);
fprintf(fid,'chis       = %11.8f;\n',chi);
fprintf(fid,'kTs        = %11.8f;\n',kTs);
fprintf(fid,'kIs        = %11.8f;\n',kIs);
fprintf(fid,'xms        = %11.8f;\n',xms);
fprintf(fid,'xTs        = %11.8f;\n',xTs);
fprintf(fid,'xIs        = %11.8f;\n',xIs);
fprintf(fid,'xns        = %11.8f;\n',xns);
fprintf(fid,'hs         = %11.8f;\n',hs);
fprintf(fid,'hbs        = %11.8f;\n',hbs);
fprintf(fid,'hns        = %11.8f;\n',hns);
fprintf(fid,'ybs        = %11.8f;\n',ybs);
fprintf(fid,'yns        = %11.8f;\n',yns);
fprintf(fid,'gdps       = %11.8f;\n',ybs+yns);
fclose(fid);
