%RESULTS   plots results for 
%
%              Technology Capital and the US Current Account
%              by Ellen McGrattan and Ed Prescott
%
%          The file is called by main.m or by altparams.m
%

% Ellen McGrattan, 2-27-08
% Revised, ERM, 9-21-09

beta    = param(1);
chidu   = param(2);
chifu   = param(3);
deltT   = param(4);
deltM   = param(5);
deltI   = param(6);
gamN    = param(7); 
gamY    = param(8);
phi     = param(9);
psi     = param(10);
tauc    = param(11);
taul    = param(12);
alphT   = param(13);
alphI   = param(14);
b0      = param(15);
sdu0    = param(16);
sfu0    = param(17);
T       = param(18);
bn      = param(19:18+T);
taud    = param(19+T:18+2*T);
taupu   = param(19+2*T:18+3*T);
taupr   = param(19+3*T:18+4*T);
Tran    = param(19+4*T:18+5*T);
lnbu    = param(19+5*T:18+6*T);
lnbr    = param(19+6*T:18+7*T);
xnbuy   = param(19+7*T:18+8*T);
ynbuy   = param(19+8*T:18+9*T);
xnbry   = param(19+9*T:18+10*T);
ynbry   = param(19+10*T:18+11*T);
Nr      = param(19+11*T:18+12*T);
Nu      = param(19+12*T:18+13*T);
sigr    = param(19+13*T:18+14*T);
sigu    = param(19+14*T:18+15*T);
sfun    = param(19+15*T:18+16*T);
rsize   = param(19+16*T:18+17*T);
Adu0    = param(19+17*T);
kTdu0   = param(20+17*T);
kTdr0   = param(21+17*T);
kTfu0   = param(22+17*T);
kTfr0   = param(23+17*T);
Md0     = param(24+17*T);
Mf0     = param(25+17*T);
kIdivkT = param(26+17*T);
nyr     = param(length(param));
t       = 1960:nyr:1959+nyr*T;
kIdu0   = kIdivkT*kTdu0;
kIdr0   = kIdivkT*kTdr0;
kIfu0   = kIdivkT*kTfu0;
kIfr0   = kIdivkT*kTfr0;
Adu     = Adu0*ones(T,1);
Afr     = Adu.*(rsize.*Nu./Nr).^(1-(alphT+alphI)*(1-phi));
Adr     = sigr.*Afr;
Afu     = sigu.*Adu;
sfu     = [sfu0;sfun(1:T-1)];
taupun  = [taupu(2:T);taupu(T)];
tauprn  = [taupr(2:T);taupr(T)];
Nrn     = [Nr(2:T);Nr(T)];
Nun     = [Nu(2:T);Nu(T)];
chidr   = 1-chidu;
chifr   = 1-chifu;
alphL   = 1-alphT-alphI;
gamy    = (1+gamY)/(1+gamN)-1;
betg    = beta/(1+gamy);
irate   = (1+gamy)/beta-1;
phi1    = 1-phi;

%
% Unknowns being computed
%
X       = zeros(T,11);
X(:)    = X0;
cu      = X(:,1);
cr      = X(:,2);
lu      = X(:,3);
lr      = X(:,4);
sdun    = X(:,5);
kTdun   = X(:,6);
kTdrn   = X(:,7);
kTfun   = X(:,8);
kTfrn   = X(:,9);
Mdn     = X(:,10);
Mfn     = X(:,11);

%
% Intermediate variables
%

%   * utilities
%
o       = ones(T,1);
ucu     = o./cu;
ucr     = o./cr;
ulu     = psi*o./(1-lu-lnbu);
ulr     = psi*o./(1-lr-lnbr);
ucun    = [ucu(2:T);ucu(T)];
ucrn    = [ucr(2:T);ucr(T)];

%   * interest rates
%
rbn     = (ucu./ucun/betg)-1;
rb      = [irate;rbn(1:T-1)];
rTun    = rbn./(1-taupun)+deltT;
rTrn    = rbn./(1-tauprn)+deltT;
rIun    = (1-taupu).*(1+rbn)./(1-taupun)+deltI-1;
rIrn    = (1-taupr).*(1+rbn)./(1-tauprn)+deltI-1;

%   * intangible capitals
%
uratio  = alphI*rTun./(alphT*rIun);
rratio  = alphI*rTrn./(alphT*rIrn);
kIdun   = uratio.*kTdun;
kIdrn   = rratio.*kTdrn;
kIfun   = uratio.*kTfun;
kIfrn   = rratio.*kTfrn;

%   * this period stocks
%
kTdu    = [kTdu0;kTdun(1:T-1)];
kTdr    = [kTdr0;kTdrn(1:T-1)];
kTfu    = [kTfu0;kTfun(1:T-1)];
kTfr    = [kTfr0;kTfrn(1:T-1)];
kIdu    = [kIdu0;kIdun(1:T-1)];
kIdr    = [kIdr0;kIdrn(1:T-1)];
kIfu    = [kIfu0;kIfun(1:T-1)];
kIfr    = [kIfr0;kIfrn(1:T-1)];
Md      = [Md0;Mdn(1:T-1)];
Mf      = [Mf0;Mfn(1:T-1)];
sdu     = [sdu0;sdun(1:T-1)];
sfu     = [sfu0;sfun(1:T-1)];
b       = [b0;bn(1:T-1)];
kIdun(T)= kIdu(T);
kIdrn(T)= kIdr(T);
kIfun(T)= kIfu(T);
kIfrn(T)= kIfr(T);

