%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Coupled model for Norway .
%
% The end purpose of this script is to produce multipliers per unit of
% consumption for Norway
% It uses a coupled model approach, combining EXIOBASE data on imports
% with Norwegian data for the domestic economy. 
% The calculation is done for both total supply chain emissions
% (multipliers) and for direct emissions (direct emissions associated with 
% imported goods). The latter is useful for extracting scope 2 emissions.
% The model is a derivation from the original, described at
% https://doi.org/10.5281/zenodo.1489943
%
%
% Richard Wood
% 09.12.2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% set year:
yr=2018
% set exchange rate using 2018 exchange rate 9.5962 https://www.norges-bank.no/en/topics/Statistics/exchange_rates/?tab=currency&id=EUR
Euro_to_NOK=9.5962;

%% Read and organise the raw data from Statistics Norway and EXIOBASE.


% set the paths for various data
filepath='.\' % in the current folder
capital_data_path = '.\' % in one folder up to save space - will upload to zenodo
%Orginal source: https://zenodo.org/record/5787624

% Read the sector matching file first. This is a concordance matrix with
% EXIOBASE industries as rows and Norwegian industries as per the IO tables
% as columns.
% Notation is G
Graw=importdata('Sector matching EXIOBASE DFØ NO64.xlsx');
G=Graw.data.EXIOBASEtoNO64(5:end,5:end);

% this is the matching between the 46 sectors in SSB emission accounts and
% EXIOBASE - see https://circabc.europa.eu/sd/a/744d3862-e51f-4612-80fa-593ff7dc0660/NO-partB1_GrantAgreement_No.%2050904.2011.05-2011.300.pdf
% for background to this matching
Grawemis=importdata('EmisMatching.xlsx');
Gemis=Grawemis.data(1:46,1:65);

% Read the capital matrix from EXIOBASE showing the use of different types of capital by
% industry.
load([capital_data_path,'Kbar_exio_v3_8_2_',num2str(yr),'ixi.mat'])
% this loads a variable KbarCfc_ixi, as well as the country and industry
% lables

% Extract purely the Norwegian consumption of capital for the domestic part of the model:
nor_index=(strmatch('NO',countries)-1)*163+1:(strmatch('NO',countries))*163;
% In  the next steps, we want to work out what capital inputs are
% domestically produced vs imported. First we get the total:
Ktot=kron(ones(49,1),eye(163))'*KbarCfc_ixi(:,nor_index); % the kron just aggregates the regional dimensions
% and collapse to 64 sectors using G
Ktot=G'*Ktot*G;
% then we extract the domestic only component from KbarCfc_ixi
Kdom=G'*KbarCfc_ixi(nor_index,nor_index)*G;
% and after aggregating, convert to coefficients:
Kdom_coef=Kdom/diag(sum(Ktot,1)+(sum(Ktot,1)==0));
% the imports are the total minus the domestic component, and normalise
Kimp_coef=(Ktot-Kdom)/diag(sum(Ktot,1)+(sum(Ktot,1)==0));
% Clear out any division by 0:
Kdom_coef(isnan(Kdom_coef))=0; % this is normalised to 1, but not yet normalised to use of captial specified in Nor IO table
Kimp_coef(isnan(Kimp_coef))=0; % this is normalised to 1, but not yet normalised to use of captial specified in Nor IO table

%% Read in the Norwegian IO data - % source: https://www.ssb.no/en/nasjonalregnskap-og-konjunkturer/tables/supply-and-use-and-input-output
%measured in million NOK
raw.NorIO.dom=importdata([filepath,'IO domestic 64x64.xlsx']); % domestic use matrix
raw.NorIO.imp=importdata([filepath,'IO imports 2018 64x64.xlsx']); % import use matrix
raw.NorIO.supply=importdata([filepath,'sut_1500_2018.xlsx']); % supply matrix (for conversion between basic and purchaser prices)

% And read in the Norwegian emissions data
% measured in tonnes:
% source: https://www.ssb.no/statbank/table/09288/
% raw.emisEurostat=importdata([filepath,'env_ac_ainah_r2.xls']);
% replaced/redundant due to Norwegian data
raw.emisNor=importdata([filepath,'09288_20211217-013416.xlsx']);
raw.emisEXIO=importdata([filepath,'Direct_Emissions_NO_EXIOBASE.xlsx']);


%% Extracting the Norwegian data
disp('Note - references to location of data in the Norwegian IO tables are hard-coded here - any modifications to data inputs need checking!')

