Appendix 2: Employment Variable Creation

Main Employment Program, Creation of Variables Linked to Past Rounds Section

Return to Appendix 2 main file


data total_numwks;
merge one round9.emp_int round9.emp_week round9.emp29_numwks empstatus; by idcode;
if r9int>-5;
array r1wks (i) &R1WKS; /* Round 1 created variable */
array r2wks (i) &R2WKS; /* Round 2 created variable */
array r3wks (i) &R3WKS; /* Round 3 created variable */

array r4wks (i) &R4WKS; /* Round 4 created variable, all jobs */
array r4ewks (i) &R4EWKS; /* Round 4 created variable, employee jobs*/
array r4swks (i) &R4SWKS; /* Round 4 created variable, self-employed jobs */

array r5wks (i) &R5WKS; /* Round 5 created variable, all jobs */
array r5ewks (i) &R5EWKS; /* Round 5 created variable, employee jobs */
array r5swks (i) &R5SWKS; /* Round 5 created variable, self-employed jobs */

array r6wks (i) &R6WKS; /* Round 6 created variable, all jobs */
array r6ewks (i) &R6EWKS; /* Round 6 created variable, employee jobs */
array r6swks (i) &R6SWKS; /* Round 6 created variable, self-employed jobs */

array r7wks (i) &R7WKS; /* Round 7 created variable, all jobs */
array r7swks (i) &R7SWKS; /*Round 7 created variable, employee jobs*/
array r7ewks (i) &R7EWKS; /*Round 7 created variable, self-employed jobs */

array r8wks (i) &R8WKS; /* Round 8 created variable, all jobs */
array r8swks (i) &R8SWKS; /*Round 8 created variable, employee jobs*/
array r8ewks (i) &R8EWKS; /*Round 8 created variable, self-employed jobs */

array r9wks (i) R9wks80-R9wks99 R9wks00-R9wks06;
array r9swks (i) R9swks80-R9swks99 R9swks00-R9swks06;
array r9ewks (i) R9ewks80-R9ewks99 R9ewks00-R9ewks06;

array twks (i) twks80-twks99 twks00-twks06; /* Total created variable, all jobs */
array tewks (i) tewks80-tewks99 tewks00-tewks06; /* Total created variable, employee jobs */
array tswks (i) tswks80-tswks99 tswks00-tswks065; /* Total created variable, self-employed jobs */

do over twks;
twks=0; tswks=0; tewks=0;
end;
do over twks;
if r9wks>0 then twks=twks+r9wks;
if r9swks>0 then tswks=tswks+r9swks;
if r9ewks>0 then tewks=tewks+r9ewks;
end;
/*Add total wks from dli to above to create new total*/
/* dli is Round 8 */
if dliwk=r8int then do;
do over r8wks;
if r8wks>0 then twks=twks+r8wks;
if r8swks>0 then tswks=tswks+r8swks;
if r8ewks>0 then tewks=tewks+r8ewks;
end;
end;
/* dli is Round 7 */
if dliwk=r7int then do;
do over r7wks;
if r7wks>0 then twks=twks+r7wks;
if r7swks>0 then tswks=tswks+r7swks;
if r7ewks>0 then tewks=tewks+r7ewks;
end;
end;
/* dli is Round 6 */
if dliwk=r6int then do;
do over r6wks;
if r6wks>0 then twks=twks+r6wks;
if r6swks>0 then tswks=tswks+r6swks;
if r6ewks>0 then tewks=tewks+r6ewks;
end;
end;
/* dli is Round 5 */
if dliwk=r5int then do;
do over r5wks;
if r5wks>0 then twks=twks+r5wks;
if r5swks>0 then tswks=tswks+r5swks;
if r5ewks>0 then tewks=tewks+r5ewks;
end;
end;
/* dli is Round 4 */
if dliwk=r4int then do;
do over r4wks;
if r4wks>0 then twks=twks+r4wks;
if r4swks>0 then tswks=tswks+r4swks;
if r4ewks>0 then tewks=tewks+r4ewks;
end;
end;
/* dli is Round 3 */
if dliwk=r3int then do;
do over r3wks;
if r3wks>0 then do; twks=twks+r3wks; tewks=tewks+r3wks; end;
end;
end;
/* dli is Round 2 */
if dliwk=r2int then do;
do over r2wks;
if r2wks>0 then do; twks=twks+r2wks; tewks=tewks+r2wks; end;
end;
end;
/* dli is Round 1 */
if dliwk=r1int then do;
do over r1wks;
if r1wks>0 then do; twks=twks+r1wks; tewks=tewks+r1wks; end;
end;
end;

/* This section is written for backreporters. Double weeks worked are identified by comparing
Round9 weeks worked with event history emp_status. A uid on event history indicates a week
that is already identified as worked. Note earliest back reported start year is 1994*/

array alljobs (i) _1-_730 wks731--wks1334;
array selfjobs (i) _1-_730 swks731--swks1334;
array empjobs (i) _1-_730 ewks731--ewks1334;

/*from event history emp_status*/
array r7ar (i) _1-_730
R8000000 -- R8005200 R8005400 -- R8010500 R8010800 -- R8015900
R8016200 -- R8021300 R8021600 -- R8026700 R8027000 -- R8032100
R8808500 -- R8813700 R8904100 -- R8909200 R9039600 -- R9044700
R9044800 -- R9049900 R9175500 -- R9180600 R9275900 -- R9278800;

/* 1994 */
dwks94=0; dswks94=0; dewks94=0;
do i=731 to 783;
if alljobs=1 and r7ar>9700 then dwks94=dwks94+1;
if selfjobs=1 and r7ar>9700 then dswks94=dswks94+1;
if empjobs=1 and r7ar>9700 then dewks94=dewks94+1;
end;

/* 1995 */
dwks95=0; dswks95=0; dewks95=0;
do i=784 to 835;
if alljobs=1 and r7ar>9700 then dwks95=dwks95+1;
if selfjobs=1 and r7ar>9700 then dswks95=dswks95+1;
if empjobs=1 and r7ar>9700 then dewks95=dewks95+1;
end;

/* 1996 */
dwks96=0; dswks96=0; dewks96=0;
do i=836 to 887;
if alljobs=1 and r7ar>9700 then dwks96=dwks96+1;
if selfjobs=1 and r7ar>9700 then dswks96=dswks96+1;
if empjobs=1 and r7ar>9700 then dewks96=dewks96+1;
end;

/* 1997 */
dwks97=0; dswks97=0; dewks97=0;
do i=888 to 939;
if alljobs=1 and r7ar>9700 then dwks97=dwks97+1;
if selfjobs=1 and r7ar>9700 then dswks97=dswks97+1;
if empjobs=1 and r7ar>9700 then dewks97=dewks97+1;
end;

/* 1998 */
dwks98=0; dswks98=0; dewks98=0;
do i=940 to 991;
if alljobs=1 and r7ar>9700 then dwks98=dwks98+1;
if selfjobs=1 and r7ar>9700 then dswks98=dswks98+1;
if empjobs=1 and r7ar>9700 then dewks98=dewks98+1;
end;

/* 1999 */
dwks99=0; dswks99=0; dewks99=0;
do i=992 to 1043;
if alljobs=1 and r7ar>9700 then dwks99=dwks99+1;
if selfjobs=1 and r7ar>9700 then dswks99=dswks99+1;
if empjobs=1 and r7ar>9700 then dewks99=dewks99+1;
end;