%   * wage rates
%
wu      = (1+tauc)/(1-taul)*ulu./ucu;
wr      = (1+tauc)/(1-taul)*ulr./ucr;

%   * productivities
%
prdu    = wu/(phi1*alphL);
prdr    = wr/(phi1*alphL);

%   * outputs
%
ydu     = (Adu.*kTdu.^(phi1*alphT).*kIdu.^(phi1*alphI).* ...
           prdu.^(-phi1*alphL).*Md.^phi).^(1/(1-phi1*alphL));
ydr     = (Adr.*kTdr.^(phi1*alphT).*kIdr.^(phi1*alphI).* ...
           prdr.^(-phi1*alphL).*Md.^phi).^(1/(1-phi1*alphL));
yfu     = (Afu.*kTfu.^(phi1*alphT).*kIfu.^(phi1*alphI).* ...
           prdu.^(-phi1*alphL).*Mf.^phi).^(1/(1-phi1*alphL));
yfr     = (Afr.*kTfr.^(phi1*alphT).*kIfr.^(phi1*alphI).* ...
           prdr.^(-phi1*alphL).*Mf.^phi).^(1/(1-phi1*alphL));
ydun    = [ydu(2:T);ydu(T)];
ydrn    = [ydr(2:T);ydr(T)];
yfun    = [yfu(2:T);yfu(T)];
yfrn    = [yfr(2:T);yfr(T)];

%
%   * labor inputs
%
ldu     = ydu./prdu;
ldr     = ydr./prdr;
lfu     = yfu./prdu;
lfr     = yfr./prdr;

%   * investments
%

xTdu    = (1+gamY)*Nun.*kTdun./Nu-(1-deltT)*kTdu;
xTdr    = (1+gamY)*Nrn.*kTdrn./Nr-(1-deltT)*kTdr;
xTfu    = (1+gamY)*Nun.*kTfun./Nu-(1-deltT)*kTfu;
xTfr    = (1+gamY)*Nrn.*kTfrn./Nr-(1-deltT)*kTfr;
xIdu    = (1+gamY)*Nun.*kIdun./Nu-(1-deltI)*kIdu;
xIdr    = (1+gamY)*Nrn.*kIdrn./Nr-(1-deltI)*kIdr;
xIfu    = (1+gamY)*Nun.*kIfun./Nu-(1-deltI)*kIfu;
xIfr    = (1+gamY)*Nrn.*kIfrn./Nr-(1-deltI)*kIfr;
xMd     = (1+gamY)*Mdn -(1-deltM)*Md;
xMf     = (1+gamY)*Mfn -(1-deltM)*Mf;

%   * other shares
%
sdrn    = 1-sdun;
sfrn    = 1-sfun;
sdr     = 1-sdu;
sfr     = 1-sfu;

%   * dividends
%
dd      = (1-taupu).*(Nu.*(ydu-wu.*ldu-deltT*kTdu-xIdu)-chidu*xMd)- ...
           ((1+gamY)*Nun.*kTdun-Nu.*kTdu)+ ...
          (1-taupr).*(Nr.*(ydr-wr.*ldr-deltT*kTdr-xIdr)-chidr*xMd)- ...
           ((1+gamY)*Nrn.*kTdrn-Nr.*kTdr);
df      = (1-taupu).*(Nu.*(yfu-wu.*lfu-deltT*kTfu-xIfu)-chifu*xMf)- ...
           ((1+gamY)*Nun.*kTfun-Nu.*kTfu)+ ...
          (1-taupr).*(Nr.*(yfr-wr.*lfr-deltT*kTfr-xIfr)-chifr*xMf)- ...
           ((1+gamY)*Nrn.*kTfrn-Nr.*kTfr);

%   * values (assuming interiority)
%
vd      = (1-taud).*(Nu.*(kTdun+(1-taupu).*kIdun)+ ...
                     Nr.*(kTdrn+(1-taupr).*kIdrn)+ ...
                     ((1-taupu)*chidu+(1-taupr)*chidr).*Mdn);
vf      = (1-taud).*(Nu.*(kTfun+(1-taupu).*kIfun)+ ...
                     Nr.*(kTfrn+(1-taupr).*kIfrn)+ ...
                     ((1-taupu)*chifu+(1-taupr)*chifr).*Mfn);

%   * transfers
%

gdpu    = (ydu+yfu-xIdu-xIfu-chidu*xMd./Nu-chifu*xMf./Nu)./(1-ynbuy);
gdpr    = (ydr+yfr-xIdr-xIfr-chidr*xMd./Nr-chifr*xMf./Nr)./(1-ynbry);
ynbu    = ynbuy.*gdpu;
xnbu    = xnbuy.*gdpu;
ynbr    = ynbry.*gdpr;
xnbr    = xnbry.*gdpr;
kapu    = tauc*cu+taul*wu.*lu+taud.*(sdu.*dd+sfu.*df)./Nu+ ...
          taupu.*(ydu+yfu-wu.*lu-deltT*(kTdu+kTfu)-xIdu-xIfu- ...
          (chidu*xMd+chifu*xMf)./Nu)+ynbu-xnbu-Tran./Nu;
