#delimit;
set more 1;
set memory 2g;
set matsize 400;


*NOTE THIS AGGREGATES ACROSS EXPERIENCE GROUPS;


*THIS DOES NOT ACCOUNT FOR FT STATUS;

*THIS CREATES THE AVERAGE WAGE IN CELL FOR SAMPLE OF WAGE & SALARY WORKERS;
*THIS USES THE PREFERRED SPECIFICATION;
*ESIMATES ELAST OF SUBST BETWEEN HS DROPOUTS AND GRADUATES ACROSS STATES;

log using /volumes/ddisk/bgh/programs/wage_mf_smsa.log, replace text;



*THIS FILE ESTIMATES THE INVERSE ELASTICITY OF SUBSTITUTION FOR NATIVES AND IMMIGRANTS USING A PREFERRED SPECIFICATION;
*18-64, POSITIVE HOURS WORKED, CORRECT DEFINITION OF IMMIGRANTS, EDUCREC FOR EDUCATION, ADJUST FOR TOP CODING;
*ESTIMATE EITHER MEN ONLY OR MEN AND WOMEN AND WITH INCWAGE;





use /volumes/ddisk/ipums2/ipums80.dta, clear;

generate byte imm=(citizen==2 | citizen==3);
drop if wkswork1==0;

*generate pdeflator=1.85;
*REPLACE WITH OP DEFLATOR;
generate pdeflator=2.314;
drop if incwage==0 | incwage==999999;
replace incwage=75000*1.5 if incwage==75000;
replace incbus=75000*1.5 if incbus==75000;
replace incfarm=75000*1.5 if incfarm==75000;
*gen incearn=incwage+incbus+incfarm;

generate weeks=wkswork1;
generate hours=uhrswork;

*SELECT FULL-TIME WORKERS;
*drop it weeks<40;
*drop if hours<35;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_wage_mf_smsa.do;
collapse (mean) lweekly weekly (count) sizew=weight (rawsum) sumweight=weight
	(sd) slweekly=lweekly sweekly=weekly [aw=weight], by(imm smsa edcode);

generate survey=1980;
sort survey edcode;
save /volumes/ddisk/data/rep80.dta, replace;



use /volumes/ddisk/ipums2/ipums90.dta, clear;

generate byte imm=(citizen==2 | citizen==3);
drop if wkswork1==0;

*generate pdeflator=1.22;
*REPLACE WITH OP DEFLATOR;
generate pdeflator=1.344;
drop if incwage==0 | incwage==999999;
generate weeks=wkswork1;
generate hours=uhrswork;

*SELECT FULL-TIME WORKERS;
*drop it weeks<40;
*drop if hours<35;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_wage_mf_smsa.do;
collapse (mean) lweekly weekly (count) sizew=weight (rawsum) sumweight=weight
	(sd) slweekly=lweekly sweekly=weekly [aw=weight], by(imm smsa edcode);

generate survey=1990;
sort survey edcode;
save /volumes/ddisk/data/rep90, replace;



use /volumes/ddisk/ipums2/ipums00.dta, clear;

generate byte imm=(citizen==2 | citizen==3);
drop if wkswork1==0;

*THIS IS ALSO THE BASE YEAR WITH OP DEFLATOR;
generate pdeflator=1;
drop if incwage==0 | incwage==999999;
generate weeks=wkswork1;
generate hours=uhrswork;

*SELECT FULL-TIME WORKERS;
*drop it weeks<40;
*drop if hours<35;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_wage_mf_smsa.do;
collapse (mean) lweekly weekly (count) sizew=weight (rawsum) sumweight=weight
	(sd) slweekly=lweekly sweekly=weekly [aw=weight], by(imm smsa edcode);

generate survey=2000;
sort survey edcode;
save /volumes/ddisk/data/rep00.dta, replace;



use /volumes/ddisk/ipumsacs/data/acs.dta, clear;

keep if year>=2005 & year<=2007;
replace perwt=perwt/3;

generate byte imm=(citizen==2 | citizen==3);
drop if wkswork1==0;

*generate pdeflator=0.85;
*REPLACE WITH OP DEFLATOR;
generate pdeflator=0.853;
drop if incwage==0 | incwage==999999;
generate weeks=wkswork1;
generate hours=uhrswork;

*SELECT FULL-TIME WORKERS;
*drop it weeks<40;
*drop if hours<35;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_wage_mf_smsa.do;
collapse (mean) lweekly weekly (count) sizew=weight (rawsum) sumweight=weight
	(sd) slweekly=lweekly sweekly=weekly [aw=weight], by(imm smsa edcode);

gen survey=2006;
sort survey edcode;
save /volumes/ddisk/data/rep06.dta, replace;




*POOL DATA ACROSS YEARS;
use /volumes/ddisk/data/rep80.dta;
append using /volumes/ddisk/data/rep90.dta;
append using /volumes/ddisk/data/rep00.dta;
append using /volumes/ddisk/data/rep06.dta;

save /volumes/ddisk/bgh/programs/wage_mf_smsa.dta, replace;

*MERGE IN DATA ON COUNTS BASED ON HOURS WORKED;
*THE COUNTS INCLUDE THE SELF-EMPLOYED;
sort survey smsa edcode;
merge survey smsa edcode using /volumes/ddisk/bgh/programs/count_smsa.dta;
tab _merge; drop _merge;
sort survey smsa edcode;
merge survey smsa edcode using /volumes/ddisk/bgh/programs/pop_smsa.dta;
tab _merge; drop _merge;


save /volumes/ddisk/bgh/programs/wage_mf_smsa.dta, replace;

log close;

