---------------------------------------------------------------------------------------------
       log:  /volumes/ddisk/bgh/programs/count_smsa.log
  log type:  text
 opened on:  13 Jul 2011, 08:12:31

. *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 EDUCAT
> ION;
. use /volumes/ddisk/ipums2/ipums80.dta, clear;

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

. drop if wkswork1==0;
(1833748 observations deleted)

. generate hours=uhrswork;

. generate weeks=wkswork1;

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

. #delimit ;
delimiter now ;
. *THIS COUNT PROGRAM INCLUDES THE SELF-EMPLOYED;
. drop if gq==0 | gq==3 | gq==4;
(148323 observations deleted)

.  drop if age<18 | age>64;
(228848 observations deleted)

. generate nweight=perwt;

. replace perwt=perwt*hours*weeks/2000;
perwt was byte now float
(4978135 real changes made)

. rename perwt weight;

. *NOTE THAT NEW IPUMS DOESN'T HAVE OLD EDUCATION CODING, SO HAD TO RECODE;
. *generate byte edcode=1*(educrec<=6) + 2*(educrec==7) + 3*(educrec==8) + 4*(educrec==9);
. generate byte edcode=1*(educ<=5) + 2*(educ==6) + 3*(educ>=7 & educ<=9) + 4*(educ==10 | educ
> ==11);

. generate exper=age-17 if edcode==1;
(4007636 missing values generated)

. replace exper=age-19 if edcode==2;
(2041933 real changes made)

. replace exper=age-21 if edcode==3;
(1024361 real changes made)

. replace exper=age-23 if edcode==4;
(941342 real changes made)

. drop if exper<1 | exper>40;
(598985 observations deleted)

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

. gen immig=imm*weight;

. gen native=(1-imm)*weight;

. gen immigm=imm*weight*(sex==1);

. gen nativem=(1-imm)*weight*(sex==1);

. gen nimmig=imm*nweight;

. gen nnative=(1-imm)*nweight;

. gen nimmigm=imm*nweight*(sex==1);

. gen nnativem=(1-imm)*nweight*(sex==1);

. *NOTE THAT IT AGGREGATES ACROSS ALL EXPERIENCE GROUPS;
. generate smsa=int(metaread/10);

. drop if smsa==0;
(1334011 observations deleted)

. summ smsa;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        smsa |   3217575    454.4421    248.6824          4        932

. keep smsa immig native immigm nativem nimmig nnative nimmigm nnativem edcode expcode;

. 
end of do-file

. collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode)
> ;

. generate survey=1980;

. save /volumes/ddisk/data/rep80.dta, replace;
file /volumes/ddisk/data/rep80.dta saved

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

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

. drop if wkswork1==0;
(1666543 observations deleted)

. generate hours=uhrswork;

. generate weeks=wkswork1;

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

. #delimit ;
delimiter now ;
. *THIS COUNT PROGRAM INCLUDES THE SELF-EMPLOYED;
. drop if gq==0 | gq==3 | gq==4;
(133841 observations deleted)

.  drop if age<18 | age>64;
(209345 observations deleted)

. generate nweight=perwt;

. replace perwt=perwt*hours*weeks/2000;
perwt was int now float
(5875161 real changes made)

. rename perwt weight;

. *NOTE THAT NEW IPUMS DOESN'T HAVE OLD EDUCATION CODING, SO HAD TO RECODE;
. *generate byte edcode=1*(educrec<=6) + 2*(educrec==7) + 3*(educrec==8) + 4*(educrec==9);
. generate byte edcode=1*(educ<=5) + 2*(educ==6) + 3*(educ>=7 & educ<=9) + 4*(educ==10 | educ
> ==11);

. generate exper=age-17 if edcode==1;
(5246710 missing values generated)

. replace exper=age-19 if edcode==2;
(2100292 real changes made)

. replace exper=age-21 if edcode==3;
(1812937 real changes made)

. replace exper=age-23 if edcode==4;
(1333481 real changes made)

. drop if exper<1 | exper>40;
(592488 observations deleted)

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

. gen immig=imm*weight;

. gen native=(1-imm)*weight;

. gen immigm=imm*weight*(sex==1);

. gen nativem=(1-imm)*weight*(sex==1);

. gen nimmig=imm*nweight;

. gen nnative=(1-imm)*nweight;

. gen nimmigm=imm*nweight*(sex==1);

. gen nnativem=(1-imm)*nweight*(sex==1);

. *NOTE THAT IT AGGREGATES ACROSS ALL EXPERIENCE GROUPS;
. generate smsa=int(metaread/10);

. drop if smsa==0;
(1826047 observations deleted)

. summ smsa;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        smsa |   3624211    459.2813    252.6329          4        936

. keep smsa immig native immigm nativem nimmig nnative nimmigm nnativem edcode expcode;

. 
end of do-file

. collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode)
> ;

. generate survey=1990;

. save /volumes/ddisk/data/rep90, replace;
file /volumes/ddisk/data/rep90.dta saved

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

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

. drop if wkswork1==0;
(1930814 observations deleted)

. generate hours=uhrswork;