NorIO.CFC=raw.NorIO.dom.data(88,5:69); %Consumption of fixed capital (values)
NorIO.CFC(isnan(NorIO.CFC))=0;

NorIO.Zdom=raw.NorIO.dom.data(15:79,5:69);  % Domestic flow matrix
NorIO.Ydom=raw.NorIO.dom.data(15:79,end-1); % Domestic final demand
NorIO.Zimp=raw.NorIO.imp.data(15:79,5:69);  % Import flow matrix
NorIO.Yimp=raw.NorIO.imp.data(15:79,end-1); % Import final demand
NorIO.x=raw.NorIO.dom.data(15:79,end);      % gross output

% clean all the data, removing any text values (NaN and Inf)
NorIO.x(isnan(NorIO.x)|isinf(NorIO.x))=0;
NorIO.Zdom(isnan(NorIO.Zdom)|isinf(NorIO.Zdom))=0;
NorIO.Ydom(isnan(NorIO.Ydom)|isinf(NorIO.Ydom))=0;
NorIO.Zimp(isnan(NorIO.Zimp)|isinf(NorIO.Zimp))=0;
NorIO.Yimp(isnan(NorIO.Yimp)|isinf(NorIO.Yimp))=0;
NorIO.x(NorIO.x==0)=1; % set 0 output to 1 to avoid division by zero.


%%
% EXIOBASE data - this data is prepared by the script ExtractMultipliers.m
% Read in EXIOBASE GHG footprints and imports without capital endogenised
EXIO_data=importdata('Multipliers_NO_bp_EXIOBASE.xlsx');
EXimp=EXIO_data.data.EXIOrawImp_2018(3:end,2);  % these are simply the imports into Norway that EXIOBASE reports
EXghg=EXIO_data.data.EXIOrawImp_2018(3:end,3);  % these are the GHG emissions embodied in imports as calculated by EXIOBASE
EXghg_direct=EXIO_data.data.EXIOrawImp_2018(3:end,4); % these are the direct GHG emissions embodied in imports as calculated by EXIOBASE


EXghg_production=raw.emisEXIO.data.EXIO_prod_2018(3:end,2); % these are the direct GHG emissions in Norway calculated by EXIOBASE

% for checking purposes
EXfd=EXIO_data.data.EXIOrawFd_2018(3:end,2);  % these are simply the imports into Norway that EXIOBASE reports
EXghgfd=EXIO_data.data.EXIOrawFd_2018(3:end,3);  % these are the GHG emissions embodied in imports as calculated by EXIOBASE


% Read in EXIOBASE GHG footprints  with capital endogenised
EXIO_data_w_K=importdata('Multipliers_NO_bp_EXIOBASE_w_Capital.xlsx');
EXghg_w_k=EXIO_data_w_K.data.EXIOrawImp_2018(3:end,3); % these are the GHG emissions embodied in imports as calculated by EXIOBASE with captial endogenised


% for checking purposes
EXfd_w_K=EXIO_data.data.EXIOrawFd_2018(3:end,2);  % these are simply the imports into Norway that EXIOBASE reports
EXghgfd_w_K=EXIO_data.data.EXIOrawFd_2018(3:end,3);  % these are the GHG emissions embodied in imports as calculated by EXIOBASE

% EXIOBASE emissions is in kilo tonnes, whilst Norwegian GHG is in tonnes, so convert all to tonnes
EXghg = EXghg/1e3;
EXghg_direct = EXghg_direct/1e3;
EXghg_w_k = EXghg_w_k/1e3;
EXghgfd = EXghgfd/1e3;
EXghgfd_w_K = EXghgfd_w_K/1e3;
EXghg_production = EXghg_production/1e3;

% EXIOBASE imports is in million Euro, whilst Norwegian IO data is in million NOK, so convert all to million NOK 
EXimp=EXimp*Euro_to_NOK;
EXfd=EXfd*Euro_to_NOK;

% Aggregate the EXIOBASE values to Norwegian classification:
EXimp64=EXimp'*G;
EXghg64=EXghg'*G;
EXghg_direct64=EXghg_direct'*G;
EXghg_w_k64=EXghg_w_k'*G;
EXghgfd64=EXghgfd'*G;
EXghgfd_w_K64=EXghgfd_w_K'*G;
EXfd64=EXfd'*G;
EXghg_production64=EXghg_production'*G;

