#delimit;
set more 1;
set memory 750m;
set matsize 400;
log using /volumes/ddisk/bgh/programs/count_national.log, replace;

*THIS GETS COUNT BY EDCODE AND STATE;

*FIRST WE GET COUNTS OF HOURS THAT INCLUDE THE SELF-EMPLOYED;
*THIS FILE COUNTS INDIVIDUALS BY HOURS WORKED FOR THE PREFERRED SPECIFICATION;
*18-64, NON GQ, POSITIVE WEEKS WORKED, CORRECT DEFINITION OF IMMIGRANTS, EDUCREC FOR EDUCATION;

use /volumes/ddisk/bgh/data/ipums60.dta, clear;

generate byte imm=(bpld>=15000);
replace imm=0 if bpld==90011 | bpld==90021;
drop if wkswork2==0;
generate hours=7.5*(hrswork2==1) + 22*(hrswork2==2) + 32*(hrswork2==3) + 37*(hrswork2==4) + 40*(hrswork2==5) + 44.5*(hrswork2==6) 
	+ 54*(hrswork2==7) + 70*(hrswork2==8) ;
generate weeks=6.5*(wkswork2==1) + 20*(wkswork2==2) + 33*(wkswork2==3) + 43.5*(wkswork2==4) + 48.5*(wkswork2==5) + 51*(wkswork2==6) ;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_national.do;

generate survey=1960;
save /volumes/ddisk/data/rep60.dta, replace;


use /volumes/ddisk/bgh/data/ipums70.dta, clear;

generate school=higraded - (int(higraded/10))*10;

generate byte imm=(citizen==2 | citizen==3);
drop if wkswork2==0;
generate hours=7.5*(hrswork2==1) + 22*(hrswork2==2) + 32*(hrswork2==3) + 37*(hrswork2==4) + 40*(hrswork2==5) + 44.5*(hrswork2==6) 
	+ 54*(hrswork2==7) + 70*(hrswork2==8) ;
generate weeks=6.5*(wkswork2==1) + 20*(wkswork2==2) + 33*(wkswork2==3) + 43.5*(wkswork2==4) + 48.5*(wkswork2==5) + 51*(wkswork2==6) ;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_national.do;

generate survey=1970;
save /volumes/ddisk/data/rep70.dta, replace;


use /volumes/ddisk/bgh/data/ipums80.dta, clear;

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

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_national.do;

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



use /volumes/ddisk/bgh/data/ipums90.dta, clear;

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

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_national.do;

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


use /volumes/ddisk/bgh/data/ipums00.dta, clear;

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

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_national.do;

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


use /volumes/ddisk/bgh/data/acs06.dta, clear;

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

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_national.do;

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


*POOL DATA ACROSS YEARS;
use /volumes/ddisk/data/rep60.dta, clear;
append using /volumes/ddisk/data/rep70.dta;
append using /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;

sort survey edcode; 
save /volumes/ddisk/bgh/programs/count_national.dta, replace;



log close;