. generate weeks=wkswork1;

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

. #delimit ;
delimiter now ;
. *THIS COUNT PROGRAM INCLUDES THE SELF-EMPLOYED;
. drop if gq==0 | gq==3 | gq==4;
(176137 observations deleted)

.  drop if age<18 | age>64;
(211252 observations deleted)

. generate nweight=perwt;

. replace perwt=perwt*hours*weeks/2000;
perwt was int now float
(6590614 real changes made)

. rename perwt weight;

. *NOTE THAT NEW IPUMS DOESN'T HAVE OLD EDUCATION CODING, SO HAD TO RECODE;
. *generate byte edcode=1*(educrec<=6) + 2*(educrec==7) + 3*(educrec==8) + 4*(educrec==9);
. generate byte edcode=1*(educ<=5) + 2*(educ==6) + 3*(educ>=7 & educ<=9) + 4*(educ==10 | educ
> ==11);

. generate exper=age-17 if edcode==1;
(6040860 missing values generated)

. replace exper=age-19 if edcode==2;
(2712312 real changes made)

. replace exper=age-21 if edcode==3;
(1607483 real changes made)

. replace exper=age-23 if edcode==4;
(1721065 real changes made)

. drop if exper<1 | exper>40;
(540886 observations deleted)

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

. gen immig=imm*weight;

. gen native=(1-imm)*weight;

. gen immigm=imm*weight*(sex==1);

. gen nativem=(1-imm)*weight*(sex==1);

. gen nimmig=imm*nweight;

. gen nnative=(1-imm)*nweight;

. gen nimmigm=imm*nweight*(sex==1);

. gen nnativem=(1-imm)*nweight*(sex==1);

. *NOTE THAT IT AGGREGATES ACROSS ALL EXPERIENCE GROUPS;
. generate smsa=int(metaread/10);

. drop if smsa==0;
(1756463 observations deleted)

. summ smsa;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        smsa |   4470676    459.5907    253.3799          4        936

. keep smsa immig native immigm nativem nimmig nnative nimmigm nnativem edcode expcode;

. 
end of do-file

. collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode)
> ;

. generate survey=2000;

. save /volumes/ddisk/data/rep00.dta, replace;
file /volumes/ddisk/data/rep00.dta saved

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

. keep if year>=2005 & year<=2007;
(5211120 observations deleted)

. replace perwt=perwt/3;
perwt was int now float
(5755921 real changes made)

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

. drop if wkswork1==0;
(1226408 observations deleted)

. generate hours=uhrswork;

. generate weeks=wkswork1;

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

. #delimit ;
delimiter now ;
. *THIS COUNT PROGRAM INCLUDES THE SELF-EMPLOYED;
. drop if gq==0 | gq==3 | gq==4;
(65451 observations deleted)

.  drop if age<18 | age>64;
(141821 observations deleted)

. generate nweight=perwt;

. replace perwt=perwt*hours*weeks/2000;
(4226290 real changes made)

. rename perwt weight;

. *NOTE THAT NEW IPUMS DOESN'T HAVE OLD EDUCATION CODING, SO HAD TO RECODE;
. *generate byte edcode=1*(educrec<=6) + 2*(educrec==7) + 3*(educrec==8) + 4*(educrec==9);
. generate byte edcode=1*(educ<=5) + 2*(educ==6) + 3*(educ>=7 & educ<=9) + 4*(educ==10 | educ
> ==11);

. generate exper=age-17 if edcode==1;
(3978616 missing values generated)

. replace exper=age-19 if edcode==2;
(1592342 real changes made)

. replace exper=age-21 if edcode==3;
(1058378 real changes made)

. replace exper=age-23 if edcode==4;
(1327896 real changes made)

. drop if exper<1 | exper>40;
(404219 observations deleted)

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

. gen immig=imm*weight;

. gen native=(1-imm)*weight;

. gen immigm=imm*weight*(sex==1);

. gen nativem=(1-imm)*weight*(sex==1);

. gen nimmig=imm*nweight;

. gen nnative=(1-imm)*nweight;

. gen nimmigm=imm*nweight*(sex==1);

. gen nnativem=(1-imm)*nweight*(sex==1);

. *NOTE THAT IT AGGREGATES ACROSS ALL EXPERIENCE GROUPS;
. generate smsa=int(metaread/10);

. drop if smsa==0;
(1017294 observations deleted)

. summ smsa;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        smsa |   2900728    457.7583    254.8139          4        936

. keep smsa immig native immigm nativem nimmig nnative nimmigm nnativem edcode expcode;

. 
end of do-file

. collapse (sum) immig native immigm nativem nimmig nnative nimmigm nnativem, by(smsa edcode)
> ;

. gen survey=2006;

. save /volumes/ddisk/data/rep06.dta, replace;
file /volumes/ddisk/data/rep06.dta saved

. *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;
file /volumes/ddisk/bgh/programs/count_smsa.dta saved

. log close;
       log:  /volumes/ddisk/bgh/programs/count_smsa.log
  log type:  text
 closed on:  13 Jul 2011, 08:15:44
---------------------------------------------------------------------------------------------
