% TABLE 5 & 6    
%
% This file accompanies `Can Sticky Price Models Generate Volatile 
% and Persistent Real Exchange Rates?'
%

format compact

%
% Read in data.
% (See README file for details on data sources.)
%

load natacct/nominal/ngdp.dat
load natacct/nominal/ncons.dat
load natacct/nominal/ngfcf.dat
load natacct/nominal/ntexp.dat
load natacct/nominal/ntimp.dat
load natacct/real/rgdp.dat
load natacct/real/rcons.dat
load natacct/real/rgfcf.dat
load natacct/real/rtexp.dat
load natacct/real/rtimp.dat
load nexchr/ner.dat
load prices/cpi.dat
load tradeus/nexpus.dat
load tradeus/nimpus.dat
load employm/emp.dat



%
% Sample and ordering of countries:
%

sample     = ptime(1960.1,161,4);
countries  = ['YEAR.QTR    ';
              'Austria     ';
              'Belgium     ';
              'Canada      ';
              'Denmark     ';
              'Finland     ';
              'France      ';
              'Germany     ';
              'Italy       ';
              'Japan       ';
              'Mexico      ';
              'Netherlands ';
              'Norway      ';
              'Spain       ';
              'Switzerland ';
              'UK          ';
              'US          ';
              'West Germany'];
nc    = 17;

%
% Convert base year for GDP, Consumption and Investment to nbyr year.
%
nbyr  = 1990;
obyr  = [1995,1995,1992,1995,1995,1980,1995,1995,1990,1993, ...
         1995,1995,1995,1990,1995,1996,1991];
t     = find(sample>nbyr & sample<nbyr+1);
for i=1:nc;
  if (obyr(i)~=nbyr);
    rgdp(:,i+1)  = rgdp(:,i+1) *mean(ngdp(t,i+1)) /mean(rgdp(t,i+1));
    rcons(:,i+1) = rcons(:,i+1)*mean(ncons(t,i+1))/mean(rcons(t,i+1));
    rgfcf(:,i+1) = rgfcf(:,i+1)*mean(ngfcf(t,i+1))/mean(rgfcf(t,i+1));
  end;
end;

%
% Fill in missing observations of employment.
%

% France:
tem        = linspace(emp(48,7),emp(52,7),5)'; emp(49:51,7) = tem(2:4);
tem        = linspace(emp(52,7),emp(56,7),5)'; emp(53:55,7) = tem(2:4);
tem        = linspace(emp(56,7),emp(60,7),5)'; emp(57:59,7) = tem(2:4);
tem        = linspace(emp(60,7),emp(64,7),5)'; emp(61:63,7) = tem(2:4);
tem        = linspace(emp(64,7),emp(68,7),5)'; emp(65:67,7) = tem(2:4);
tem        = linspace(emp(68,7),emp(72,7),5)'; emp(69:71,7) = tem(2:4);

%
% PPP's from www.oecd.org/std/pps.htm
%

ppp90      = [NaN;14.0;39.5;1.30;9.39;6.38;6.61;2.09;1421;195;
              1.53;2.17;9.73;110;2.20;.602;1.00;2.09];
ppp95      = [NaN;13.7;36.7;1.18;8.42;5.86;6.46;2.02;1550;170;
              2.96;2.03;9.14;122;2.01;.654;1.00;2.02];
ppp        = ppp90;

t          = 53:140;
T          = length(t);
i          = [7,18,9,16];               % France,Germany,Italy, UK
j          = [i,17];    % add US
I          = length(i);
ot         = ones(T,1);
oi         = ones(I,1);
oi1        = ones(I+1,1);
oti        = ones(T,I);

%
% Trade weights:
%

twgt       = (nexpus(t,i)+nimpus(t,i))./(sum(nexpus(t,i)'+nimpus(t,i)')' * oi');
cwgt       = mean(twgt)'/sum(mean(twgt)');

%
% Variables we will work with:
%

exch       = oti./ner(t,i);
E          = exch./(ot*exch(1,:));           % $/Franc
Eeur       = E*cwgt;

Y          = rgdp(t,i)./(ot*ppp(i)');
Yeur       = sum(Y')';                       % Real GDP in nbyr base year US$
Yus        = rgdp(t,17);

C          = rcons(t,i)./(ot*ppp(i)');
Ceur       = sum(C')';                       % Real Consumption in nbyr US$
Cus        = rcons(t,17);

In         = rgfcf(t,i)./(ot*ppp(i)');
Ieur       = sum(In')';                      % Real Investment in nbyr US$
Ius        = rgfcf(t,17);

N          = emp(t,i);
Neur       = sum(N')';                       % Employment
Nus        = emp(t,17);

EX         = nexpus(t,i);
EXus       = sum(EX')';                      % Nominal US Exports in US$
tau        = find(sample(t)>nbyr & sample(t)<nbyr+1);
PEXus      = ntexp(t,17)./rtexp(t,17);
PEXus      = PEXus/mean(PEXus(tau));
REXus      = EXus./PEXus;                    % Real US Exports in nbyr US$

IM         = nimpus(t,i);
IMus       = sum(IM')';                      % Nominal US Imports in US$
PIMus      = ntimp(t,17)./rtimp(t,17);
PIMus      = PIMus/mean(PIMus(tau));
RIMus      = IMus./PIMus;                    % Real US Imports in nbyr US$

RNXus      = REXus-RIMus;

P          = cpi(t,j);
P          = cpi(t,j)./(ot * P(1,:));
Peur       = P(:,1:I)*cwgt;
Pus        = P(:,I+1);
Prat       = Peur./Pus;

Qeur       = Eeur .*Peur ./ Pus;

%
% Detrending:
%

t          = sample(t);
dPrat      = log(Prat)   - hptrend(log(Prat),1600);
dQ         = log(Qeur)   - hptrend(log(Qeur),1600);
dE         = log(Eeur)   - hptrend(log(Eeur),1600);
dYus       = log(Yus)    - hptrend(log(Yus),1600);
dCus       = log(Cus)    - hptrend(log(Cus),1600);
dIus       = log(Ius)    - hptrend(log(Ius),1600);
dNus       = log(Nus)    - hptrend(log(Nus),1600);
dYeur      = log(Yeur)   - hptrend(log(Yeur),1600);
dCeur      = log(Ceur)   - hptrend(log(Ceur),1600);
dIeur      = log(Ieur)   - hptrend(log(Ieur),1600);
dNeur      = log(Neur)   - hptrend(log(Neur),1600);
dRNXYus    = RNXus./Yus  - hptrend(RNXus./Yus,1600);
dCC        = dCus-dCeur;
dNN        = dNus-dNeur;

%
% Correlations and Autocorrelations 
%

cQE        = corrcoef([dQ,dE]);                       cQE   = cQE(1,2);
cYRXY      = corrcoef([dYus,dRNXYus]);                cYRXY = cYRXY(1,2);
cQRXY      = corrcoef([dQ,dRNXYus]);                  cQRXY = cQRXY(1,2);
cQCC       = corrcoef([dQ,dCC]);                      cQCC  = cQCC(1,2);
cYQ        = corrcoef([dYus,dQ]);                     cYQ   = cYQ(1,2);
cYs        = corrcoef([dYus,dYeur]);                  cYs   = cYs(1,2);
cCs        = corrcoef([dCus,dCeur]);                  cCs   = cCs(1,2);
cIs        = corrcoef([dIus,dIeur]);                  cIs   = cIs(1,2);
cNs        = corrcoef([dNus,dNeur]);                  cNs   = cNs(1,2);

aP         = corrcoef([dPrat(1:T-1),dPrat(2:T)]);     aP    = aP(1,2);
aQ         = corrcoef([dQ(1:T-1),dQ(2:T)]);           aQ    = aQ(1,2);
aE         = corrcoef([dE(1:T-1),dE(2:T)]);           aE    = aE(1,2);
aY         = corrcoef([dYus(1:T-1),dYus(2:T)]);       aY    = aY(1,2);
aC         = corrcoef([dCus(1:T-1),dCus(2:T)]);       aC    = aC(1,2);
aI         = corrcoef([dIus(1:T-1),dIus(2:T)]);       aI    = aI(1,2);
aN         = corrcoef([dNus(1:T-1),dNus(2:T)]);       aN    = aN(1,2);
aRXY       = corrcoef([dRNXYus(1:T-1),dRNXYus(2:T)]); aRXY  = aRXY(1,2);

%
% Write out results:
%

disp(' ')
disp('TABLE 5. PRICE STATS')
disp(sprintf('  Std( P*/P ) / Std(RGDP)  =  %7.2f ',std(dPrat)/std(dYus)))
disp(sprintf('  Std( E )    / Std(RGDP)  =  %7.2f ',std(dE)/std(dYus)))
disp(sprintf('  Std( Q )    / Std(RGDP)  =  %7.2f ',std(dQ)/std(dYus)))
disp(sprintf('  Autocorr( P*/P )         =  %7.2f ',aP))
disp(sprintf('  Autocorr( E )            =  %7.2f ',aE))
disp(sprintf('  Autocorr( Q )            =  %7.2f ',aQ))
disp(sprintf('  Corr( Q,E )              =  %7.2f ',cQE))
disp(' ')
disp('TABLE 6. WITH BUSINESS CYCLE STATS')
disp(sprintf('  Std( RGDP )*100          =  %7.2f ',std(dYus)*100))
disp(sprintf('  Std( C )/Std(RGDP)       =  %7.2f ',std(dCus)/std(dYus)))
disp(sprintf('  Std( I )/Std(RGDP)       =  %7.2f ',std(dIus)/std(dYus)))
disp(sprintf('  Std( N )/Std(RGDP)       =  %7.2f ',std(dNus)/std(dYus)))
disp(sprintf('  Std( RNX/RGDP )*100      =  %7.2f ',std(dRNXYus)*100))
disp(sprintf('  Autocorr( RGDP )         =  %7.2f ',aY))
disp(sprintf('  Autocorr( C )            =  %7.2f ',aC))
disp(sprintf('  Autocorr( I )            =  %7.2f ',aI))
disp(sprintf('  Autocorr( N )            =  %7.2f ',aN))
disp(sprintf('  Autocorr( RNX/RGDP )     =  %7.2f ',aRXY))
disp(sprintf('  Corr( RGDP''s )           =  %7.2f ',cYs))
disp(sprintf('  Corr( C''s )              =  %7.2f ',cCs))
disp(sprintf('  Corr( I''s )              =  %7.2f ',cIs))
disp(sprintf('  Corr( N''s )              =  %7.2f ',cNs))
disp(sprintf('  Corr( RNX/RGDP,RGDP )    =  %7.2f ',cYRXY))
disp(sprintf('  Corr( RGDP,Q )           =  %7.2f ',cYQ))
disp(sprintf('  Corr( RNX/RGDP,Q )       =  %7.2f ',cQRXY))
disp(sprintf('  Corr( C-C*,Q )           =  %7.2f ',cQCC))
disp(' ')