/* 2000 */
dwks00=0; dswks00=0; dewks00=0;
do i=1044 to 1096;
if alljobs=1 and r7ar>9700 then dwks00=dwks00+1;
if selfjobs=1 and r7ar>9700 then dswks00=dswks00+1;
if empjobs=1 and r7ar>9700 then dewks00=dewks00+1;
end;

/* 2001 */
dwks01=0; dswks01=0; dewks01=0;
do i=1097 to 1148;
if alljobs=1 and r7ar>9700 then dwks01=dwks01+1;
if selfjobs=1 and r7ar>9700 then dswks01=dswks01+1;
if empjobs=1 and r7ar>9700 then dewks01=dewks01+1;
end;

/* 2002 */
dwks02=0; dswks02=0; dewks02=0;
do i=1149 to 1200;
if alljobs=1 and r7ar>9700 then dwks02=dwks02+1;
if selfjobs=1 and r7ar>9700 then dswks02=dswks02+1;
if empjobs=1 and r7ar>9700 then dewks02=dewks02+1;
end;
if idcode=416 then do; dwks02=dwks02+20; dewks02=dewks02+20; end;
*bckrep on alljobs not on r7ar;

/* 2003 */
dwks03=0; dswks03=0; dewks03=0;
do i=1201 to 1252;
if alljobs=1 and r7ar>9700 then dwks03=dwks03+1;
if selfjobs=1 and r7ar>9700 then dswks03=dswks03+1;
if empjobs=1 and r7ar>9700 then dewks03=dewks03+1;
end;

/* 2004 */
dwks04=0; dswks04=0; dewks04=0;
do i=1253 to 1304;
if alljobs=1 and r7ar>9700 then dwks04=dwks04+1;
if selfjobs=1 and r7ar>9700 then dswks04=dswks04+1;
if empjobs=1 and r7ar>9700 then dewks04=dewks04+1;
end;

/* 2005 */
dwks05=0; dswks05=0; dewks05=0;
do i=1305 to 1334;
if alljobs=1 and r7ar>9700 then dwks05=dwks05+1;
if selfjobs=1 and r7ar>9700 then dswks05=dswks05+1;
if empjobs=1 and r7ar>9700 then dewks05=dewks05+1;
end;

array dwks (i) dwks80-dwks99 dwks00-dwks06;
array dswks (i) dswks80-dswks99 dswks00-dswks06;
array dewks (i) dewks80-dewks99 dewks00-dewks06;
do over dwks;
if dwks>0 then twks=twks-dwks;
if dswks>0 then tswks=tswks-dswks;
if dewks>0 then tewks=tewks-dewks;
end;

/* If created variable from current or dli is -1/-2/-3,
then the overall created variable will be -3*/
do over r7wks;
if r9wks in (-1,-2,-3) then twks=-3;
if r9swks in (-1,-2,-3) then tswks=-3;
if r9ewks in (-1,-2,-3) then tewks=-3;
if r8wks in (-1,-2,-3) and dliwk=r8int then twks=-3;
if r8swks in (-1,-2,-3) and dliwk=r8int then tswks=-3;
if r8ewks in (-1,-2,-3) and dliwk=r8int then tewks=-3;
if r7wks in (-1,-2,-3) and dliwk=r7int then twks=-3;
if r7swks in (-1,-2,-3) and dliwk=r7int then tswks=-3;
if r7ewks in (-1,-2,-3) and dliwk=r7int then tewks=-3;
if r6wks in (-1,-2,-3) and dliwk=r6int then twks=-3;
if r6swks in (-1,-2,-3) and dliwk=r6int then tswks=-3;
if r6ewks in (-1,-2,-3) and dliwk=r6int then tewks=-3;
if r5wks in (-1,-2,-3) and dliwk=r5int then twks=-3;
if r5swks in (-1,-2,-3) and dliwk=r5int then tswks=-3;
if r5ewks in (-1,-2,-3) and dliwk=r5int then tewks=-3;
if r4wks in (-1,-2,-3) and dliwk=r4int then twks=-3;
if r4swks in (-1,-2,-3) and dliwk=r4int then tswks=-3;
if r4ewks in (-1,-2,-3) and dliwk=r4int then tewks=-3;
if r3wks in (-1,-2,-3) and dliwk=r3int then do; twks=-3; tewks=-3; end;
if r2wks in (-1,-2,-3) and dliwk=r2int then do; twks=-3; tewks=-3; end;
if r1wks in (-1,-2,-3) and dliwk=r1int then do; twks=-3; tewks=-3; end;
end;
drop _1-_730;
run;

data total_numwksyr(keep=idcode match1_1 -- match6_9);

*Not included in R9 variable list. Need match variable for other programs;
merge one round9.emp_int round9.emp_week; by idcode;
if r9int>-5;

/* Define "mat1_4" as the dummy match variable that equals 1 when the first job
in the last round and the fourth job in the current round have the same UID.*/
array r9uid (j) &R9uid;
array r9mil (j) &r9mil;
array r8uid (i) &R8uid;
array r7uid (i) &R7UID;
array r6uid (i) &R6uid;
array r5uid (i) &R5UID;
array r4uid (i) &R4uid;
array r3uid (i) &R3uid;
array r2uid (i) &R2UID;
array r1uid (i) &R1uid;

array match {11,9} match1_1-match1_9 match2_1-match2_9
match3_1-match3_9 match4_1-match4_9
match5_1-match5_9 match6_1-match6_9
match7_1-match7_9 match8_1-match8_9
match9_1-match9_9 match10_1-match10_9
match11_1-match11_9;
do i=1 to 9;
if r1uid>0 then do;
do j=1 to 9;
if r1uid=r9uid and r2uid ne r9uid and r3uid ne r9uid and r4uid ne r9uid and
r5uid ne r9uid and r6uid ne r9uid and r7uid ne r9uid
then match(i,j)=1;
end;
end;
end;
do i=1 to 9;
if r2uid>0 then do;
do j=1 to 9;
if r2uid=r9uid and r3uid ne r9uid and r4uid ne r9uid and
r5uid ne r9uid and r6uid ne r9uid and r7uid ne r9uid
then match(i,j)=2;
end;
end;
end;
do i=1 to 9;
if r3uid>0 then do;
do j=1 to 9;
if r3uid=r9uid and r4uid ne r9uid and
r5uid ne r9uid and r6uid ne r9uid and r7uid ne r9uid
then match(i,j)=3;
end;
end;
end;
do i=1 to 9;
if r4uid>0 then do;
do j=1 to 9;
if r4uid=r9uid and
r5uid ne r9uid and r6uid ne r9uid and r7uid ne r9uid
then match(i,j)=4;
end;
end;
end;
do i=1 to 8;
if r5uid>0 then do;
do j=1 to 9;
if r5uid=r9uid and r6uid ne r9uid and r7uid ne r9uid
then match(i,j)=5;
end;
end;
end;
do i=1 to 11;
if r6uid>0 then do;
do j=1 to 9;
if r6uid=r9uid and r7uid ne r9uid then match(i,j)=6;
end;
end;
end;
do i=1 to 10;
if r7uid>0 then do;
do j=1 to 9;
if r7uid=r9uid then match(i,j)=7;
end;
end;
end;
do i=1 to 7;
if r8uid>0 then do;
do j=1 to 9;
if r8uid=r9uid then match(i,j)=8;
end;
end;
end;