kapr    = tauc*cr+taul*wr.*lr+taud.*(sdr.*dd+sfr.*df)./Nr+ ...
          taupr.*(ydr+yfr-wr.*lr-deltT*(kTdr+kTfr)-xIdr-xIfr- ...
          (chidr*xMd+chifr*xMf)./Nr)+ynbr-xnbr+Tran./Nr;


%   * returns to capital
%
rkTdun  = phi1*alphT*ydun./kTdun;
rkTdrn  = phi1*alphT*ydrn./kTdrn;
rkTfun  = phi1*alphT*yfun./kTfun;
rkTfrn  = phi1*alphT*yfrn./kTfrn;
rMdn    = ((1-taupun).*(phi*Nun.*ydun./Mdn+chidu*(1-deltM))+ ...
           (1-tauprn).*(phi*Nrn.*ydrn./Mdn+chidr*(1-deltM)))./ ...
          ((1-taupu)*chidu+(1-taupr)*chidr)-1;
rMfn    = ((1-taupun).*(phi*Nun.*yfun./Mfn+chifu*(1-deltM))+ ...
           (1-tauprn).*(phi*Nrn.*yfrn./Mfn+chifr*(1-deltM)))./ ...
          ((1-taupu)*chifu+(1-taupr)*chifr)-1;


%
% 11 residual equations 
%
res     = [(1+rb).*b-(1+gamY)*bn.*Nun./Nu+(1-taul)*wu.*lu+ ...
             (1-taud).*(sdu.*dd+sfu.*df)./Nu+ ...
             kapu-(1+tauc)*cu-(vd.*(sdun-sdu)+vf.*(sfun-sfu))./Nu;
          (-(1+rb).*b+(1+gamY)*bn.*Nun./Nu).*Nu./Nr+(1-taul)*wr.*lr+ ...
             (1-taud).*(sdr.*dd+sfr.*df)./Nr+ ...
             kapr-(1+tauc)*cr-(vd.*(sdrn-sdr)+vf.*(sfrn-sfr))./Nr;
           ldu+lfu-lu;
           ldr+lfr-lr;
           [ucu(1:T-1)./ucun(1:T-1)-ucr(1:T-1)./ucrn(1:T-1);sdun(T)-sdu(T)];  
           [rkTdun(1:T-1)-rTun(1:T-1);kTdun(T)-kTdu(T)];
           [rkTdrn(1:T-1)-rTrn(1:T-1);kTdrn(T)-kTdr(T)];
           [rkTfun(1:T-1)-rTun(1:T-1);kTfun(T)-kTfu(T)];
           [rkTfrn(1:T-1)-rTrn(1:T-1);kTfrn(T)-kTfr(T)];
           [rMdn(1:T-1)-rbn(1:T-1);Mdn(T)-Md(T)];
           [rMfn(1:T-1)-rbn(1:T-1);Mfn(T)-Mf(T)]];

%
% Variables to be printed
%
I       = 1:10;     % display averages for these periods in the table
lI      = length(I);
Cu      = Nu.*cu;
Cr      = Nr.*cr;
Yu      = Nu.*(ydu+yfu);
Yr      = Nr.*(ydr+yfr);
XTu     = Nu.*(xTdu+xTfu);
XTr     = Nr.*(xTdr+xTfr);
KTu     = Nu.*(kTdu+kTfu);
KTr     = Nr.*(kTdr+kTfr);
KTun    = Nun.*(kTdun+kTfun);
KTrn    = Nrn.*(kTdrn+kTfrn);
XIu     = Nu.*(xIdu+xIfu);
XIr     = Nr.*(xIdr+xIfr);
KIu     = Nu.*(kIdu+kIfu);
KIr     = Nr.*(kIdr+kIfr);
KIun    = Nun.*(kIdun+kIfun);
KIrn    = Nrn.*(kIdrn+kIfrn);
XMu     = chidu*xMd+chifu*xMf;
XMr     = chidr*xMd+chifr*xMf;
Mu      = chidu*Md+chifu*Mf;
Mr      = chidr*Md+chifr*Mf;
Mun     = chidu*Mdn+chifu*Mfn;
Mrn     = chidr*Mdn+chifr*Mfn;
GDPu    = Yu-XIu-chidu*xMd-chifu*xMf+Nu.*ynbu;
GDPr    = Yr-XIr-chidr*xMd-chifr*xMf+Nr.*ynbr;
NXu     = GDPu-XTu-Cu-Nu.*xnbu;
NXr     = GDPr-XTr-Cr-Nr.*xnbr;
Lu      = Nu.*lu;
Lr      = Nr.*lr;
Cmpu    = wu.*Lu;
Cmpr    = wr.*Lr;
Taxu    = taupu.*(Yu-wu.*Lu-XIu-XMu-deltT*KTu);
Taxr    = taupr.*(Yr-wr.*Lr-XIr-XMr-deltT*KTr);
Divu    = Yu-wu.*Lu-XIu-XMu-XTu-Taxu;
Divr    = Yr-wr.*Lr-XIr-XMr-XTr-Taxr;
REu     = (1+gamY)*KTun-KTu;
REr     = (1+gamY)*KTrn-KTr;
Prfu    = Divu+Taxu+REu;
Prfr    = Divr+Taxr+REr;
Cmpualt = Cmpu-.5*(XIu+chidu*xMd+chifu*xMf);
Prfualt = Prfu+.5*(XIu+chidu*xMd+chifu*xMf);
Depu    = deltT*KTu;
Depr    = deltT*KTr;
DIAdivu = Nr.*(ydr-wr.*ldr-xTdr-xIdr)-chidr*xMd- ...
          taupr.*(Nr.*(ydr-wr.*ldr-deltT*kTdr-xIdr)-chidr*xMd);
