#delimit ;

*THIS COUNT PROGRAM INCLUDES THE SELF-EMPLOYED;

drop if gq==0 | gq==3 | gq==4; 
drop if age<18 | age>64;

generate nweight=perwt;
replace perwt=perwt*hours*weeks/2000;
rename perwt weight;

generate byte edcode=1*(educrec<=6) + 2*(educrec==7) + 3*(educrec==8) + 4*(educrec==9);

generate exper=age-17 if edcode==1;
replace exper=age-19 if edcode==2;
replace exper=age-21 if edcode==3;
replace exper=age-23 if edcode==4;
drop if exper<1 | exper>40;
generate expcode=1*(exper>=1 & exper<=5) + 2*(exper>=6 & exper<=10) + 3*(exper>=11 & exper<=15) 
	+ 4*(exper>=16 & exper<=20)
	+5*(exper>=21 & exper<=25) + 6*(exper>=26 & exper<=30) + 7*(exper>=31 & exper<=35) 
	+ 8*(exper>=36 & exper<=40);

gen immig=imm*weight;
gen native=(1-imm)*weight;
gen immigm=imm*weight*(sex==1);
gen nativem=(1-imm)*weight*(sex==1);

gen nimmig=imm*nweight;
gen nnative=(1-imm)*nweight;
gen nimmigm=imm*nweight*(sex==1);
gen nnativem=(1-imm)*nweight*(sex==1);

keep immig native immigm nativem nimmig nnative nimmigm nnativem edcode expcode;
collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(edcode expcode);