*find the most recent round matching each Round9 job;
array match1 (j) match1_1-match1_9;
array match2 (j) match2_1-match2_9;
array match3 (j) match3_1-match3_9;
array match4 (j) match4_1-match4_9;
array match5 (j) match5_1-match5_9;
array match6 (j) match6_1-match6_9;

do over match1;
if match1 ne max(match1,match2,match3,match4,match5,match6) then match1=.;
if match2 ne max(match1,match2,match3,match4,match5,match6) then match2=.;
if match3 ne max(match1,match2,match3,match4,match5,match6) then match3=.;
if match4 ne max(match1,match2,match3,match4,match5,match6) then match4=.;
if match5 ne max(match1,match2,match3,match4,match5,match6) then match5=.;
if match6 ne max(match1,match2,match3,match4,match5,match6) then match6=.;
end;
run;

data total_tenure;
merge one round9.emp_int round9.emp32_jobten total_numwksyr; by idcode;
if r9int>-5;
*Adds current total weeks worked to dli total weeks worked to update
total weeks worked for each job reported in current round;
array match1 (j) match1_1-match1_9;
array match2 (j) match2_1-match2_9;
array match3 (j) match3_1-match3_9;
array match4 (j) match4_1-match4_9;
array match5 (j) match5_1-match5_9;
array match6 (j) match6_1-match6_9;
array r9ten (j) r9ten1-r9ten9;
array totten (j) totten1-totten9;

do j=1 to 9;
totten=0;
if r9ten ne . then totten=totten+r9ten;
end;

*The only R9 matches are to L1-L6, round1 to round8;
array match {6,9} match1_1-match1_9 match2_1-match2_9 match3_1-match3_9
match4_1-match4_9 match5_1-match5_9 match6_1-match6_9;
array r8ten (i) S3836500 S3836600 S3836700 S3836800 S3836900 S3837000;
array r7ten (i) S2035100 S2035200 S2035300 S2035400 S2035500 S2035600;
array r6ten (i) S1565000 S1565100 S1565200 S1565300 S1565400 S1565500;
array r5ten (i) R7249100 R7249200 R7249300 R7249400 R7249500 R7249600;
array r4ten (i) R5484800 R5484900 R5485000 R5485100 R5485200 R5485300;
array r3ten (i) R3901600 R3901700 R3901800 R3901900 R3902000 R3902100;
array r2ten (i) R2579200 R2579300 R2579400 R2579500 R2579600 R2579700;
array r1ten (i) R1219900 R1220000 R1220100 R1220200 R1220300 R1220400;

do j=1 to 9;
if totten ge 0 then do;
do i=1 to 6;
if match(i,j)=8 and r8ten>0 then totten=totten+r8ten;
if match(i,j)=8 and r8ten=-3 then totten=-3;
if match(i,j)=7 and r7ten>0 then totten=totten+r7ten;
if match(i,j)=7 and r7ten=-3 then totten=-3;
if match(i,j)=6 and r6ten>0 then totten=totten+r6ten;
if match(i,j)=6 and r6ten=-3 then totten=-3;
if match(i,j)=5 and r5ten>0 then totten=totten+r5ten;
if match(i,j)=5 and r5ten=-3 then totten=-3;
if match(i,j)=4 and r4ten>0 then totten=totten+r4ten;
if match(i,j)=4 and r4ten=-3 then totten=-3;
if match(i,j)=3 and r3ten>0 then totten=totten+r3ten;
if match(i,j)=3 and r3ten=-3 then totten=-3;
if match(i,j)=2 and r2ten>0 then totten=totten+r2ten;
if match(i,j)=2 and r2ten=-3 then totten=-3;
if match(i,j)=1 and r1ten>0 then totten=totten+r1ten;
if match(i,j)=1 and r1ten=-3 then totten=-3;
end;
end;
end;
run;

data total_anhrs;
merge one round9.emp_int round9.emp_week round9.emp33_anhours; by idcode;
if r9int>-5;

array thrs (k) thrs80-thrs99 thrs00-thrs06;
array tshrs (k) tshrs80-tshrs99 tshrs00-tshrs06;
array tehrs (k) tehrs80-tehrs99 tehrs00-tehrs06;
array r1hrs (k) &R1hrs;
array r2hrs (k) &R2hrs;
array r3hrs (k) &R3hrs;
array r4hrs (k) &R4hrs;
array r4shrs (k) &R4shrs;
array r4ehrs (k) &R4ehrs;
array r5hrs (k) &R5hrs;
array r5shrs (k) &R5shrs;
array r5ehrs (k) &R5ehrs;
array r6hrs (k) &R6hrs;
array r6shrs (k) &R6shrs;
array r6ehrs (k) &R6ehrs;
array r7hrs (k) &R7hrs;
array r7shrs (k) &R7shrs;
array r7ehrs (k) &R7ehrs;
array r8hrs (k) &R8hrs;
array r8shrs (k) &R8shrs;
array r8ehrs (k) &R8ehrs;
array r9hrs (k) r9hrs80-r9hrs99 r9hrs00-r9hrs06;
array r9shrs (k) r9shrs80-r9shrs99 r9shrs00-r9shrs06;
array r9ehrs (k) r9ehrs80-r9ehrs99 r9ehrs00-r9ehrs06;

*Total annual hours is current annual hours + annual hours from dli,
by calendar year;
do k=1 to 27;
thrs=0; tshrs=0; tehrs=0;
if r9hrs>0 then thrs=thrs+r9hrs;
if r9shrs>0 then tshrs=tshrs+r9shrs;
if r9ehrs>0 then tehrs=tehrs+r9ehrs;

if r8hrs>0 and dliwk=r8int then thrs=thrs+r8hrs;
if r8shrs>0 and dliwk=r8int then tshrs=tshrs+r8shrs;
if r8ehrs>0 and dliwk=r8int then tehrs=tehrs+r8ehrs;

if r7hrs>0 and dliwk=r7int then thrs=thrs+r7hrs;
if r7shrs>0 and dliwk=r7int then tshrs=tshrs+r7shrs;
if r7ehrs>0 and dliwk=r7int then tehrs=tehrs+r7ehrs;

if r6hrs>0 and dliwk=r6int then thrs=thrs+r6hrs;
if r6shrs>0 and dliwk=r6int then tshrs=tshrs+r6shrs;
if r6ehrs>0 and dliwk=r6int then tehrs=tehrs+r6ehrs;

if r5hrs>0 and dliwk=r5int then thrs=thrs+r5hrs;
if r5shrs>0 and dliwk=r5int then tshrs=tshrs+r5shrs;
if r5ehrs>0 and dliwk=r5int then tehrs=tehrs+r5ehrs;

if r4hrs>0 and dliwk=r4int then thrs=thrs+r4hrs;
if r4shrs>0 and dliwk=r4int then tshrs=tshrs+r4shrs;
if r4ehrs>0 and dliwk=r4int then tehrs=tehrs+r4ehrs;

if r3hrs>0 and dliwk=r3int then thrs=thrs+r3hrs;
if r2hrs>0 and dliwk=r2int then thrs=thrs+r2hrs;
if r1hrs>0 and dliwk=r1int then thrs=thrs+r1hrs;

if -4<r9hrs<0 then thrs=r9hrs;
if -4<r9shrs<0 then tshrs=r9shrs;
if -4<r9ehrs<0 then tehrs=r9ehrs;

if -4<r8hrs<0 and dliwk=r8int then thrs=r8hrs;
if -4<r8shrs<0 and dliwk=r8int then tshrs=r8shrs;
if -4<r8ehrs<0 and dliwk=r8int then tehrs=r8ehrs;

