clear
clc
path='D:\#课题\#国家社科\#数据\#matlab数据rural\1987\';
Files = dir(strcat(path,'*.csv'));
LengthFiles = length(Files);%%将每次循环不同的文件都输出结果
m=60;%m为单个数组的行数
n=23;%n为单个数组的列数
l=13;%数据只有l列
xls_data=zeros(m,n);
 xls_data_bq=xlsread("D:\#课题\#国家社科\#数据\#matlab数据rural\1987\buqi.xlsx");%xls_data_bq为补齐的矩阵
for i = 1:LengthFiles
     xls_data1 = xlsread(strcat(path,Files(i).name));
            file_name=Files(i).name; 
    for j=1:m
        for y=1:l  
            xls_data2((i-1)*60+j,y)=xls_data1(j,y+1);
        end
    end
        for j1=1:m
        for y1=1:n-l
            xls_data2((i-1)*60+j1,y1+l)=xls_data_bq(j1,y1+1);
        end
    end
end
for a=1:LengthFiles
    xls_data=xls_data2(((a-1)*60+1):((a)*60),:);
   
    nosch_male_sum(:,a) =sum( xls_data(:,2:2:12),2);%文盲
    nosch_male_per(:,a) =xls_data(:,2)./nosch_male_sum(:,a);
    nosch_female_sum(:,a) =sum( xls_data(:,3:2:13),2);
    nosch_female_per(:,a) =xls_data(:,3)./nosch_female_sum(:,a);
    primary_male_sum(:,a) =sum( xls_data(:,2:2:12),2);%小学
    primary_male_per(:,a) =xls_data(:,4)./primary_male_sum(:,a);
    primary_female_sum(:,a) =sum( xls_data(:,3:2:13),2);
    primary_female_per(:,a) =xls_data(:,5)./primary_female_sum(:,a);
    junior_male_sum(:,a) =sum( xls_data(:,2:2:12),2);%初中
    junior_male_per(:,a) =xls_data(:,6)./junior_male_sum(:,a);
    junior_female_sum(:,a) =sum( xls_data(:,3:2:13),2);
    junior_female_per(:,a) =xls_data(:,7)./junior_female_sum(:,a);
    senior_male_sum(:,a) =sum( xls_data(:,2:2:12),2);%高中
    senior_male_per(:,a) =xls_data(:,8)./senior_male_sum(:,a);
    senior_female_sum(:,a) =sum( xls_data(:,3:2:13),2);
    senior_female_per(:,a) =xls_data(:,9)./senior_female_sum(:,a);
    college_male_sum(:,a) =sum( xls_data(:,2:2:12),2);%大专
    college_male_per(:,a) =xls_data(:,10)./college_male_sum(:,a);
    college_female_sum(:,a) =sum( xls_data(:,3:2:13),2);
    college_female_per(:,a) =xls_data(:,11)./college_female_sum(:,a);
    university_male_sum(:,a) =sum( xls_data(:,2:2:12),2);%本科
    university_male_per(:,a) =xls_data(:,12)./university_male_sum(:,a);
    university_female_sum(:,a) =sum( xls_data(:,3:2:13),2);
    university_female_per(:,a) =xls_data(:,13)./university_female_sum(:,a);
    edu_male(:,a) =primary_male_per(:,a).*0.1404+junior_male_per(:,a).*0.4491+senior_male_per(:,a).*0.1922+college_male_per(:,a).*0.2734+university_male_per(:,a).*0.3172;%男性edu1987年方程
    edu_female(:,a) =primary_female_per(:,a).*0.1404+junior_female_per(:,a).*0.4491+senior_female_per(:,a).*0.1922+college_female_per(:,a).*0.2734+university_female_per(:,a).*0.3172;%女性edu1987年方程
    male(:,a) =xls_data(:,4)  + xls_data(:,6) + xls_data(:,8) + xls_data(:,10) + xls_data(:,12);%男性总人口
    female(:,a) =xls_data(:,5)  + xls_data(:,7) + xls_data(:,9) + xls_data(:,11) + xls_data(:,13);%女性总人口
    HC_edu_male(:,a) =edu_male(:,a) .* male(:,a);%人口加权的男性教育方面人力资本
    HC_edu_female(:,a) =edu_female(:,a) .* female(:,a);%人口加权的女性教育方面人力资本
    HC_edu_totmale(a,1) =sum(HC_edu_male(16:60,a),1);%男性总教育人力资本
    HC_edu_totfemale(a,1) =sum(HC_edu_female(16:55,a),1);%女性总教育人力资本
    pop(:,a) =sum( xls_data(:,2:13),2);%分年龄段总人口
    totpop(a,1) =sum(pop(16:60,a),1);%总人口（大于14岁的）
    HC_exp_primary(:,a) =(xls_data(:,14).* xls_data(:,4)) + (xls_data(:,15).* xls_data(:,5));%分年龄小学经验人力资本
    HC_exp_junior(:,a) =(xls_data(:,16).* xls_data(:,6)) + (xls_data(:,17).* xls_data(:,7));
    HC_exp_senior(:,a) =(xls_data(:,18).* xls_data(:,8)) + (xls_data(:,19).* xls_data(:,9));
    HC_exp_college(:,a) =(xls_data(:,20).* xls_data(:,10)) + (xls_data(:,21).* xls_data(:,11));
    HC_exp_university(:,a) =(xls_data(:,22).* xls_data(:,12)) + (xls_data(:,23).* xls_data(:,13));
    HC_exp_totprimary(a,1) =sum(HC_exp_primary(16:60,a),1);%总的小学经验人力资本
    HC_exp_totjunior(a,1) =sum(HC_exp_junior(16:60,a),1);
    HC_exp_totsenior(a,1) =sum(HC_exp_senior(16:60,a),1);
    HC_exp_totcollege(a,1) =sum(HC_exp_college(16:60,a),1);
    HC_exp_totuniversity(a,1) =sum(HC_exp_university(16:60,a),1);
    HC_edu(a,1) =HC_edu_totmale(a,1)+HC_edu_totfemale(a,1);%总的教育的人力资本
    HC_edu_aver(a,1) =HC_edu(a,1)/totpop(a,1);%教育的人均人力资本
    HC_exp(a,1) =HC_exp_totprimary(a,1)+HC_exp_totjunior(a,1)+HC_exp_totsenior(a,1)+HC_exp_totcollege(a,1)+HC_exp_totuniversity(a,1);%总的经验的人力资本
    HC_exp_aver(a,1) =HC_exp(a,1)/totpop(a,1);%经验的人均人力资本
    HC(a,1) =HC_edu(a,1)+HC_exp(a,1);%总的人力资本
    HC_aver(a,1) =HC(a,1)/totpop(a,1);%总的人均人力资本
end
HC_1987=[HC_edu,HC_edu_aver,HC_exp,HC_exp_aver,HC,HC_aver]