% Assign all sector 10:12 emissions to sector 12, as per the Norwegian IO
% data
EXimp64(12)=sum(EXimp64(10:12));
EXimp64(10:11)=0;
EXghg64(12)=sum(EXghg64(10:12));
EXghg64(10:11)=0;
EXghg_direct64(12)=sum(EXghg_direct64(10:12));
EXghg_direct64(10:11)=0;
EXghg_w_k64(12)=sum(EXghg_w_k64(10:12));
EXghg_w_k64(10:11)=0;
EXghgfd64(12)=sum(EXghgfd64(10:12));
EXghgfd64(10:11)=0;
EXghgfd_w_K64(12)=sum(EXghgfd_w_K64(10:12));
EXghgfd_w_K64(10:11)=0;
EXfd64(12)=sum(EXfd64(10:12));
EXfd64(10:11)=0;


% And calculate weighted import multipliers and intensities by dividing
% GHG footprints by imports:
EXIO_weighted_import_multipliers_64=EXghg64./EXimp64;
EXIO_weighted_import_multipliers_w_k_64=EXghg_w_k64./EXimp64;
EXIO_weighted_import_direct_64=EXghg_direct64./EXimp64;
EXIO_weighted_fd_multipliers_64=EXghgfd64./EXfd64;
EXIO_weighted_fd_multipliers_w_k_64=EXghgfd_w_K64./EXfd64;

% clean for any division by 0:
EXIO_weighted_import_multipliers_64(isnan(EXIO_weighted_import_multipliers_64)|isinf(EXIO_weighted_import_multipliers_64))=0;
EXIO_weighted_import_multipliers_w_k_64(isnan(EXIO_weighted_import_multipliers_w_k_64)|isinf(EXIO_weighted_import_multipliers_w_k_64))=0;
EXIO_weighted_import_direct_64(isnan(EXIO_weighted_import_direct_64)|isinf(EXIO_weighted_import_direct_64))=0;
EXIO_weighted_fd_multipliers_64(isnan(EXIO_weighted_fd_multipliers_64)|isinf(EXIO_weighted_fd_multipliers_64))=0;
EXIO_weighted_fd_multipliers_w_k_64(isnan(EXIO_weighted_fd_multipliers_w_k_64)|isinf(EXIO_weighted_fd_multipliers_w_k_64))=0;