DIAreu  = ((1+gamY)*Nrn.*kTdrn-Nr.*kTdr);
EQRu    = sfu.*df;
FDIdivu = Nu.*(yfu-wu.*lfu-xTfu-xIfu)-chifu*xMf- ...
          taupu.*(Nu.*(yfu-wu.*lfu-deltT*kTfu-xIfu)-chifu*xMf);
FDIreu  = ((1+gamY)*Nun.*kTfun-Nu.*kTfu);
EQPu    = sdr.*dd;
DBRu    = max(Nu.*rb.*b,0);
DBPu    = max(-Nu.*rb.*b,0);
NFRu    = DIAdivu+DIAreu+EQRu+DBRu;
NFPu    = FDIdivu+FDIreu+EQPu+DBPu;
GNPu    = GDPu+NFRu-NFPu;
CAu     = NXu+NFRu-NFPu-Tran;
GNPr    = GDPr-NFRu+NFPu;
FAu     = ((1+gamY)*Nrn.*kTdrn-Nr.*kTdr)-((1+gamY)*Nun.*kTfun-Nu.*kTfu)+ ...
          vf.*(sfun-sfu)-vd.*(sdrn-sdr)+((1+gamY)*Nun.*bn-Nu.*b);
NAPfdiu = Nrn.*kTdrn;
NAPstku = sfun.*vf;
NAPdbtu = max(0,Nun.*bn);
NAPu    = NAPfdiu+NAPstku+NAPdbtu;
NAPfdir = Nun.*kTfun;
NAPstkr = sdrn.*vd;
NAPdbtr = max(0,-Nun.*bn);
NAPr    = NAPfdir+NAPstkr+NAPdbtr;
NAP     = NAPu-NAPr;

load ./rawdata/dtaud.dat
figure(1)
subplot(211)
plot(t,taud*100,'-b*',dtaud(:,1),dtaud(:,2),'-bx')
text(1965,30,'Tax on Dividends')
axis([1960,2015,10,50])
load ./rawdata/dtaup.dat

subplot(212)
plot(t,taupu*100,'-b*',dtaup(:,1),dtaup(:,2),'-bx')
text(1965,30,'Tax on Profits')
axis([1960,2015,10,50])
fig1    = [taud,taupu]*100;

figure(2)
subplot(221)
plot(t,Adr./Afr,'-g*')
axis([1960,2040,.65,.95])
text(1965,.9,'Openness of ROW to US')
subplot(222)
plot(t,Afu./Adu,'-r*')
axis([1960,2040,.65,.95])
text(1965,.85,'Openness of US to ROW')
subplot(223)
plot(t,o./rsize,'-b*')
axis([1960,2040,.4,.55])
text(1965,.51,'Size of US Relative to ROW')
subplot(224)
plot(t,sfun,'-k*')
axis([1960,2040,-.5,.5])
text(1965,-.2,'Foreign Share of US Companies')
fig2    = [(Afr./Adu).^(1-(alphT+alphI)*(1-phi)).*Nr./Nu, ...
            Adr./Afr,Afu./Adu,sfun];

load ./rawdata/dnpiintgnp.dat
figure(3)
plot(t,rb.*b.*Nu./GNPu*100,'-b*',dnpiintgnp(:,1),dnpiintgnp(:,2),'-bx')
text(1965,-.5,'Interest net income/GNP')
axis([1960,2006,-1.5,.5])
fig3 = rb.*b.*Nu./GNPu*100;

figure(4)
plot(t,[NAPfdiu-NAPfdir,NAPfdiu,NAPfdir]./(GNPu*[1,1,1])*100 * nyr)
legend('Net','US','ROW','Location','Northwest')
title('Reported FDI Asset Positions, at Current Cost, Relative to US GNP', ...
      'Fontsize',14)
axis([1960,2006,-5,30])
fig4 = [NAPfdiu-NAPfdir,NAPfdiu,NAPfdir]./(GNPu*[1,1,1])*100 * nyr;

load ./rawdata/dusdiaret.dat
load ./rawdata/dfdiusret.dat
figure(5)
plot(t,(DIAdivu+DIAreu)./(Nr.*kTdr)*100 /nyr,'-b*', ...
     t,(FDIdivu+FDIreu)./(Nu.*kTfu)*100 /nyr,'-g*', ...
     dusdiaret(:,1),dusdiaret(:,2),'-bx', ...
     dfdiusret(:,1),dfdiusret(:,2),'-gx')