if -4<r7hrs<0 and dliwk=r7int then thrs=r7hrs;
if -4<r7shrs<0 and dliwk=r7int then tshrs=r7shrs;
if -4<r7ehrs<0 and dliwk=r7int then tehrs=r7ehrs;

if -4<r6hrs<0 and dliwk=r6int then thrs=r6hrs;
if -4<r6shrs<0 and dliwk=r6int then tshrs=r6shrs;
if -4<r6ehrs<0 and dliwk=r6int then tehrs=r6ehrs;

if -4<r5hrs<0 and dliwk=r5int then thrs=r5hrs;
if -4<r5shrs<0 and dliwk=r5int then tshrs=r5shrs;
if -4<r5ehrs<0 and dliwk=r5int then tehrs=r5ehrs;

if -4<r4hrs<0 and dliwk=r4int then thrs=r4hrs;
if -4<r4shrs<0 and dliwk=r4int then tshrs=r4shrs;
if -4<r4ehrs<0 and dliwk=r4int then tehrs=r4ehrs;

if -4<r3hrs<0 and dliwk=r3int then thrs=r3hrs;
if -4<r2hrs<0 and dliwk=r2int then thrs=r2hrs;
if -4<r1hrs<0 and dliwk=r1int then thrs=r1hrs;
end;

run;

data total_wksage14(drop=_1-_730);
merge one(keep=idcode S3836200 -- S3836400 S2034800 -- S2035000
S1564700 -- S1564900 R7248800 -- R7249000
R5484500 -- R5484700 R3901500 R2579100 R1219800) round9.emp_bday
round9.emp_int round9.emp_week round9.emp29_numwks round9.emp34_wksage14
empstatus; by idcode;
if r9int>-5;

/*rename variables from prior rounds*/
r8ewks14=S3836200; r8ewks20=S3836300; r8wks20=S3836400;
r7ewks14=S2034800; r7ewks20=S2034900; r7wks20=S2035000;
r6ewks14=S1564700; r6ewks20=S1564800; r6wks20=S1564900;
r5ewks14=R7248800; r5ewks20=R7248900; r5wks20=R7249000;
r4ewks14=R5484500; r4ewks20=R5484600; r4wks20=R5484700;
r3ewks14=R3901500;
r2ewks14=R2579100;
r1ewks14=R1219800;

if age20wk<r9int then twks20=0; if age20wk<r9int then tewks20=0; tewks14=0;
if r9wks20>0 then twks20=twks20+r9wks20;
if r9ewks20>0 then tewks20=tewks20+r9ewks20;
if r9ewks14>0 then tewks14=tewks14+r9ewks14;

/*Add total wks from dli to above to create new total*/
/* dli is Round 8 */
if dliwk=r8int then do;
if r8wks20>0 then twks20=twks20+r8wks20;
if r8ewks20>0 then tewks20=tewks20+r8ewks20;
if r8ewks14>0 then tewks14=tewks14+r8ewks14;
end;
/* dli is Round 7 */
if dliwk=r7int then do;
if r7wks20>0 then twks20=twks20+r7wks20;
if r7ewks20>0 then tewks20=tewks20+r7ewks20;
if r7ewks14>0 then tewks14=tewks14+r7ewks14;
end;
/* dli is Round 6 */
if dliwk=r6int then do;
if r6wks20>0 then twks20=twks20+r6wks20;
if r6ewks20>0 then tewks20=tewks20+r6ewks20;
if r6ewks14>0 then tewks14=tewks14+r6ewks14;
end;
/* dli is Round 5 */
if dliwk=r5int then do;
if r5wks20>0 then twks20=twks20+r5wks20;
if r5ewks20>0 then tewks20=tewks20+r5ewks20;
if r5ewks14>0 then tewks14=tewks14+r5ewks14;
end;
/* dli is Round 4 */
if dliwk=r4int then do;
if r4wks20>0 then twks20=twks20+r4wks20;
if r4ewks20>0 then tewks20=tewks20+r4ewks20;
if r4ewks14>0 then tewks14=tewks14+r4ewks14;
end;
/* dli is Round 3 */
if dliwk=r3int then do;
if r3ewks14>0 then tewks14=tewks14+r3ewks14;
end;
/* dli is Round 2 */
if dliwk=r2int then do;
if r2ewks14>0 then tewks14=tewks14+r2ewks14;
end;
/* dli is Round 1 */
if dliwk=r1int then do;
if r1ewks14>0 then tewks14=tewks14+r1ewks14;
end;

/* This section is written for backreporters. Double weeks worked are identified by comparing
Round8 weeks worked with event history emp_status. A uid on event history indicates a week
that is already identified as worked. Note earliest back reported start year is 1994*/
array alljobs (i) _1-_730 wks731--wks1334;
array empjobs (i) _1-_730 ewks731--ewks1334;

/*from event history emp_status*/
array r7ar (i) _1-_730
R8000000 -- R8005200 R8005400 -- R8010500 R8010800 -- R8015900
R8016200 -- R8021300 R8021600 -- R8026700 R8027000 -- R8032100
R8808500 -- R8813700 R8904100 -- R8909200 R9039600 -- R9044700
R9044800 -- R9049900 R9175500 -- R9180600 R9275900 -- R9278800;

/*age14wk to age20wk-1 */
dewks14=0;
if age20wk-1 le 1334 then do;
do i=731 to age20wk-1;
if empjobs=1 and r7ar>9700 then dewks14=dewks14+1;
end; end;

/* age20wk to wk1334 */
if age20wk<r8int then do; dwks20=0; dewks20=0; end;
if age20wk le 1334 then do;
do i=age20wk to 1334;
if alljobs=1 and r7ar>9700 then dwks20=dwks20+1;
if empjobs=1 and r7ar>9700 then dewks20=dewks20+1;
end; end;

if dwks20>0 then twks20=twks20-dwks20;
if dewks20>0 then tewks20=tewks20-dewks20;
if dewks14>0 then tewks14=tewks14-dewks14;

/* If either created variable from current or dli is -3,
then the overall created variable will be -3 */
if r9wks20 in (-3) then twks20=-3;
if r9ewks20 in (-3) then tewks20=-3;
if r9ewks14 in (-3) then tewks14=-3;
if r8wks20 in (-3) and dliwk=r8int then twks20=-3;
if r8ewks20 in (-3) and dliwk=r8int then tewks20=-3;
if r8ewks14 in (-3) and dliwk=r8int then tewks14=-3;
if r7wks20 in (-3) and dliwk=r7int then twks20=-3;
if r7ewks20 in (-3) and dliwk=r7int then tewks20=-3;
if r7ewks14 in (-3) and dliwk=r7int then tewks14=-3;
if r6wks20 in (-3) and dliwk=r6int then twks20=-3;
if r6ewks20 in (-3) and dliwk=r6int then tewks20=-3;
if r6ewks14 in (-3) and dliwk=r6int then tewks14=-3;
if r5wks20 in (-3) and dliwk=r5int then twks20=-3;
if r5ewks20 in (-3) and dliwk=r5int then tewks20=-3;
if r5ewks14 in (-3) and dliwk=r5int then tewks14=-3;
if r4wks20 in (-3) and dliwk=r4int then twks20=-3;
if r4ewks20 in (-3) and dliwk=r4int then tewks20=-3;
if r4ewks14 in (-3) and dliwk=r4int then tewks14=-3;
if r3ewks14 in (-3) and dliwk=r3int then do; tewks14=-3; end;
if r2ewks14 in (-3) and dliwk=r2int then do; tewks14=-3; end;
if r1ewks14 in (-3) and dliwk=r1int then do; tewks14=-3; end;
run;