%% Now lets process all the Norwegian data that was previously read in (note there is a dependency on EXIOBASE emissions data for the allocation

% allocate the Norwegian emissions data (reported in 46 industries) to the
% 64 industries of the IO table, based on (aggregated) EXIOBASE data, using
% the G matrix showing the relationship between 46 and 64 industries.
tmp_emis=raw.emisNor.data*1e3; %(convert to Tonnes)
tmp_emis(isnan(tmp_emis))=0;
% NorIO.emis = tmp_emis*(Gemis*diag(EXghg_production64)./repmat(sum(Gemis*diag(EXghg_production64),2),1,65));
NorIO.emis = tmp_emis*(Gemis*diag(NorIO.x)./repmat(sum(Gemis*diag(NorIO.x),2)+eps,1,65));
NorIO.emis(isnan(NorIO.emis)|isinf(NorIO.emis))=0;

% Produce coefficients:
NorIO.Adom=NorIO.Zdom/diag(NorIO.x);            % Direct domestic coefficients
NorIO.CFCcoef=NorIO.CFC/diag(NorIO.x);          % Direct capital coefficients
NorIO.Kcoef_dom=Kdom_coef*diag(NorIO.CFCcoef);  % Direct capital coefficients, domestically sources
NorIO.Kcoef_imp=Kimp_coef*diag(NorIO.CFCcoef);  % Direct capital coefficients, imports
NorIO.Sdom=NorIO.emis/diag(NorIO.x);            % Direct emission coefficients
NorIO.Aimp=NorIO.Zimp/diag(NorIO.x);            % Direct import coefficients
NorIO.Ldom=inv(eye(size(NorIO.Adom))-NorIO.Adom);   % Leontief inverse of domestic inputs
NorIO.LKdom=inv(eye(size(NorIO.Adom))-(NorIO.Adom+NorIO.Kcoef_dom));    % Leontief inverse of domestic inputs including capital
NorIO.SLdom=NorIO.Sdom * NorIO.Ldom;            % Emission multipliers
NorIO.SLKdom=NorIO.Sdom * NorIO.LKdom;          % Emission multipliers including capital
NorIO.direct=NorIO.Sdom;


%% Coupling of EXIOBASE multipliers
Coup.S_Aimp=EXIO_weighted_import_direct_64*NorIO.Aimp;
Coup.Q_Aimp=EXIO_weighted_import_multipliers_64*NorIO.Aimp;
Coup.Q_AimpLdom = Coup.Q_Aimp*(NorIO.Ldom);

% with capital included
Coup.Q_AimpK=EXIO_weighted_import_multipliers_w_k_64*(NorIO.Aimp+NorIO.Kcoef_imp);
Coup.Q_AimpLKdom = Coup.Q_AimpK*(NorIO.LKdom);

%% Write intermediate output to files (excluding capital):

% construct a table (for writing purposes) showing Norwegian IO codes on rows, and
% the various multipliers (in basic prices) in columns  **This one
% excludes capital
Nor_Multipliers=table(NorIO.SLdom',Coup.Q_AimpLdom',EXIO_weighted_import_multipliers_64',NorIO.direct',Coup.S_Aimp',...
    'VariableNames',{'Domestic Multipliers for Domestic demand; t-CO2eq/MNOK',...
    'Import Multipliers for Domestic demand; t-CO2eq/MNOK',...
    'Import Multipliers for Direct Import demand; t-CO2eq/MNOK',...
    'Direct Multipliers of electricity - domestic; t-CO2eq/MNOK',...
    'Direct Multipliers of electricity - imports; t-CO2eq/MNOK'},'RowNames',raw.NorIO.dom.textdata(29:93,4));

writetable(Nor_Multipliers,'Multipliers_NO_bp_Coupled.xlsx','WriteRowNames',1)

%% Write intermediate output to files (including capital):

% construct a table (for writing purposes) showing Norwegian IO codes on rows, and
% the various multipliers (in basic prices) in columns **This one
% includes capital
Nor_Multipliers_with_Capital=table(NorIO.SLKdom',Coup.Q_AimpLKdom',EXIO_weighted_import_multipliers_w_k_64',NorIO.direct',Coup.S_Aimp',...
    'VariableNames',{'Domestic Multipliers for Domestic demand; t-CO2eq/MNOK',...
    'Import Multipliers for Domestic demand; t-CO2eq/MNOK',...
    'Import Multipliers for Direct Import demand; t-CO2eq/MNOK',...
    'Direct Multipliers for electricity - domestic; t-CO2eq/MNOK',...
    'Direct Multipliers for electricity - imports; t-CO2eq/MNOK'},'RowNames',raw.NorIO.dom.textdata(29:93,4));

writetable(Nor_Multipliers_with_Capital,'Multipliers_NO_bp_Coupled_w_Capital.xlsx','WriteRowNames',1)




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Stage 2
% Now lets add together the domestic and imported impacts and divide by total final demand in order to remove the trade dimension
% Firstly do it for direct scope 2 (electricity) emissions before removing the scope 2 from
% the other multipliers (to avoid double counting)

% pre-calc: total final demand (add domestic and imports, as this is not
% distinguished in the model)
Ytot = (sum(NorIO.Ydom,2)+sum(NorIO.Yimp,2)); % total final demand (denominator for the calculation of multipliers)

% The direct is simply to get the scope 2 emissions from the electricity
% sector (the other sectors are not relevant).
direct_footprints=NorIO.direct'.*sum(NorIO.Ydom,2)+Coup.S_Aimp'.*sum(NorIO.Yimp,2);
direct_footprints_domestic=NorIO.direct'.*sum(NorIO.Ydom,2);
direct_footprints_imports=Coup.S_Aimp'.*sum(NorIO.Yimp,2);

% electricity sector is sector 24
direct_footprints_elec=direct_footprints;
direct_footprints_elec([1:23,25:end])=0;
% electricity sector is sector 24
direct_footprints_elec_domestic=direct_footprints_domestic;
direct_footprints_elec_domestic([1:23,25:end])=0;
% electricity sector is sector 24
direct_footprints_elec_imports=direct_footprints_imports;
direct_footprints_elec_imports([1:23,25:end])=0;


% calculate the intensities of the direct footprints by dividing by
% expenditure
weighted_direct_intensities=direct_footprints_elec./Ytot;
weighted_direct_intensities_domestic=direct_footprints_elec_domestic./Ytot;
weighted_direct_intensities_imports=direct_footprints_elec_imports./Ytot;
weighted_direct_intensities(isnan(weighted_direct_intensities))=0;
weighted_direct_intensities_domestic(isnan(weighted_direct_intensities_domestic))=0;
weighted_direct_intensities_imports(isnan(weighted_direct_intensities_imports))=0;

% Now do it for total footprints:
total_footprints=NorIO.SLKdom'.*sum(NorIO.Ydom,2)+Coup.Q_AimpLKdom'.*sum(NorIO.Ydom,2)+EXIO_weighted_import_multipliers_w_k_64'.*sum(NorIO.Yimp,2);
total_footprints_domestic=NorIO.SLKdom'.*sum(NorIO.Ydom,2);
total_footprints_imports=Coup.Q_AimpLKdom'.*sum(NorIO.Ydom,2)+EXIO_weighted_import_multipliers_w_k_64'.*sum(NorIO.Yimp,2);

% And remove direct scope 2 to avoid double counting of electricity:
total_footprints_without_scope2=total_footprints- direct_footprints_elec;
total_footprints_without_scope2_domestic=total_footprints_domestic- direct_footprints_elec_domestic;
total_footprints_without_scope2_imports=total_footprints_imports- direct_footprints_elec_imports;

% construct multipliers as the division of total footprints and the total
% expenditure:
weighted_multipliers=total_footprints_without_scope2./Ytot;
weighted_multipliers_domestic=total_footprints_without_scope2_domestic./Ytot;
weighted_multipliers_imports=total_footprints_without_scope2_imports./Ytot;

weighted_multipliers(isnan(weighted_multipliers))=0;
weighted_multipliers_domestic(isnan(weighted_multipliers_domestic))=0;
weighted_multipliers_imports(isnan(weighted_multipliers_imports))=0;

%% Write intermediate output to files (including capital):

% construct a table (for writing purposes) showing Norwegian IO codes on rows, and
% the Coupled model multipliers (in basic prices) and EXIOBASE (basic price) multipliers
% in columns
Multipliers_with_Capital_Comparison=table(weighted_multipliers,EXIO_weighted_fd_multipliers_w_k_64',...
    'VariableNames',{'Multipliers - Coupled; t-CO2eq/MNOK',...
    'Multipliers - EXIOBASE; t-CO2eq/MNOK'},'RowNames',raw.NorIO.dom.textdata(29:93,4));

writetable(Multipliers_with_Capital_Comparison,'Multipliers_NO_bp_w_Capital_Comparison.xlsx','WriteRowNames',1)





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Stage 3 rebase to pp

% read the raw data for trade and transport margins (and basic price and
% purchaser price values)
bp=raw.NorIO.supply.data(1:65,72);
trdtsMargins=raw.NorIO.supply.data(1:65,73);
pp=raw.NorIO.supply.data(1:65,75);

% clean text showing as NaN
bp(isnan(bp))=0;
trdtsMargins(isnan(trdtsMargins))=0;
pp(isnan(pp))=0;

% Extract the positive margin values, vs the negative - the negative are
% the actual margin sectors
trdtsMargins_pos=trdtsMargins.*(trdtsMargins>0);
trdtsMargins_neg=-trdtsMargins.*(trdtsMargins<0);

% Calculate the margin component of the trade and transport margins,
% leaving the non-margin component intact. These are only a few values for
% e.g. road transport, retail and wholesale trade - they are not 100%, as
% there are both margin and non-margin components of these sectors
perc_margincomponent=trdtsMargins_neg./bp;
perc_margincomponent(isnan(perc_margincomponent))=0;
% Here we calculate the percentage of the footprints that are due to
% margins - i.e. the amount of road transprot GHG footprint that is
% actually due to margins (transport of other goods) than for transport for
% its own purpose:
ghg_todistribute=perc_margincomponent.*total_footprints;

% the remainder of the emissions are the non-margin components (i.e. the
% footprint without any trade and transport emissions included - so for the
% purchase of a book, it is just the footprint of the book production, and
% not its transport and sale to the consumer.
non_margin_emissions = (1-perc_margincomponent).*total_footprints;

% Next we need to calculate how much margins are distributed across all other commodities
trdtsMargins_distribute=trdtsMargins_pos/sum(trdtsMargins_pos);

% then we allocate the embodied margin emissions to the actual goods that
% they should be applied to eg. allocating transport emissions to the book.
margin_emissions_allocated=trdtsMargins_distribute*sum(ghg_todistribute);

% then get the total footprints (in absolute terms)
total_footprints_w_margins = non_margin_emissions+margin_emissions_allocated;

% Final step is to generate multipliers by converting between basic price
% and purchaser price as the denominator.
pp_to_bp_ratio=pp./bp;
pp_to_bp_ratio(isnan(pp_to_bp_ratio))=0;


weighted_multipliers_pp=total_footprints_w_margins./(Ytot.*pp_to_bp_ratio);
weighted_multipliers_pp(isnan(weighted_multipliers_pp))=0;
weighted_multipliers_pp(isinf(weighted_multipliers_pp))=0;

weighted_direct_pp=direct_footprints_elec./(Ytot.*pp_to_bp_ratio);
weighted_direct_pp(isnan(weighted_direct_pp))=0;

% establish the % from domestic sources:
perc_domestic_totals=total_footprints_without_scope2_domestic./total_footprints_without_scope2;
perc_domestic_direct=direct_footprints_elec_domestic./direct_footprints_elec;
perc_domestic_totals(isnan(perc_domestic_totals))=0;
perc_domestic_direct(isnan(perc_domestic_direct))=0;

weighted_multipliers_pp_domestic=weighted_multipliers_pp.*perc_domestic_totals;
weighted_multipliers_pp_imports=weighted_multipliers_pp.*(1-perc_domestic_totals);
weighted_direct_pp_domestic=weighted_direct_pp.*perc_domestic_direct;
weighted_direct_pp_imports=weighted_direct_pp.*(1-perc_domestic_direct);

%% Write final output to files (including capital):

% construct a table (for writing purposes) showing Norwegian IO codes on rows, and
% the differnt multipliers in columns.
Nor_Multipliers_with_Capital_PP=table(weighted_multipliers_pp,weighted_multipliers_pp_domestic,weighted_multipliers_pp_imports,...
    weighted_direct_pp,weighted_direct_pp_domestic,weighted_direct_pp_imports,...
    'VariableNames',...
    {'Total Multipliers, Scope 3, purchaser price; t-CO2eq/MNOK',...
    'Multipliers, Domestic, Scope 3, purchaser price; t-CO2eq/MNOK',...
    'Multipliers, Imported, Scope 3, purchaser price; t-CO2eq/MNOK',...
    'Direct Multipliers for elec, Scope 2; t-CO2eq/MNOK',...
    'Direct Multipliers for elec, Scope 2, Domestic ; t-CO2eq/MNOK',...
    'Direct Multipliers for elec, Scope 2, Imports ; t-CO2eq/MNOK'},...
    'RowNames',raw.NorIO.dom.textdata(29:93,4));

writetable(Nor_Multipliers_with_Capital_PP,'Multipliers_NO_pp_Coupled_w_Capital.xlsx','WriteRowNames',1)



%% Final step, remap to DFØ categories
GDFOraw=importdata('Matching of DFØ categories_with chemicals aggregation.xlsx');
GDFO=GDFOraw.data.NIRASMatchDF0xD8(:,2:66);

DFOcodes=GDFOraw.data.NIRASMatchDF0xD8(:,1);
DFOtxt=GDFOraw.textdata.NIRASMatchDF0xD8(3:end,2);

% construct a table (for writing purposes) showing DFØ codes on rows, and
% the differnt multipliers in columns.
Nor_Multipliers_with_Capital_PP=table(DFOtxt,DFOcodes,...
    GDFO*weighted_multipliers_pp,GDFO*weighted_multipliers_pp_domestic,GDFO*weighted_multipliers_pp_imports,...
    GDFO*weighted_direct_pp,GDFO*weighted_direct_pp_domestic,GDFO*weighted_direct_pp_imports,...
    'VariableNames',...
    {'DFØ Names','DFØ Codes',...
    'Total Multipliers, Scope 3, purchaser price; t-CO2eq/MNOK',...
    'Multipliers, Domestic, Scope 3, purchaser price; t-CO2eq/MNOK',...
    'Multipliers, Imported, Scope 3, purchaser price; t-CO2eq/MNOK',...
    'Direct Multipliers for elec, Scope 2; t-CO2eq/MNOK',...
    'Direct Multipliers for elec, Scope 2, Domestic ; t-CO2eq/MNOK',...
    'Direct Multipliers for elec, Scope 2, Imports ; t-CO2eq/MNOK'});

writetable(Nor_Multipliers_with_Capital_PP,'Multipliers_NO_pp_Coupled_w_Capital_DFO.xlsx','WriteRowNames',1)