legend('USDIA','FDIUS','Location','Northwest')
title('Returns on FDI','Fontsize',14)
axis([1982,2006,-2,14])
fig5 = [(DIAdivu+DIAreu)./(Nr.*kTdr) /nyr, ...
        (FDIdivu+FDIreu)./(Nu.*kTfu) /nyr,rb /nyr]*100;

load ./rawdata/dusdiagnp.dat
load ./rawdata/dfdiusgnp.dat
load ./rawdata/dnxgnp.dat
load ./rawdata/dnpignp.dat
figure(6)
subplot(221)
plot(t,(DIAdivu+DIAreu)./GNPu*100,'-g*',dusdiagnp(:,1),dusdiagnp(:,2),'-gx');
axis([1960,2006,-.25,2.5])
text(1965,2.1,'US DI Abroad/US GNP')
subplot(222)
plot(t,(FDIdivu+FDIreu)./GNPu*100,'-r*',dfdiusgnp(:,1),dfdiusgnp(:,2),'-rx');
axis([1960,2006,-.25,2.5])
text(1965,1,'FDI in US/US GNP')
subplot(223)
plot(t,NXu./GNPu*100,'-b*',dnxgnp(:,1),dnxgnp(:,2),'-bx');
axis([1960,2006,-8,4])
text(1965,2.25,'Net Exports/US GNP')
subplot(224)
plot(t,(EQRu+DBRu-EQPu-DBPu)./GNPu*100,'-k*',dnpignp(:,1),dnpignp(:,2),'-kx');
axis([1960,2006,-1,.5])
text(1965,-.75,'Portfolio Income (Net)/US GNP')
fig6 = [(DIAdivu+DIAreu)./GNPu*100,(FDIdivu+FDIreu)./GNPu*100, ...
         NXu./GNPu*100,(EQRu+DBRu-EQPu-DBPu)./GNPu*100];

load ./rawdata/dcshare.dat
figure(7)
plot(t,Cu./GDPu*100,'-b*',dcshare(:,1),dcshare(:,2),'-bx')
axis([1960,2006,70,80])
text(1962,79,'US Consumption Relative to GDP','Fontsize',14)
fig7  = Cu./GDPu*100;

load ./rawdata/dusrowgdp.dat
figure(8)
plot(t,GDPu./(GDPu+GDPr)*100,'-b*', ...
     dusrowgdp(:,1),dusrowgdp(:,2)./(dusrowgdp(:,2)+dusrowgdp(:,3))*100,'-bx')
axis([1960,2006,25,35])
text(1965,26,'US GDP Relative to World GDP','Fontsize',14)
fig8  = GDPu./(GDPu+GDPr)*100;

load match.dat
figure(9)
subplot(221)
plot(dusdiagnp(:,1),dusdiagnp(:,2),'-gx',match(:,1),match(:,2),'-go');
axis([1960,2006,-.25,2.5])
text(1965,2.1,'US DI Abroad/US GNP')
subplot(222)
plot(dfdiusgnp(:,1),dfdiusgnp(:,2),'-rx',match(:,1),match(:,3),'-ro');
axis([1960,2006,-.25,2.5])
text(1965,1,'FDI in US/US GNP')
subplot(223)
plot(dnxgnp(:,1),dnxgnp(:,2),'-bx',match(:,1),match(:,4),'-bo');
axis([1960,2006,-8,4])
text(1965,2.25,'Net Exports/US GNP')
subplot(224)
plot(dnpignp(:,1),dnpignp(:,2),'-kx',match(:,1),match(:,5),'-ko');
axis([1960,2006,-1,.5])
text(1965,-.75,'Portfolio Income (Net)/US GNP')

figure(10)
subplot(221)
plot(t,(DIAdivu+DIAreu)./GNPu*100,'-g*',match(:,1),match(:,2),'-go');
axis([1960,2006,-.25,2.5])
text(1965,2.1,'US DI Abroad/US GNP')
subplot(222)
plot(t,(FDIdivu+FDIreu)./GNPu*100,'-r*',match(:,1),match(:,3),'-ro');
axis([1960,2006,-.25,2.5])
text(1965,1,'FDI in US/US GNP')
subplot(223)
plot(t,NXu./GNPu*100,'-b*',match(:,1),match(:,4),'-bo');
axis([1960,2006,-8,4])
text(1965,2.25,'Net Exports/US GNP')
subplot(224)
plot(t,(EQRu+DBRu-EQPu-DBPu)./GNPu*100,'-k*',match(:,1),match(:,5),'-ko');
axis([1960,2006,-1,.5])
text(1965,-.75,'Portfolio Income (Net)/US GNP')