data total_hrsage14; merge one round9.emp_bday round9.emp_int
round9.emp_week round9.emp35_hrsage14 ;
by idcode;
if r9int>-5;
*this program creates the following variables:
CV_HOURS_WK_TEEN
CV_HOURS_WK_ADULT_ALL
CV_HOURS_WK_ADULT_ET;

*rename variables from prior rounds;
r8ehrs14=S3813900; r8ehrs20=S3814000; r8hrs20=S3814100;
r7ehrs14=S2012400; r7ehrs20=S2012500; r7hrs20=S2012600;
r6ehrs14=S1542600; r6ehrs20=S1542700; r6hrs20=S1542800;
r5ehrs14=R7228700; r5ehrs20=R7228800; r5hrs20=R7228900;
r4ehrs14=R5465000; r4ehrs20=R5465100; r4hrs20=R5465000;
r3hrs14=R3885800;
r2hrs14=R2564200;
r1hrs14=R1205800;

*initialize for Rs age14(age20) as of current interview;
tehrs14=0;
if age20wk<r9int then thrs20=0;
if age20wk<r9int then tehrs20=0;

*Want only hrs from employee type jobs for age 14-19.
All hrs R3 and earlier are assumed to be from employee type jobs;
if r9ehrs14=>0 then tehrs14=tehrs14+r9ehrs14;
if r9ehrs14=-3 then tehrs14=-3;

if tehrs14 ge 0 and dliwk=r8int then do;
if r8ehrs14>0 then tehrs14=tehrs14+r8ehrs14;
if r8ehrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r7int then do;
if r7ehrs14>0 then tehrs14=tehrs14+r7ehrs14;
if r7ehrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r6int then do;
if r6ehrs14>0 then tehrs14=tehrs14+r6ehrs14;
if r6ehrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r5int then do;
if r5ehrs14>0 then tehrs14=tehrs14+r5ehrs14;
if r5ehrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r4int then do;
if r4ehrs14>0 then tehrs14=tehrs14+r4ehrs14;
if r4ehrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r3int then do;
if r3hrs14>0 then tehrs14=tehrs14+r3hrs14;
if r3hrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r2int then do;
if r2hrs14>0 then tehrs14=tehrs14+r2hrs14;
if r2hrs14=-3 then tehrs14=-3;
end;
if tehrs14 ge 0 and dliwk=r1int then do;
if r1hrs14>0 then tehrs14=tehrs14+r1hrs14;
if r1hrs14=-3 then tehrs14=-3;
end;

/*No R is age 20 until R3 and none of these has dliwk=r3int*/
if r9ehrs20=>0 then tehrs20=tehrs20+r9ehrs20;
if r9ehrs20=-3 then tehrs20=-3;

if tehrs20 ge 0 and dliwk=r8int then do;
if r8ehrs20>0 then tehrs20=tehrs20+r8ehrs20;
if r8ehrs20=-3 then tehrs20=-3;
end;
if tehrs20 ge 0 and dliwk=r7int then do;
if r7ehrs20>0 then tehrs20=tehrs20+r7ehrs20;
if r7ehrs20=-3 then tehrs20=-3;
end;
if tehrs20 ge 0 and dliwk=r6int then do;
if r6ehrs20>0 then tehrs20=tehrs20+r6ehrs20;
if r6ehrs20=-3 then tehrs20=-3;
end;
if tehrs20 ge 0 and dliwk=r5int then do;
if r5ehrs20>0 then tehrs20=tehrs20+r5ehrs20;
if r5ehrs20=-3 then tehrs20=-3;
end;
if tehrs20 ge 0 and dliwk=r4int then do;
if r4ehrs20>0 then tehrs20=tehrs20+r4ehrs20;
if r4ehrs20=-3 then tehrs20=-3;
end;

if r9hrs20=>0 then thrs20=thrs20+r9hrs20;
if r9hrs20=-3 then thrs20=-3;

if thrs20 ge 0 and dliwk=r8int then do;
if r8hrs20>0 then thrs20=thrs20+r8hrs20;
if r8hrs20=-3 then thrs20=-3;
end;
if thrs20 ge 0 and dliwk=r7int then do;
if r7hrs20>0 then thrs20=thrs20+r7hrs20;
if r7hrs20=-3 then thrs20=-3;
end;
if thrs20 ge 0 and dliwk=r6int then do;
if r6hrs20>0 then thrs20=thrs20+r6hrs20;
if r6hrs20=-3 then thrs20=-3;
end;
if thrs20 ge 0 and dliwk=r5int then do;
if r5hrs20>0 then thrs20=thrs20+r5hrs20;
if r5hrs20=-3 then thrs20=-3;
end;
if thrs20 ge 0 and dliwk=r4int then do;
if r4hrs20>0 then thrs20=thrs20+r4hrs20;
if r4hrs20=-3 then thrs20=-3;
end;

run;

data total_numjobs; merge one round9.emp_int round9.emp_week
round9.emp31_jobwks round9.emp36_numjobs total_numwksyr; by idcode;
if r9int ne -5;

array r2job (k) &R2job;
array r3job (k) &R3job;
array r4job (k) &R4job;
array r4self (k) &R4self;
array r4emp (k) &R4emp;
array r5job (k) &R5job;
array r5self (k) &R5self;
array r5emp (k) &R5emp;
array r6job (k) &R6job;
array r6self (k) &R6self;
array r6emp (k) &R6emp;
array r7job (k) &R7job;
array r7self (k) &R7self;
array r7emp (k) &R7emp;
array r8job (k) &R8job;
array r8self (k) &R8self;
array r8emp (k) &R8emp;

array r9job (k) r9job80 -r9job99 r9job00 -r9job06;
array r9self (k) r9self80-r9self99 r9self00-r9self06;
array r9emp (k) r9emp80 -r9emp99 r9emp00 -r9emp06;
array tjob (k) tjob80-tjob99 tjob00-tjob06;
array tsjob (k) tsjob80-tsjob99 tsjob00-tsjob06;
array tejob (k) tejob80-tejob99 tejob00-tejob06;

/* Initialize created variable */
do over tjob;
tjob=0;
tsjob=0;
tejob=0;
end;

do over tjob;
if r9job>0 then tjob=tjob+r9job; else if r9job=-3 then tjob=-3;
if r9emp>0 then tejob=tejob+r9emp; else if r9emp=-3 then tejob=-3;
if r9self>0 then tsjob=tsjob+r9self; else if r9self=-3 then tsjob=-3;

if dliwk=r8int then do;
if tjob ge 0 and r8job>0 then tjob=tjob+r8job; else if r8job=-3 then tjob=-3;
if tejob ge 0 and r8emp>0 then tejob=tejob+r8emp; else if r8emp=-3 then tejob=-3;
if tsjob ge 0 and r8self>0 then tsjob=tsjob+r8self; else if r8self=-3 then tsjob=-3;
end;

if dliwk=r7int then do;
if tjob ge 0 and r7job>0 then tjob=tjob+r7job; else if r7job=-3 then tjob=-3;
if tejob ge 0 and r7emp>0 then tejob=tejob+r7emp; else if r7emp=-3 then tejob=-3;
if tsjob ge 0 and r7self>0 then tsjob=tsjob+r7self; else if r7self=-3 then tsjob=-3;
end;

