#delimit;
set more 1;
set memory 2g;
set matsize 1000;
log using /volumes/ddisk/bgh/programs/count_smsa.log, replace;


*NOTE THIS AGGREGATES ACROSS EXPERIENCE GROUPS;


*THIS GETS COUNT BY EDCODE,  AND METROPOLITAN AREA;
*MUST USE MY OWN IPUMS FILES, BECAUSE THE ONES WE DOWNLOADED LONG AGO DON'T HAVE METAREAD;
*MUST ALSO RESTRICT THE ANALYSIS TO CENSUS DATA BEGINNING IN 1980;
*AND WILL USE POOLED ACS0507 TO GET AROUND SMALL SAMPLE SIZE FOR 2006;
*WHICH JUST HAPPENS TO BE THE FILE I DOWNLOADED LONG AGO;


*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/ipums2/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_smsa.do;
collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode);

generate survey=1980;
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 hours=uhrswork;
generate weeks=wkswork1;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_smsa.do;
collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode);

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


use /volumes/ddisk/ipums2/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_smsa.do;
collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode);

generate survey=2000;
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 hours=uhrswork;
generate weeks=wkswork1;

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_count_smsa.do;
collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode);

gen survey=2006;
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;

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



log close;