disp(' FIXED PARAMETER INPUTS ')
disp(' ---------------------- ')
disp(sprintf('    Time period: %3.0f years',nyr))
disp('    Preferences ')
disp(sprintf('      sum (%3.2f)^t U(c,h) ',beta))
disp(sprintf('      U = log(c) + %4.2f log(1-l) ',psi))
disp('    Technology ')
disp(sprintf('      F = A Z^(%4.2f) M^(%4.2f)',1-phi,phi))
disp(sprintf('      Z = KT^(%4.2f) KI^(%4.2f) L^(%4.2f)',alphT,alphI,alphL))
gamA = (1+gamY)^(phi1*(1-alphT-alphI))/((1+gamN)^(1-phi1*(alphT+alphI)))-1;
disp('    Growth rates (%, annual) ')
disp(sprintf('      Technology                       %5.1f', ...
    ((1+gamA)^(1/nyr)-1)*100 ))
disp(sprintf('      Population                       %5.1f', ...
    ((1+gamN)^(1/nyr)-1)*100 ))
disp('    Tax rates (%) ')
disp(sprintf('      Consumption                      %5.1f',tauc*100))
disp(sprintf('      Labor                            %5.1f',taul*100))
disp('    Depreciation rates (%, annual)')
disp(sprintf('      Tangible capital                 %5.1f', ...
    (1-(1-deltT)^(1/nyr))*100))
disp(sprintf('      Plant-specific intangible cap.   %5.1f', ...
    (1-(1-deltI)^(1/nyr))*100))
disp(sprintf('      Technology capital               %5.1f', ...
    (1-(1-deltM)^(1/nyr))*100))
disp('    Expensing choice')
disp(sprintf('      in US, US companies              %5.2f',chidu))
disp(sprintf('      in US, ROW companies             %5.2f',chifu))
disp(sprintf('      in ROW, US companies             %5.2f',chidr))
disp(sprintf('      in ROW, ROW companies            %5.2f',chifr))
disp('    Initial stocks (annualized)')
Nu0=Nu(1);
Nr0=Nr(1);
disp(sprintf('      Tangible K, US firms, in US      %5.3f',Nu0*kTdu0 *nyr))
disp(sprintf('      Tangible K, US firms, in ROW     %5.3f',Nr0*kTdr0 *nyr))
disp(sprintf('      Tangible K, ROW firms, in US     %5.3f',Nu0*kTfu0 *nyr))
disp(sprintf('      Tangible K, ROW firms, in ROW    %5.3f',Nr0*kTfr0 *nyr))
disp(sprintf('      P-S Intang. K, US firms, in US   %5.3f',Nu0*kIdu0 *nyr))
disp(sprintf('      P-S Intang. K, US firms, in ROW  %5.3f',Nr0*kIdr0 *nyr))
disp(sprintf('      P-S Intang. K, ROW firms, in US  %5.3f',Nu0*kIfu0 *nyr))
disp(sprintf('      P-S Intang. K, ROW firms, in ROW %5.3f',Nr0*kIfr0 *nyr))
disp(sprintf('      Technology K, US firms           %5.3f',Md0 *nyr))
disp(sprintf('      Technology K, ROW firms          %5.3f',Mf0 *nyr))
disp(sprintf('      Debt                             %5.3f',b0 *nyr))
disp(sprintf('      US equity, US firms              %5.3f',sdu0))
disp(sprintf('      US equity, ROW firms             %5.3f',sfu0))
disp(sprintf('      ROW equity, US firms             %5.3f',1-sdu0))
disp(sprintf('      ROW equity, ROW firms            %5.3f',1-sfu0))

disp(' ')
disp([' TIME-VARYING PARAMETER INPUTS, PERIODS ',sprintf('%g-%g',I(1),I(lI))])
disp( ' ------------------------------------------- ')
disp('    Population size')
disp(['      US                = ',sprintf('%7.2f',Nu(I))])
disp(['      ROW               = ',sprintf('%7.2f',Nr(I))])
disp( '    Productivities (A) x scale factor')
disp(['      in US, US firms   = ',sprintf('%7.3f',Adu(I))])
disp(['      in US, ROW firms  = ',sprintf('%7.3f',Afu(I))])
disp(['      in ROW, US firms  = ',sprintf('%7.3f',Adr(I))])
disp(['      in ROW, ROW firms = ',sprintf('%7.3f',Afr(I))])
disp( '    Tax rates (%)')
disp(['      Dividend tax      = ',sprintf('%7.1f',taud(I)*100)])
disp(['      Profits in US     = ',sprintf('%7.1f',taupu(I)*100)])
disp(['      Profits in ROW    = ',sprintf('%7.1f',taupr(I)*100)])
disp(['    Pre-specified debt  = ',sprintf('%7.2f',Nu(I).*b(I))])
disp( '    Pre-specified company ownership (%)')
disp(['      US, ROW firms     = ',sprintf('%7.1f',sfu(I)*100)])
disp( '    Implied company ownership (%)')
disp(['      US, US firms      = ',sprintf('%7.1f',sdu(I)*100)])
disp(['      ROW, US firms     = ',sprintf('%7.1f',sdr(I)*100)])
disp(['      ROW, ROW firms    = ',sprintf('%7.1f',sfr(I)*100)])