if dliwk=r6int then do;
if tjob ge 0 and r6job>0 then tjob=tjob+r6job; else if r6job=-3 then tjob=-3;
if tejob ge 0 and r6emp>0 then tejob=tejob+r6emp; else if r6emp=-3 then tejob=-3;
if tsjob ge 0 and r6self>0 then tsjob=tsjob+r6self; else if r6self=-3 then tsjob=-3;
end;

if dliwk=r5int then do;
if tjob ge 0 and r5job>0 then tjob=tjob+r5job; else if r5job=-3 then tjob=-3;
if tejob ge 0 and r5emp>0 then tejob=tejob+r5emp; else if r5emp=-3 then tejob=-3;
if tsjob ge 0 and r5self>0 then tsjob=tsjob+r5self; else if r5self=-3 then tsjob=-3;
end;

if dliwk=r4int then do;
if tjob ge 0 and r4job>0 then tjob=tjob+r4job; else if r4job=-3 then tjob=-3;
if tejob ge 0 and r4emp>0 then tejob=tejob+r4emp; else if r4emp=-3 then tejob=-3;
if tsjob ge 0 and r4self>0 then tsjob=tsjob+r4self; else if r4self=-3 then tsjob=-3;
end;

if dliwk=r3int then do;
if tjob ge 0 and r3job>0 then tjob=tjob+r3job; else if r3job=-3 then tjob=-3;
end;

if dliwk=r2int then do;
if tjob ge 0 and r2job>0 then tjob=tjob+r2job; else if r2job=-3 then tjob=-3;
end;
end;

array self (j) &R9sel;
array match1 (j) match1_1-match1_9;
array match2 (j) match2_1-match2_9;
array match3 (j) match3_1-match3_9;
array match4 (j) match4_1-match4_9;
array match5 (j) match5_1-match5_9;
array match6 (j) match6_1-match6_9;

array same (k) same80-same99 same00-same06;
array ssame (k) ssame80-ssame99 ssame00-ssame06;
do k=1 to 27; same=0; ssame=0; end;

array r8w_1 (k) &R8W_01;
array r8w_2 (k) &R8W_02;
array r8w_3 (k) &R8W_03;
array r8w_4 (k) &R8W_04;
array r8w_5 (k) &R8W_05;
array r8w_6 (k) &R8W_06;

array r7w_1 (k) &R7W_01;
array r7w_2 (k) &R7W_02;
array r7w_3 (k) &R7W_03;
array r7w_4 (k) &R7W_04;
array r7w_5 (k) &R7W_05;
array r7w_6 (k) &R7W_06;

array r6w_1 (k) &R6W_01;
array r6w_2 (k) &R6W_02;
array r6w_3 (k) &R6W_03;
array r6w_4 (k) &R6W_04;
array r6w_5 (k) &R6W_05;
array r6w_6 (k) &R6W_06;

array r5w_1 (k) &R5W_01;
array r5w_2 (k) &R5W_02;
array r5w_3 (k) &R5W_03;
array r5w_4 (k) &R5W_04;
array r5w_5 (k) &R5W_05;
array r5w_6 (k) &R5W_06;

array r4w_1 (k) &R4W_01;
array r4w_2 (k) &R4W_02;
array r4w_3 (k) &R4W_03;
array r4w_4 (k) &R4W_04;
array r4w_5 (k) &R4W_05;
array r4w_6 (k) &R4W_06;

array r3w_1 (k) &R3W_01;
array r3w_2 (k) &R3W_02;
array r3w_3 (k) &R3W_03;
array r3w_4 (k) &R3W_04;
array r3w_5 (k) &R3W_05;
array r3w_6 (k) &R3W_06;

array r2w_1 (k) &R2W_01;
array r2w_2 (k) &R2W_02;
array r2w_3 (k) &R2W_03;
array r2w_4 (k) &R2W_04;
array r2w_5 (k) &R2W_05;
array r2w_6 (k) &R2W_06;

array r1w_1 (k) &R1W_01;
array r1w_2 (k) &R1W_02;
array r1w_3 (k) &R1W_03;
array r1w_4 (k) &R1W_04;
array r1w_5 (k) &R1W_05;
array r1w_6 (k) &R1W_06;

array r9wks {27,9}
r9w80_1-r9w80_9 r9w81_1-r9w81_9 r9w82_1-r9w82_9 r9w83_1-r9w83_9 r9w84_1-r9w84_9
r9w85_1-r9w85_9 r9w86_1-r9w86_9 r9w87_1-r9w87_9 r9w88_1-r9w88_9 r9w89_1-r9w89_9
r9w90_1-r9w90_9 r9w91_1-r9w91_9 r9w92_1-r9w92_9 r9w93_1-r9w93_9 r9w94_1-r9w94_9
r9w95_1-r9w95_9 r9w96_1-r9w96_9 r9w97_1-r9w97_9 r9w98_1-r9w98_9 r9w99_1-r9w99_9
r9w00_1-r9w00_9 r9w01_1-r9w01_9 r9w02_1-r9w02_9 r9w03_1-r9w03_9 r9w04_1-r9w04_9
r9w05_1-r9w05_9 r9w06_1-r9w06_9;

do j=1 to 9; do k=1 to 27;
if r9wks(k,j)>0 and match1=8 and r8w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=8 and r8w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=8 and r8w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=8 and r8w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=8 and r8w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=8 and r8w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=7 and r7w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=7 and r7w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=7 and r7w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=7 and r7w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=7 and r7w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=7 and r7w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=6 and r6w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=6 and r6w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=6 and r6w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=6 and r6w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=6 and r6w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=6 and r6w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=5 and r5w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=5 and r5w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=5 and r5w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=5 and r5w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=5 and r5w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=5 and r5w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=4 and r4w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=4 and r4w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=4 and r4w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=4 and r4w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=4 and r4w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=4 and r4w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=3 and r3w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=3 and r3w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=3 and r3w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=3 and r3w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=3 and r3w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=3 and r3w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=2 and r2w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=2 and r2w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=2 and r2w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=2 and r2w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=2 and r2w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=2 and r2w_6>0 then same=same+1;

if r9wks(k,j)>0 and match1=1 and r1w_1>0 then same=same+1;
if r9wks(k,j)>0 and match2=1 and r1w_2>0 then same=same+1;
if r9wks(k,j)>0 and match3=1 and r1w_3>0 then same=same+1;
if r9wks(k,j)>0 and match4=1 and r1w_4>0 then same=same+1;
if r9wks(k,j)>0 and match5=1 and r1w_5>0 then same=same+1;
if r9wks(k,j)>0 and match6=1 and r1w_6>0 then same=same+1;

if r9wks(k,j)>0 and self=1 and match1=8 and r8w_1>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match2=8 and r8w_2>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match3=8 and r8w_3>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match4=8 and r8w_4>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match5=8 and r8w_5>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match6=8 and r8w_6>0 then ssame=ssame+1;

if r9wks(k,j)>0 and self=1 and match1=7 and r7w_1>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match2=7 and r7w_2>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match3=7 and r7w_3>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match4=7 and r7w_4>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match5=7 and r7w_5>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match6=7 and r7w_6>0 then ssame=ssame+1;

if r9wks(k,j)>0 and self=1 and match1=6 and r6w_1>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match2=6 and r6w_2>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match3=6 and r6w_3>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match4=6 and r6w_4>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match5=6 and r6w_5>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match6=6 and r6w_6>0 then ssame=ssame+1;

