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

*NOTE IT AGGREGATES ACROSS EXPERIENCE GROUPS;

*THIS PROGRAM CALCULATES COUNT OF ALL PERSONS IN THE SKILL CELL, THE VARIABLE THAT WILL BE THE INSTRUMENT;

*THIS FILE COUNTS INDIVIDUALS FOR THE PREFERRED SPECIFICATION;
*18-64, NON GQ, 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;

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

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


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

generate byte imm=(citizen==2 | citizen==3);

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_pop_state.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);

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_pop_state.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);

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_pop_state.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);

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_pop_state.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);

* DEFINE SAMPLE RESTRICTIONS, COMMON VARIABLES;
do /volumes/ddisk/bgh/programs/restriction_pop_state.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 state edcode ; 
save /volumes/ddisk/bgh/programs/pop_state.dta, replace;

log close;