%
% Load line account items and interpolate if necessary
%
ACCT0   = [Cu./GNPu,(XTu+Nu.*xnbu)./GNPu,XTu./GNPu,Nu.*xnbu./GNPu, ...
           NXu./GNPu,GDPu./GNPu,Cmpu./GNPu,Depu./GNPu,Prfu./GNPu, ...
           Taxu./GNPu,REu./GNPu,Divu./GNPu,Nu.*ynbu./GNPu, ...
           NFRu./GNPu,(DIAdivu+DIAreu)./GNPu,DIAdivu./GNPu, ...
           DIAreu./GNPu,(EQRu+DBRu)./GNPu,EQRu./GNPu,DBRu./GNPu, ...
           NFPu./GNPu,(FDIdivu+FDIreu)./GNPu,FDIdivu./GNPu, ...
           FDIreu./GNPu,(EQPu+DBPu)./GNPu,EQPu./GNPu,DBPu./GNPu, ...
           (NFRu-NFPu)./GNPu,-Tran./GNPu,CAu./GNPu,FAu./GNPu, ...
           Cmpualt./GNPu,Prfualt./GNPu, ...
           Cr./GNPr,(XTr+Nr.*xnbr)./GNPr,XTr./GNPr,Nr.*xnbr./GNPr, ...
           NXr./GNPr,GDPr./GNPr,Cmpr./GNPr,Depr./GNPr,Prfr./GNPr, ...
           Taxr./GNPr,REr./GNPr,Divr./GNPr,Nr.*ynbr./GNPr, ...
           NAPfdiu./GNPu*nyr,NAPstku./GNPu*nyr,NAPdbtu./GNPu*nyr, ...
           NAPfdir./GNPu*nyr,NAPstkr./GNPu*nyr,NAPdbtr./GNPu*nyr, ...
           NAP./GNPu*nyr,Md./GNPu*nyr,xMd./GNPu,KIu./GNPu*nyr, ...
           XIu./GNPu,kIdu./kTdu,Mf./GNPu*nyr,xMf./GNPu,KIr./GNPu*nyr, ...
           XIr./GNPu,kIfr./kTfr];
[n,m]   = size(ACCT0);
for i=1:m;
  ACCT1(:,i) = interp(ACCT0(:,i),nyr);
end;
t0      = 1960;
t1      = 2006;
i0      = find([t(1):t(1)-1+nyr*T]==t0);
i1      = find([t(1):t(1)-1+nyr*T]==t1);
M       = mean(ACCT1(i0:i1,:));

VAL0    = [vd./GNPu*nyr,vf./GNPu*nyr];
[n,m]   = size(VAL0);
for i=1:m;
  VAL1(:,i) = interp(VAL0(:,i),nyr);
end;
s0      = 1960;
s1      = 1970;
i0      = find([t(1):t(1)-1+nyr*T]==s0);
i1      = find([t(1):t(1)-1+nyr*T]==s1);
Mv      = mean(VAL1(i0:i1,:));

RET0    = [(DIAdivu+DIAreu)./(Nr.*kTdr)/nyr, ...
           (FDIdivu+FDIreu)./(Nu.*kTfu) /nyr]*100;
[n,m]   = size(RET0);
for i=1:m;
  RET1(:,i) = interp(RET0(:,i),nyr);
end;
s0      = 1982;
s1      = 2006;
i0      = find([t(1):t(1)-1+nyr*T]==s0);
i1      = find([t(1):t(1)-1+nyr*T]==s1);
Mr      = mean(RET1(i0:i1,:));