if r9wks(k,j)>0 and self=1 and match1=5 and r5w_1>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match2=5 and r5w_2>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match3=5 and r5w_3>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match4=5 and r5w_4>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match5=5 and r5w_5>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match6=5 and r5w_6>0 then ssame=ssame+1;

if r9wks(k,j)>0 and self=1 and match1=4 and r4w_1>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match2=4 and r4w_2>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match3=4 and r4w_3>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match4=4 and r4w_4>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match5=4 and r4w_5>0 then ssame=ssame+1;
if r9wks(k,j)>0 and self=1 and match6=4 and r4w_6>0 then ssame=ssame+1;
end;
end;

do k=1 to 27;
if tjob>0 then tjob=tjob-same;
if tsjob>0 then tsjob=tsjob-ssame;
if tejob>0 then tejob=tejob-(same-ssame);
end;
run;

data total_numjobs14; merge one round9.emp_bday round9.emp_int round9.emp_week
total_numwksyr(keep=idcode match1_1 -- match6_9) round9.emp37_numjobs14
round9.prior_jobs14;
by idcode;
if r9int ne -5;

/* This program calculates the total number of jobs between age 14 and 19 and since age 20. The created variables are:
CV_TTL_JOB_TEEN
CV_TTL_JOB_ADULT_ALL
CV_TTL_JOB_ADULT_ET */

/*rename variables from prior rounds*/
r8emp14=S3823900; r8emp20=S3824000; r8job20=S3824100;
r7emp14=S2023000; r7emp20=S2023100; r7job20=S2023200;
r6emp14=S1553400; r6emp20=S1553500; r6job20=S1553600;
r5emp14=R7238100; r5emp20=R7238200; r5job20=R7238300;
r4emp14=R5474400; r4emp20=R5474500; r4job20=R5474600;
r3emp14=R3892400; r3emp20=r3job20;
r2emp14=R2570400;

totemp14=0;
if age20wk<r9int then totjob20=0;
if age20wk<r9int then totemp20=0;

if r9emp14 ne . then totemp14=totemp14+r9emp14;
if r9job20 ne . then totjob20=totjob20+r9job20;
if r9emp20 ne . then totemp20=totemp20+r9emp20;

/* Begin by adding together the created variables from both rounds. Jobs that are double counted will be subtracted off
later in the program. */
if dliwk=r8int and totemp14 ge 0 then do;
if r8emp14>0 then totemp14=totemp14+r8emp14;
if r8emp14=-3 then totemp14=-3;
end;
if dliwk=r7int and totemp14 ge 0 then do;
if r7emp14>0 then totemp14=totemp14+r7emp14;
if r7emp14=-3 then totemp14=-3;
end;
if dliwk=r6int and totemp14 ge 0 then do;
if r6emp14>0 then totemp14=totemp14+r6emp14;
if r6emp14=-3 then totemp14=-3;
end;
if dliwk=r5int and totemp14 ge 0 then do;
if r5emp14>0 then totemp14=totemp14+r5emp14;
if r5emp14=-3 then totemp14=-3;
end;
if dliwk=r4int and totemp14 ge 0 then do;
if r4emp14>0 then totemp14=totemp14+r4emp14;
if r4emp14=-3 then totemp14=-3;
end;
if dliwk=r3int and totemp14 ge 0 then do;
if r3emp14>0 then totemp14=totemp14+r3emp14;
if r3emp14=-3 then totemp14=-3;
end;
if dliwk=r2int and totemp14 ge 0 then do;
if r2emp14>0 then totemp14=totemp14+r2emp14;
if r2emp14=-3 then totemp14=-3;
end;

if dliwk=r8int and totemp20 ge 0 then do;
if r8emp20>0 then totemp20=totemp20+r8emp20;
if r8emp20=-3 then totemp20=-3;
end;
if dliwk=r7int and totemp20 ge 0 then do;
if r7emp20>0 then totemp20=totemp20+r7emp20;
if r7emp20=-3 then totemp20=-3;
end;
if dliwk=r6int and totemp20 ge 0 then do;
if r6emp20>0 then totemp20=totemp20+r6emp20;
if r6emp20=-3 then totemp20=-3;
end;
if dliwk=r5int and totemp20 ge 0 then do;
if r5emp20>0 then totemp20=totemp20+r5emp20;
if r5emp20=-3 then totemp20=-3;
end;
if dliwk=r4int and totemp20 ge 0 then do;
if r4emp20>0 then totemp20=totemp20+r4emp20;
if r4emp20=-3 then totemp20=-3;
end;
if dliwk=r3int and totemp20 ge 0 then do;
if r3emp20>0 then totemp20=totemp20+r3emp20;
if r3emp20=-3 then totemp20=-3;
end;

if dliwk=r8int and totjob20 ge 0 then do;
if r8job20>0 then totjob20=totjob20+r8job20;
if r8job20=-3 then totjob20=-3;
end;
if dliwk=r7int and totjob20 ge 0 then do;
if r7job20>0 then totjob20=totjob20+r7job20;
if r7job20=-3 then totjob20=-3;
end;
if dliwk=r6int and totjob20 ge 0 then do;
if r6job20>0 then totjob20=totjob20+r6job20;
if r6job20=-3 then totjob20=-3;
end;
if dliwk=r5int and totjob20 ge 0 then do;
if r5job20>0 then totjob20=totjob20+r5job20;
if r5job20=-3 then totjob20=-3;
end;
if dliwk=r4int and totjob20 ge 0 then do;
if r4job20>0 then totjob20=totjob20+r4job20;
if r4job20=-3 then totjob20=-3;
end;
if dliwk=r3int and totjob20 ge 0 then do;
if r3job20>0 then totjob20=totjob20+r3job20;
if r3job20=-3 then totjob20=-3;
end;

array match1 (j) match1_1-match1_9;
array match2 (j) match2_1-match2_9;
array match3 (j) match3_1-match3_9;
array match4 (j) match4_1-match4_9;
array match5 (j) match5_1-match5_9;
array match6 (j) match6_1-match6_9;

array emp14 (j) r9e1401-r9e1409;
array job20 (j) r9j2001-r9j2009;
array emp20 (j) r9e2001-r9e2009;

same14=0;
same20=0;
esame20=0;

do j=1 to 9;
if match1=8 and emp14>0 and r8j1401>0 then same14=same14+1;
if match2=8 and emp14>0 and r8j1402>0 then same14=same14+1;
if match3=8 and emp14>0 and r8j1403>0 then same14=same14+1;
if match4=8 and emp14>0 and r8j1404>0 then same14=same14+1;
if match5=8 and emp14>0 and r8j1405>0 then same14=same14+1;
if match6=8 and emp14>0 and r8j1406>0 then same14=same14+1;

if match1=8 and emp20>0 and r8j2001>0 then esame20=esame20+1;
if match2=8 and emp20>0 and r8j2002>0 then esame20=esame20+1;
if match3=8 and emp20>0 and r8j2003>0 then esame20=esame20+1;
if match4=8 and emp20>0 and r8j2004>0 then esame20=esame20+1;
if match5=8 and emp20>0 and r8j2005>0 then esame20=esame20+1;
if match6=8 and emp20>0 and r8j2006>0 then esame20=esame20+1;

if match1=8 and job20>0 and r8j2001>0 then same20=same20+1;
if match2=8 and job20>0 and r8j2002>0 then same20=same20+1;
if match3=8 and job20>0 and r8j2003>0 then same20=same20+1;
if match4=8 and job20>0 and r8j2004>0 then same20=same20+1;
if match5=8 and job20>0 and r8j2005>0 then same20=same20+1;
if match6=8 and job20>0 and r8j2006>0 then same20=same20+1;

