#delimit ;

*THESE ARE THE PREFERRED RESTRICTIONS FOR WAGE AND SALARY SAMPLE;

generate perwt2=perwt;
replace perwt=perwt*hours*weeks/2000;

*COMMON RESTRICTIONS AND VARIABLE DEFINITIONS ACROSS SPECIFICATIONS;
*IN SPECIFICATION 1 PROGRAM, OP USE 18 AGE CUTOFF;
*IN OTHER PROGRAMS, OP USE 17 AGE CUTOFF;
*DROPS SELF-EMPLOYED SO CORRECT SAMPLE OF WAGE & SALARY WORKERS;

*keep if sex==1;
drop if gq==0 | gq==3 | gq==4; 
drop if age<18 | age>64;
keep if classwkd>=20 & classwkd<=28;

rename perwt weight;
rename perwt2 perwt;

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);

replace incearn=incearn*(pdeflator);
replace incwage=incwage*(pdeflator);

generate weekly=(incwage/weeks);
generate annual=(incwage);
generate wage=incwage/(weeks*hours);

generate lweekly=log(weekly);

*NOTE THAT MEAN EARNINGS ARE WEIGHTED BY HOURS WORKED;

collapse (mean) lweekly weekly (count) sizew=weight (rawsum) sumweight=weight
	(sd) slweekly=lweekly sweekly=weekly [aw=weight], by(imm edcode expcode);
