% TABLE 3
%
% 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 tradeus/nexpus.dat
load tradeus/nimpus.dat
load nexchr/ner.dat
load prices/wpi.dat

%
% Data transformations:
%
%  1. Log-linearly interpolate nexpus & nimpus for 
%     Belgium, 1996:4-present (only 96:4 and 98:1 
%     available in this period).

beta              = (log(nexpus(153,3))-log(nexpus(148,3)))/5;
alpha             = log(nexpus(148,3))-beta*148;
nexpus(148:161,3) = exp(alpha+beta*[148:161]');

beta              = (log(nimpus(153,3))-log(nimpus(148,3)))/5;
alpha             = log(nimpus(148,3))-beta*148;
nimpus(148:161,3) = exp(alpha+beta*[148:161]');


%
% 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     ';
              ' W.Germany '];

%
% Choose quarters and countries
%

t          = 53:161;     % 1973:1-2000:1
T          = length(t);
i          = [2,5,6,18,9,12,14,15,16]; 
j          = [i,17];     
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,:));           % unit: $/Franc
Eeur       = E*cwgt;                         % trade-weighted exchange rate

P          = wpi(t,j);                          
P          = wpi(t,j)./(ot * P(1,:));        % normalize price by initial P
Pus        = P(:,I+1);                       % U.S. price
Peur       = P(:,1:I)*cwgt;                  % trade-weighted price
P          = P(:,1:I);                       % individual prices

PR         = P./(Pus * oi');                 % price ratios with U.S. price
PReur      = Peur./Pus;                      % European price ratio 

Q          = E .* P ./(Pus * oi');           % real exchange rates with U.S.
Qeur       = Eeur .*Peur ./ Pus;             % European real exchange rate

%
% Detrending:
%

t          = sample(t);

dPR        = log(PR)         - hptrend(log(PR),1600);
dQ         = log(Q)          - hptrend(log(Q),1600);
dE         = log(E)          - hptrend(log(E),1600);
dPReur     = log(PReur)      - hptrend(log(PReur),1600);
dQeur      = log(Qeur)       - hptrend(log(Qeur),1600);
dEeur      = log(Eeur)       - hptrend(log(Eeur),1600);

%
% Correlations and Autocorrelations 
%

for k=1:I;
  sPR      = std(dPR(:,k))*100;
  sE       = std(dE(:,k))*100;
  sQ       = std(dQ(:,k))*100;
  aPR      = corrcoef([dPR(1:T-1,k),dPR(2:T,k)]);
  aE       = corrcoef([dE(1:T-1,k), dE(2:T,k)]);
  aQ       = corrcoef([dQ(1:T-1,k), dQ(2:T,k)]);
  cQE      = corrcoef([dQ(:,k),dE(:,k)]);
  tab3(:,k)= [sPR;sE;sQ;aPR(1,2);aE(1,2);aQ(1,2);cQE(1,2)];
end;
sPR        = std(dPReur)*100;
sE         = std(dEeur)*100;
sQ         = std(dQeur)*100;
aPR        = corrcoef([dPReur(1:T-1),dPReur(2:T)]);
aE         = corrcoef([dEeur(1:T-1), dEeur(2:T)]);
aQ         = corrcoef([dQeur(1:T-1), dQeur(2:T)]);
cQE        = corrcoef([dQeur, dEeur]);
tab3(:,I+1)= [sPR;sE;sQ;aPR(1,2);aE(1,2);aQ(1,2);cQE(1,2)];

%
% Convert Years:Quarters to string variables and print table
%

yr0        = int2str(floor(t(1)));
yr1        = int2str(floor(t(length(t))));
q0         = int2str((t(1)-floor(t(1)))*1000);
q1         = int2str((t(length(t))-floor(t(length(t))))*1000);
switch q0
  case '125',  qr0='1';
  case '375',  qr0='2';
  case '625',  qr0='3';
  case '875',  qr0='4';
end
switch q1
  case '125',  qr1='1';
  case '375',  qr1='2';
  case '625',  qr1='3';
  case '875',  qr1='4';
end

disp(['TABLE 3. Properties of Exchange Rates and WPI''s, ', ...
      yr0,':',qr0,'-',yr1,':',qr1])
disppr(tab3',[countries(i,:);'  Europe   '])
disp(' ')
disp(' ')