if match1=7 and emp14>0 and r7j141>0 then same14=same14+1;
if match2=7 and emp14>0 and r7j142>0 then same14=same14+1;
if match3=7 and emp14>0 and r7j143>0 then same14=same14+1;
if match4=7 and emp14>0 and r7j144>0 then same14=same14+1;
if match5=7 and emp14>0 and r7j145>0 then same14=same14+1;
if match6=7 and emp14>0 and r7j146>0 then same14=same14+1;

if match1=7 and emp20>0 and r7j201>0 then esame20=esame20+1;
if match2=7 and emp20>0 and r7j202>0 then esame20=esame20+1;
if match3=7 and emp20>0 and r7j203>0 then esame20=esame20+1;
if match4=7 and emp20>0 and r7j204>0 then esame20=esame20+1;
if match5=7 and emp20>0 and r7j205>0 then esame20=esame20+1;
if match6=7 and emp20>0 and r7j206>0 then esame20=esame20+1;

if match1=7 and job20>0 and r7j201>0 then same20=same20+1;
if match2=7 and job20>0 and r7j202>0 then same20=same20+1;
if match3=7 and job20>0 and r7j203>0 then same20=same20+1;
if match4=7 and job20>0 and r7j204>0 then same20=same20+1;
if match5=7 and job20>0 and r7j205>0 then same20=same20+1;
if match6=7 and job20>0 and r7j206>0 then same20=same20+1;

if match1=6 and emp14>0 and r6j141>0 then same14=same14+1;
if match2=6 and emp14>0 and r6j142>0 then same14=same14+1;
if match3=6 and emp14>0 and r6j143>0 then same14=same14+1;
if match4=6 and emp14>0 and r6j144>0 then same14=same14+1;
if match5=6 and emp14>0 and r6j145>0 then same14=same14+1;
if match6=6 and emp14>0 and r6j146>0 then same14=same14+1;

if match1=6 and emp20>0 and r6j201>0 then esame20=esame20+1;
if match2=6 and emp20>0 and r6j202>0 then esame20=esame20+1;
if match3=6 and emp20>0 and r6j203>0 then esame20=esame20+1;
if match4=6 and emp20>0 and r6j204>0 then esame20=esame20+1;
if match5=6 and emp20>0 and r6j205>0 then esame20=esame20+1;
if match6=6 and emp20>0 and r6j206>0 then esame20=esame20+1;

if match1=6 and job20>0 and r6j201>0 then same20=same20+1;
if match2=6 and job20>0 and r6j202>0 then same20=same20+1;
if match3=6 and job20>0 and r6j203>0 then same20=same20+1;
if match4=6 and job20>0 and r6j204>0 then same20=same20+1;
if match5=6 and job20>0 and r6j205>0 then same20=same20+1;
if match6=6 and job20>0 and r6j206>0 then same20=same20+1;

if match1=5 and emp14>0 and r5j141>0 then same14=same14+1;
if match2=5 and emp14>0 and r5j142>0 then same14=same14+1;
if match3=5 and emp14>0 and r5j143>0 then same14=same14+1;
if match4=5 and emp14>0 and r5j144>0 then same14=same14+1;
if match5=5 and emp14>0 and r5j145>0 then same14=same14+1;
if match6=5 and emp14>0 and r5j146>0 then same14=same14+1;

if match1=5 and emp20>0 and r5j201>0 then esame20=esame20+1;
if match2=5 and emp20>0 and r5j202>0 then esame20=esame20+1;
if match3=5 and emp20>0 and r5j203>0 then esame20=esame20+1;
if match4=5 and emp20>0 and r5j204>0 then esame20=esame20+1;
if match5=5 and emp20>0 and r5j205>0 then esame20=esame20+1;
if match6=5 and emp20>0 and r5j206>0 then esame20=esame20+1;

if match1=5 and job20>0 and r5j201>0 then same20=same20+1;
if match2=5 and job20>0 and r5j202>0 then same20=same20+1;
if match3=5 and job20>0 and r5j203>0 then same20=same20+1;
if match4=5 and job20>0 and r5j204>0 then same20=same20+1;
if match5=5 and job20>0 and r5j205>0 then same20=same20+1;
if match6=5 and job20>0 and r5j206>0 then same20=same20+1;

if match1=4 and emp14>0 and r4j141>0 then same14=same14+1;
if match2=4 and emp14>0 and r4j142>0 then same14=same14+1;
if match3=4 and emp14>0 and r4j143>0 then same14=same14+1;
if match4=4 and emp14>0 and r4j144>0 then same14=same14+1;
if match5=4 and emp14>0 and r4j145>0 then same14=same14+1;
if match6=4 and emp14>0 and r4j146>0 then same14=same14+1;

if match1=4 and emp20>0 and r4j201>0 then esame20=esame20+1;
if match2=4 and emp20>0 and r4j202>0 then esame20=esame20+1;
if match3=4 and emp20>0 and r4j203>0 then esame20=esame20+1;
if match4=4 and emp20>0 and r4j204>0 then esame20=esame20+1;
if match5=4 and emp20>0 and r4j205>0 then esame20=esame20+1;
if match6=4 and emp20>0 and r4j206>0 then esame20=esame20+1;

if match1=4 and job20>0 and r4j201>0 then same20=same20+1;
if match2=4 and job20>0 and r4j202>0 then same20=same20+1;
if match3=4 and job20>0 and r4j203>0 then same20=same20+1;
if match4=4 and job20>0 and r4j204>0 then same20=same20+1;
if match5=4 and job20>0 and r4j205>0 then same20=same20+1;
if match6=4 and job20>0 and r4j206>0 then same20=same20+1;

if match1=3 and emp14>0 and r3j141>0 then same14=same14+1;
if match2=3 and emp14>0 and r3j142>0 then same14=same14+1;
if match3=3 and emp14>0 and r3j143>0 then same14=same14+1;
if match4=3 and emp14>0 and r3j144>0 then same14=same14+1;
if match5=3 and emp14>0 and r3j145>0 then same14=same14+1;
if match6=3 and emp14>0 and r3j146>0 then same14=same14+1;

if match1=3 and emp20>0 and r3j201>0 then esame20=esame20+1;
if match2=3 and emp20>0 and r3j202>0 then esame20=esame20+1;
if match3=3 and emp20>0 and r3j203>0 then esame20=esame20+1;
if match4=3 and emp20>0 and r3j204>0 then esame20=esame20+1;
if match5=3 and emp20>0 and r3j205>0 then esame20=esame20+1;
if match6=3 and emp20>0 and r3j206>0 then esame20=esame20+1;

if match1=3 and job20>0 and r3j201>0 then same20=same20+1;
if match2=3 and job20>0 and r3j202>0 then same20=same20+1;
if match3=3 and job20>0 and r3j203>0 then same20=same20+1;
if match4=3 and job20>0 and r3j204>0 then same20=same20+1;
if match5=3 and job20>0 and r3j205>0 then same20=same20+1;
if match6=3 and job20>0 and r3j206>0 then same20=same20+1;
end;

if totemp14>0 then totemp14=totemp14-same14;
if totjob20>0 then totjob20=totjob20-same20;
if totemp20>0 then totemp20=totemp20-esame20;

run;
endsas;


Return to Appendix 2 main file