%
%SETUP  uses country averages to set up inputs for compsteady.m
%
% Data will be re-ordered as such: 
% 1. US+Can
% 2. EU 
% 3. UK 
% 4. Norway + switzerland  
% 5. China+Japan+Korea 

% ouputs will be: 
% 1. bilateral fdii as a fraction of GDP: bfdi
% 2. bilateral imports as a fraction of GDP: bim
% 3. data: includes: 
%       population relative to the UK      : pop(ii)/pop(3)*100
%       rGDP relative to UK's rGDP         : rgdpp(ii)/rgdpp(3)*100
%       corporate tax rates                : taup/100, 
%       total fdii flow relative to gdp    : btfdi
%       total import flows relative to gdp :   btim


load fdii_bilat.txt
load fdii_total.txt
load fdio_bilat.txt
load fdio_total.txt
load pop.txt
load ngdpd.txt
load rgdpd.txt
load rgdpp.txt
load corptax.txt
load exports_bilat.txt
load imports_bilat.txt
load exports_total.txt
load imports_total.txt
load imports_gs_bilat.txt
load imports_gs_total.txt

imp_type = input('Do you want to use imports of goods only (Comtrade) or imports of goods and services (WIOT)? 1 = goods only, 2 = goods and services    '); 

fdii         = fdii_bilat; 
tfdii        = fdii_total; %=sum(fdii)
fdio         = fdio_bilat;
tfdio        = fdio_total; %=sum(fdio)
ex           = exports_bilat/10^6;
tex          = exports_total/10^6; % = sum(ex)
ngdpd        = ngdpd/10^6;
nn = length(ngdpd); 
if imp_type ==1 
    im           = imports_bilat/10^6;
    tim          = imports_total/10^6; % = sum(im)
elseif imp_type == 2
    im           = imports_gs_bilat;
    tim          = imports_gs_total; % = sum(im)
end
ii           = [3,2,1,4:5]; % here, she is re-organizing data to
                                   % match Mc-P, where US is first and UK
                                   % is 3rd (I think)
bfdi        = fdii(ii,ii)./(ones(nn,1)*ngdpd(ii)')*100;
bim         = im(ii,ii)./(ones(nn,1)*ngdpd(ii)')*100; 
btfdi       = tfdii(ii)./ngdpd(ii);
btim        = tim(ii)./ngdpd(ii);

tex_gdp      = 100*tex(ii)./ngdpd(ii);
tim_gdp      = 100*tim(ii)./ngdpd(ii);
%             (i,j) element =fdi from i to j/gdp from j

% ==> put answer in loaddata.m

%
% For now: 
%    increase UK fdi to Switzerland by .0656%
% i1           = 2;
% i2           = 6;
% bfdi(i1,i2)  = bfdi(i1,i2)+.0656;

rgdppc       = rgdpp(ii)./pop(ii);
pop          = pop(ii);
taup         = corptax(ii);
data         = [pop/pop(1)*100,rgdppc/rgdppc(1)*100, taup/100, btfdi...
                btim];
             % ==> put answer in loaddata.m
clc
disp('Put bfdi,data in loaddata.m...')
