clear;clc
cd '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+运行数据'
addpath('/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+程序代码')
addpath('/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件')
load('Data_use.mat');

%% 2017年贸易壁垒反事实
n = [0.5;0.7;0.9];% 依次下降50%、30%和10%
[W1_2017_C1,W2_2017_C1,W3_2017_C1] = wel2(NData.NEX_2017,TB(:,103:119),Data.ela,Data.ls(103:119,:),n(1));
[W1_2017_C2,W2_2017_C2,W3_2017_C2] = wel2(NData.NEX_2017,TB(:,103:119),Data.ela,Data.ls(103:119,:),n(2));
[W1_2017_C3,W2_2017_C3,W3_2017_C3] = wel2(NData.NEX_2017,TB(:,103:119),Data.ela,Data.ls(103:119,:),n(3));
% 反事实1：双循环贸易壁垒同时下降
[WR1_n1,WS1_n1] = wel3(NData.NIM_2017,W1_2017_C1);
[WR1_n2,WS1_n2] = wel3(NData.NIM_2017,W1_2017_C2);
[WR1_n3,WS1_n3] = wel3(NData.NIM_2017,W1_2017_C3);
WEL_REGION_1 = [WR1_n3 WR1_n2 WR1_n1];
WEL_REGION_1 = (WEL_REGION_1-1);
WEL_REGION_1 = round(WEL_REGION_1,4)*100;
WEL_SECTOR_1 = [WS1_n3 WS1_n2 WS1_n1];
WEL_SECTOR_1 = (WEL_SECTOR_1-1);
WEL_SECTOR_1 = round(WEL_SECTOR_1,4)*100;
% 反事实2：内循环贸易壁垒下降，外循环贸易壁垒不变
[WR2_n1,WS2_n1] = wel3(NData.NIM_2017,W2_2017_C1);
[WR2_n2,WS2_n2] = wel3(NData.NIM_2017,W2_2017_C2);
[WR2_n3,WS2_n3] = wel3(NData.NIM_2017,W2_2017_C3);
WEL_REGION_2 = [WR2_n3 WR2_n2 WR2_n1];
WEL_REGION_2 = (WEL_REGION_2-1);
WEL_REGION_2 = round(WEL_REGION_2,4)*100;
WEL_SECTOR_2 = [WS2_n3 WS2_n2 WS2_n1];
WEL_SECTOR_2 = (WEL_SECTOR_2-1);
WEL_SECTOR_2 = round(WEL_SECTOR_2,4)*100;
% 反事实3：外循环贸易壁垒下降，内循环贸易壁垒不变
[WR3_n1,WS3_n1] = wel3(NData.NIM_2017,W3_2017_C1);
[WR3_n2,WS3_n2] = wel3(NData.NIM_2017,W3_2017_C2);
[WR3_n3,WS3_n3] = wel3(NData.NIM_2017,W3_2017_C3);
WEL_REGION_3 = [WR3_n3 WR3_n2 WR3_n1];
WEL_REGION_3 = (WEL_REGION_3-1);
WEL_REGION_3 = round(WEL_REGION_3,4)*100;
WEL_SECTOR_3 = [WS3_n3 WS3_n2 WS3_n1];
WEL_SECTOR_3 = (WEL_SECTOR_3-1);
WEL_SECTOR_3 = round(WEL_SECTOR_3,4)*100;

%% 福利整理
% 地区层面
WEL_REGION = [WEL_REGION_1 WEL_REGION_2 WEL_REGION_3];
IntraColname = {'全国';'沿海';'内陆'};
Varname_region ={'ALL_1','ALL_2','ALL_3','D1','D2','D3','F1','F2','F3'}; 
Table_3_1 = table(WEL_REGION(:,1),WEL_REGION(:,2),WEL_REGION(:,3),WEL_REGION(:,4),WEL_REGION(:,5), ...
    WEL_REGION(:,6),WEL_REGION(:,7),WEL_REGION(:,8),WEL_REGION(:,9),'RowNames',IntraColname,'VariableNames',Varname_region);
tname_3_1 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/table_3_1.csv';
writetable(Table_3_1, tname_3_1,'WriteRowNames',true);

% 部门层面
WEL_SECTOR = [WEL_SECTOR_1 WEL_SECTOR_2 WEL_SECTOR_3];
IntraColname = {'工业';'劳动';'资本'};
Table_3_2 = table(WEL_SECTOR(:,1),WEL_SECTOR(:,2),WEL_SECTOR(:,3),WEL_SECTOR(:,4),WEL_SECTOR(:,5), ...
    WEL_SECTOR(:,6),WEL_SECTOR(:,7),WEL_SECTOR(:,8),WEL_SECTOR(:,9),'RowNames',IntraColname,'VariableNames',Varname_region);
tname_3_2 = '/Users/yuwenfang/Desktop/2023-01295_拟刊用稿/2023-01295+数据/2023-01295+日志文件/table_3_2.csv';
writetable(Table_3_2, tname_3_2,'WriteRowNames',true);