disp(' ')
disp(' ')
disp(' REPORTED US ACCOUNTS (Relative to US GNP)')
disp(' -----------------------------------------')
disp(['  Sample                 ',sprintf('%4g-%4g',t0,t1)])
disp( '  Domestic Product       ')
disp(['    Consumption          ',sprintf('%7.3f',M(1))])
disp(['    Investment           ',sprintf('%7.3f',M(2))])
disp(['      Business           ',sprintf('%7.3f',M(3))])
disp(['      Nonbusiness        ',sprintf('%7.3f',M(4))])
disp(['    Net Exports          ',sprintf('%7.3f',M(5))])
disp( '  =====================  ')
disp(['  Total Domestic Product ',sprintf('%7.3f',M(6))])
disp(' ')
disp( '  Domestic Income*       ')
disp(['    Compensation         ',sprintf('%7.3f',M(7))])
disp(['    Depreciation         ',sprintf('%7.3f',M(8))])
disp(['    Domestic Profits     ',sprintf('%7.3f',M(9))])
disp(['      Tax liability      ',sprintf('%7.3f',M(10))])
disp(['      Undistributed      ',sprintf('%7.3f',M(11))])
disp(['      Dividends          ',sprintf('%7.3f',M(12))])
disp(['    Nonbusiness income   ',sprintf('%7.3f',M(13))])
disp( '  =====================  ')
disp(['  Total Domestic Income  ',sprintf('%7.3f',M(6))])
disp(' ')
disp(['  Net factor receipts    ',sprintf('%7.3f',M(14))])
disp(['    DI Earnings          ',sprintf('%7.3f',M(15))])
disp(['      Distributed        ',sprintf('%7.3f',M(16))])
disp(['      Reinvested         ',sprintf('%7.3f',M(17))])
disp(['    Portfolio Income     ',sprintf('%7.3f',M(18))])
disp(['      Equities           ',sprintf('%7.3f',M(19))])
disp(['      Debt               ',sprintf('%7.3f',M(20))])
disp(' ')
disp(['  Net factor payments    ',sprintf('%7.3f',M(21))])
disp(['    DI Earnings          ',sprintf('%7.3f',M(22))])
disp(['      Distributed        ',sprintf('%7.3f',M(23))])
disp(['      Reinvested         ',sprintf('%7.3f',M(24))])
disp(['    Portfolio Income     ',sprintf('%7.3f',M(25))])
disp(['      Equities           ',sprintf('%7.3f',M(26))])
disp(['      Debt               ',sprintf('%7.3f',M(27))])
disp( '  ---------------------  ')
disp(['  Net factor income      ',sprintf('%7.3f',M(28))])
disp( '  =====================  ')
disp(['  Total National Income  ',sprintf('%7.3f',1)])
disp(' ')
disp(['  Transfers              ',sprintf('%7.3f',M(29))])
disp(['  Current account        ',sprintf('%7.3f',M(30))])
disp(['  Financial account      ',sprintf('%7.3f',M(31))])
disp(' ')
disp(' -------------------------------------------')
disp(' NOTE: Intangible investment is subtracted  ')
disp('       from profits. If it is financed by   ')
disp('       both labor and capital, then ')
disp(['           Compensation         ',sprintf('%7.3f',M(32))])
disp(['           Domestic Profits     ',sprintf('%7.3f',M(33))])
disp(' ')
disp(' ')
disp(' ')
disp(' REPORTED ROW ACCOUNTS (Relative to ROW GNP)')
disp(' -------------------------------------------')
disp(['  Sample                 ',sprintf('%4g-%4g',t0,t1)])
disp( '  Domestic Product       ')
disp(['    Consumption          ',sprintf('%7.3f',M(34))])
disp(['    Investment           ',sprintf('%7.3f',M(35))])
disp(['      Business           ',sprintf('%7.3f',M(36))])
disp(['      Nonbusiness        ',sprintf('%7.3f',M(37))])
disp(['    Net Exports          ',sprintf('%7.3f',M(38))])
disp( '  =====================  ')
disp(['  Total Domestic Product ',sprintf('%7.3f',M(39))])
disp(' ')
disp( '  Domestic Income        ')
disp(['    Compensation         ',sprintf('%7.3f',M(40))])
disp(['    Depreciation         ',sprintf('%7.3f',M(41))])
disp(['    Domestic Profits     ',sprintf('%7.3f',M(42))])
disp(['      Tax liability      ',sprintf('%7.3f',M(43))])
disp(['      Undistributed      ',sprintf('%7.3f',M(44))])
disp(['      Dividends          ',sprintf('%7.3f',M(45))])
disp(['    Nonbusiness income   ',sprintf('%7.3f',M(46))])
disp( '  =====================  ')
disp(['  Total Domestic Income  ',sprintf('%7.3f',M(39))])
disp(' -----------------------------------------------')
disp(' ')
disp(' ')
disp(' REPORTED INTL. ASSET POSITIONS (Rel. to US GNP)')
disp(' -----------------------------------------------')
disp(' ')
disp( '  US Assets Abroad')
disp(['    Current cost of FDI  ',sprintf('%7.3f',M(47))])
disp(['    Foreign equities     ',sprintf('%7.3f',M(48))])
disp(['    Foreign net debt     ',sprintf('%7.3f',M(49))])
disp(' ')
disp( '  ROW Assets in US')
disp(['    Current cost of FDI  ',sprintf('%7.3f',M(50))])
disp(['    Foreign equities     ',sprintf('%7.3f',M(51))])
disp(['    Foreign net debt     ',sprintf('%7.3f',M(52))])
disp(' ')
disp(['  Net Position           ',sprintf('%7.3f',M(53))])

disp(' ')
disp(' ')
disp(' ADDENDA: OTHER STATISTICS (levels relative to US GNP)')
disp(' -----------------------------------------------------')
disp( ' ')
disp( '  Statistics for US companies ')
disp(['    Technology capital   ',sprintf('%7.3f',M(54))])
disp(['    T-capital investment ',sprintf('%7.3f',M(55))])
disp(['    P-S intang. capital  ',sprintf('%7.3f',M(56))])
disp(['    P-S intang. invest.  ',sprintf('%7.3f',M(57))])
disp(['    P-S intang k/tang k  ',sprintf('%7.3f',M(58))])
disp(['    Equity Value, 1960s  ',sprintf('%7.3f',Mv(1))])
disp(['    1982-2006 FDI return ',sprintf('%7.3f',Mr(1))])
disp( ' ')
disp( '  Statistics for ROW companies ')
disp(['    Technology capital   ',sprintf('%7.3f',M(59))])
disp(['    T-capital investment ',sprintf('%7.3f',M(60))])
disp(['    P-S intang. capital  ',sprintf('%7.3f',M(61))])
disp(['    P-S intang. invest.  ',sprintf('%7.3f',M(62))])
disp(['    P-S intang k/tang k  ',sprintf('%7.3f',M(63))])
disp(['    Equity Value, 1960s  ',sprintf('%7.3f',Mv(2))])
disp(['    1982-2006 FDI return ',sprintf('%7.3f',Mr(2))])
