Return to Appendix 2 main file
**************************************************************
** Preliminary information, setting up arrays, etc. **
**************************************************************;
if birthmo=2
and birthdy=29 and birthyr in (1980,1984)
then do; birthmo=3; birthdy=1; end;
birthmdy=mdy(birthmo,birthdy,birthyr);
age14mdy=mdy(birthmo,birthdy,birthyr+14);
age18mdy=mdy(birthmo,birthdy,birthyr+18);
age20mdy=mdy(birthmo,birthdy,birthyr+20);
ag18jmdy=mdy(01,01,birthyr+18);
begmdy=mdy(01,01,1980);
birthwk=intck('week',begmdy,birthmdy)+1;
age14wk=intck('week',begmdy,age14mdy)+1;
age18wk=intck('week',begmdy,age18mdy)+1;
age20wk=intck('week',begmdy,age20mdy)+1;
ag18jan=intck('week',begmdy,ag18jmdy)+1;
if r1int_y in (1994,1995) then r1int_y=1997;
r1mdy=mdy(r1int_m,r1int_d,r1int_y);
if r2int_y in (1994,1997) then r2int_y=1998;
if r2int_y>0 then r2mdy=mdy(r2int_m,r2int_d,r2int_y);
if r3int_y>0 then r3mdy=mdy(r3int_m,r3int_d,r3int_y);
if r4int_y>0 then r4mdy=mdy(r4int_m,r4int_d,r4int_y);
if r5int_y>0 then r5mdy=mdy(r5int_m,r5int_d,r5int_y);
if r6int_y>0 then r6mdy=mdy(r6int_m,r6int_d,r6int_y);
if r7int_y>0 then r7mdy=mdy(r7int_m,r7int_d,r7int_y);
begmdy=mdy(01,01,1980);
r1int=intck('week',begmdy,r1mdy)+1;
r2int=intck('week',begmdy,r2mdy)+1; if r2int=. then r2int=-4;
r3int=intck('week',begmdy,r3mdy)+1; if r3int=. then r3int=-4;
r4int=intck('week',begmdy,r4mdy)+1; if r4int=. then r4int=-4;
r5int=intck('week',begmdy,r5mdy)+1; if r5int=. then r5int=-4;
r6int=intck('week',begmdy,r6mdy)+1; if r6int=. then r6int=-4;
r7int=intck('week',begmdy,r7mdy); if r7int=. then r7int=-5;
if PUBID=7315 then r1int=918;
/* ostartm represents the "old" start dates, used when start dates are updated to interview dates. */
array ostartm (i) ostarm01-ostarm10;
array ostartd (i) ostard01-ostard10;
array ostarty (i) ostary01-ostary10;
array ostopm (i) ostopm01-ostopm10;
array ostopd (i) ostopd01-ostopd10;
array ostopy (i) ostopy01-ostopy10;
array startm (i) starm01-starm10;
array startd (i) stard01-stard10;
array starty (i) stary01-stary10;
array stopm (i) stopm01-stopm10;
array stopd (i) stopd01-stopd10;
array stopy (i) stopy01-stopy10;
array UID (i) UID01-UID10;
array sttdays (i) sttday01-sttday10; /* total days in that year from startdate (to Jan 1) */
array stpdays (i) stpday01-stpday10; /* total days in that year from stopdate (to Jan 1) */
array startwk (i) starw01-starw10;
array stopwk (i) stopw01-stopw10;
array srflag (i) srflg01-srflg10;
array spflag (i) spflg01-spflg10;
array uflag (i) uflag01-uflag10; /* uflag=1 when job startdate is updated */
array smofl (i) smof01-smof10; /* dummy equals 1 when a start month is imputed */
array emofl (i) emof01-emof10; /* dummy equals 1 when a stop month is imputed */
array self (i) self01-self10;
/* Establish dli week*/
if r6int_y>0 then do;
dli_y=r6int_y;
dli_m=r6int_m;
dli_d=r6int_d;
dliwk=r6int;
r6dli=1;
end;
if r6int_y=-5 and r5int_y>0 then do;
dli_y=r5int_y;
dli_m=r5int_m;
dli_d=r5int_d;
dliwk=r5int;
r5dli=1;
end;
if r6int_y=-5 and r5int_y=-5 and r4int_y>0 then do;
dli_y=r4int_y;
dli_m=r4int_m;
dli_d=r4int_d;
dliwk=r4int;
r4dli=1;
end;
if r6int_y=-5 and r5int_y=-5 and r4int_y=-5 and r3int_y>0 then do;
dli_y=r3int_y;
dli_m=r3int_m;
dli_d=r3int_d;
dliwk=r3int;
r3dli=1;
end;
if r6int_y=-5 and r5int_y=-5 and r4int_y=-5 and r3int_y=-5 and r2int_y>0 then do;
dli_y=r2int_y;
dli_m=r2int_m;
dli_d=r2int_d;
dliwk=r2int;
r2dli=1;
end;
if r6int_y=-5 and r5int_y=-5 and r4int_y=-5 and r3int_y=-5 and r2int_y=-5 and r1int_y>0 then do;
dli_y=r1int_y;
dli_m=r1int_m;
dli_d=r1int_d;
dliwk=r1int;
r1dli=1;
end;
/* Initialize smofl and emofl */
do i=1 to 10;
smofl=0; emofl=0;
end;
/* Define old start and stop dates */
do i=1 to 10;
ostartm=startm;
ostartd=startd;
ostarty=starty;
ostopm=stopm;
ostopd=stopd;
ostopy=stopy;
end;
***Fill-in start/stop day for those missing;
/* flag1 = impute start day (valid month)
flag2 = impute start month (valid day)
flag3 = impute start day and month
flag4 = impute stop day (valid month)
flag5 = impute stop month (valid day)
flag6 = impute stop day and month */
array flag1 (i) flag101-flag110;
array flag2 (i) flag201-flag210;
array flag3 (i) flag301-flag310;
array flag4 (i) flag401-flag410;
array flag5 (i) flag501-flag510;
array flag6 (i) flag601-flag610;
do i=1 to 10;
flag1=-4;
flag2=-4;
flag3=-4;
flag4=-4;
flag5=-4;
flag6=-4;
end;
/* Impute missing start days to 1, missing stop days to 28, missing start month to 1 (Jan.) and missing stop months to 12 (Dec.). */
/* Reset flag(1-3) to zero when the start year is valid */
do over starty;
if starty>0 then do;
flag1=0; flag2=0; flag3=0;
if startm>0 and startd<=0 then do;
startd=1;
flag1=1;
srflag=1;
end;
if startm<=0 and startd>0 then do;
startm=1;
flag2=1;
srflag=1;
smofl=1;
end;
if startm<=0 and startd<=0 then do;
startm=1;
startd=1;
flag3=1;
srflag=1;
smofl=1;
end;
end;
end;
do over stopy;
if stopy>0 then do;
flag4=0; flag5=0; flag6=0;
if stopm>0 and stopd<=0 then do;
stopd=28;
flag4=1;
spflag=1;
end;
if stopm<=0 and stopd>0 then do;
stopm=12;
flag5=1;
spflag=1;
emofl=1;
end;
if stopm<=0 and stopd<=0 then do;
stopm=12;
stopd=28;
flag6=1;
spflag=1;
emofl=1;
end;
/* The following lines prevent imputed values for stop months and days to exceed the Round 7 interview date. */
if stopy=r7int_y and stopm=r7int_m and stopd>r7int_d and spflag=1 then do;
stopd=r7int_d;
end;
if stopy=r7int_y and stopm>r7int_m then do;
stopm=r7int_m;
stopd=r7int_d;
end;
end;
end;
/* The following lines of code account for the cases where the respondent has a start date for a job reported in an
earlier round that comes before the dli. The idea is to only count the weeks employed from dli to
today. Then, the activity from previous rounds will be added to the current Round activity to get
the full history. To
achieve this, all jobs reported in earlier rounds (UID's begin with 97,98,1999,2000,2001 or 2002)
will have their startdates
updated to the dli interview date. The start week and stop week for these jobs will be counted the same. */
do i=1 to 10;
uflag=0; /* Initialize uflag */
if -5<uid<200300 and startd>-4 then do;
if starty=dli_y and startm=dli_m and startd<dli_d and starty>0 then do;
startd=dli_d;
uflag=1;
end;
if starty=dli_y and startm<dli_m and starty>0 then do;
startm=dli_m;
startd=dli_d;
uflag=1;
end;
if starty<dli_y and starty>0 then do;
starty=dli_y;
startm=dli_m;
startd=dli_d;
uflag=1;
end;
end;
end;
***Convert START month and day to total days;
do over startm;
if startm>0 and startd>0 then do;
if startm=1 then sttdays=startd;
if startm=2 then sttdays=startd+31;
if startm=3 then sttdays=startd+59;
if startm=4 then sttdays=startd+90;
if startm=5 then sttdays=startd+120;
if startm=6 then sttdays=startd+151;
if startm=7 then sttdays=startd+181;
if startm=8 then sttdays=startd+212;
if startm=9 then sttdays=startd+243;
if startm=10 then sttdays=startd+273;
if startm=11 then sttdays=startd+304;
if startm=12 then sttdays=startd+334;
end;
end;
***Account for leap years;
do over starty;
if starty=1980 or starty=1984 or starty=1988 or starty=1992 or starty=1996 or starty=2000 or
starty=2004 then do;
if startm>0 and startd>0 then do;
if startm=1 then sttdays=startd;
if startm=2 then sttdays=startd+31;
if startm=3 then sttdays=startd+60;
if startm=4 then sttdays=startd+91;
if startm=5 then sttdays=startd+121;
if startm=6 then sttdays=startd+152;
if startm=7 then sttdays=startd+182;
if startm=8 then sttdays=startd+213;
if startm=9 then sttdays=startd+244;
if startm=10 then sttdays=startd+274;
if startm=11 then sttdays=startd+305;
if startm=12 then sttdays=startd+335;
end;
end;
end;
***Convert STOP month and day to total days;
do over stopm;
if stopm>0 and stopd>0 then do;
if stopm=1 then stpdays=stopd;
if stopm=2 then stpdays=stopd+31;
if stopm=3 then stpdays=stopd+59;
if stopm=4 then stpdays=stopd+90;
if stopm=5 then stpdays=stopd+120;
if stopm=6 then stpdays=stopd+151;
if stopm=7 then stpdays=stopd+181;
if stopm=8 then stpdays=stopd+212;
if stopm=9 then stpdays=stopd+243;
if stopm=10 then stpdays=stopd+273;
if stopm=11 then stpdays=stopd+304;
if stopm=12 then stpdays=stopd+334;
end;
end;
***Account for leap years;
do over stopy;
if stopy=1980 or stopy=1984 or stopy=1988 or stopy=1992 or stopy=1996 or stopy=2000 or
stopy=2004 then do;
if stopm>0 and stopd>0 then do;
if stopm=1 then stpdays=stopd;
if stopm=2 then stpdays=stopd+31;
if stopm=3 then stpdays=stopd+60;
if stopm=4 then stpdays=stopd+91;
if stopm=5 then stpdays=stopd+121;
if stopm=6 then stpdays=stopd+152;
if stopm=7 then stpdays=stopd+182;
if stopm=8 then stpdays=stopd+213;
if stopm=9 then stpdays=stopd+244;
if stopm=10 then stpdays=stopd+274;
if stopm=11 then stpdays=stopd+305;
if stopm=12 then stpdays=stopd+335;
end;
end;
end;
***Convert days into week numbers;
***************************************************************************************
** Basic Formula: **
** weekno=endweek{specific year}+ceil[(totdays+{# of days remaining in DEC})/7] **
*************************************************************************************** ;
/* Create year flag variable */
array byear (i) byear01-byear10;
array eyear (i) eyear01-eyear10;
do over starty;
if starty>0 and sttdays>0 then do;
if starty=1980 then do;
startwk=ceil((sttdays+2)/7);
end;
if starty=1981 then do;
startwk=52+ceil((sttdays+4)/7);
end;
if starty=1982 then do;
startwk=104+ceil((sttdays+5)/7);
end;
if starty=1983 then do;
startwk=156+ceil((sttdays+6)/7);
end;
if starty=1984 then do;
startwk=209+ceil((sttdays)/7);
end;
if starty=1985 then do;
startwk=261+ceil((sttdays+2)/7);
end;
if starty=1986 then do;
startwk=313+ceil((sttdays+3)/7);
end;
if starty=1987 then do;
startwk=365+ceil((sttdays+4)/7);
end;
if starty=1988 then do;
startwk=417+ceil((sttdays+5)/7);
end;
if starty=1989 then do;
startwk=470+ceil((sttdays)/7);
end;
if starty=1990 then do;
startwk=522+ceil((sttdays+1)/7);
end;
if starty=1991 then do;
startwk=574+ceil((sttdays+2)/7);
end;
if starty=1992 then do;
startwk=626+ceil((sttdays+3)/7);
end;
if starty=1993 then do;
startwk=678+ceil((sttdays+5)/7);
end;
if starty=1994 then do;
startwk=730+ceil((sttdays+6)/7);
end;
if starty=1995 then do;
startwk=783+ceil((sttdays)/7);
end;
if starty=1996 then do;
startwk=835+ceil((sttdays+1)/7);
end;
if starty=1997 then do;
startwk=887+ceil((sttdays+3)/7);
end;
if starty=1998 then do;
startwk=939+ceil((sttdays+4)/7);
end;
if starty=1999 then do;
startwk=991+ceil((sttdays+5)/7);
end;
if starty=2000 then do;
startwk=1043+ceil((sttdays+6)/7);
end;
if starty=2001 then do;
startwk=1096+ceil((sttdays+1)/7);
end;
if starty=2002 then do;
startwk=1148+ceil((sttdays+2)/7);
end;
if starty=2003 then do;
startwk=1200+ceil((sttdays+3)/7);
end;
if starty=2004 then do;
startwk=1252+ceil((sttdays+4)/7);
end;
end;
if starty<0 and starty>-4 then do;
startwk=-3;
end;
if -4<ostarty<0 then byear=1;
end;
do over stopy;
if stopy>0 and stpdays>0 then do;
if stopy=1980 then do;
stopwk=ceil((stpdays+2)/7);
end;
if stopy=1981 then do;
stopwk=52+ceil((stpdays+4)/7);
end;
if stopy=1982 then do;
stopwk=104+ceil((stpdays+5)/7);
end;
if stopy=1983 then do;
stopwk=156+ceil((stpdays+6)/7);
end;
if stopy=1984 then do;
stopwk=209+ceil((stpdays)/7);
end;
if stopy=1985 then do;
stopwk=261+ceil((stpdays+2)/7);
end;
if stopy=1986 then do;
stopwk=313+ceil((stpdays+3)/7);
end;
if stopy=1987 then do;
stopwk=365+ceil((stpdays+4)/7);
end;
if stopy=1988 then do;
stopwk=417+ceil((stpdays+5)/7);
end;
if stopy=1989 then do;
stopwk=470+ceil((stpdays)/7);
end;
if stopy=1990 then do;
stopwk=522+ceil((stpdays+1)/7);
end;
if stopy=1991 then do;
stopwk=574+ceil((stpdays+2)/7);
end;
if stopy=1992 then do;
stopwk=626+ceil((stpdays+3)/7);
end;
if stopy=1993 then do;
stopwk=678+ceil((stpdays+5)/7);
end;
if stopy=1994 then do;
stopwk=730+ceil((stpdays+6)/7);
end;
if stopy=1995 then do;
stopwk=783+ceil((stpdays)/7);
end;
if stopy=1996 then do;
stopwk=835+ceil((stpdays+1)/7);
end;
if stopy=1997 then do;
stopwk=887+ceil((stpdays+3)/7);
end;
if stopy=1998 then do;
stopwk=939+ceil((stpdays+4)/7);
end;
if stopy=1999 then do;
stopwk=991+ceil((stpdays+5)/7);
end;
if stopy=2000 then do;
stopwk=1043+ceil((stpdays+6)/7);
end;
if stopy=2001 then do;
stopwk=1096+ceil((stpdays+1)/7);
end;
if stopy=2002 then do;
stopwk=1148+ceil((stpdays+2)/7);
end;
if stopy=2003 then do;
stopwk=1200+ceil((stpdays+3)/7);
end;
if stopy=2004 then do;
stopwk=1252+ceil((stpdays+4)/7);
end;
end;
if stopy<0 and stopy>-4 then do;
stopwk=-3;
end;
if -4<ostopy<0 then eyear=1;
end;
/* To create a seamless list of information from dli Round to current Round, the following lines of code are included. By
decreasing the current Round interview date by one (which was done in /emp_prep/emp_interview.sas), jobs that are worked up to the
interview date are also decreased by one. This is done so that the current Round interview week will not be counted twice
for respondents with a job during that time. The same procedure is used in the previous rounds. */
do over stopwk;
if stopwk>0 and UID>0 then do;
if stopwk>r7int then do;
stopwk=r7int;
end;
end;
end;
/* The following lines considers jobs that begin the same week as the current Round interview date. Since we are updating
the current Round interview week by -1, we need to account for jobs that start in the same week or tenures of -1 will
result. */
do over startwk;
if startwk>0 and UID>0 then do;
if startwk>r7int then do;
startwk=r7int;
end;
end;
end;
/* The job start date will be cut off at the week of Jan.1 of the respondent's 18th birthday for self-employed
jobs. This is done so every starts the self-employed jobs at the same point. The 18th birthday week was not chosen because
too many jobs were completely eliminated using the actual 18th birthday. This method cuts off 2 jobs entirely
(both the start and stop week are before Jan. 1 of the 18th birthday), and shortens 26 other jobs. */
array bself (i) bself01-bself10;
array eself (i) eself01-eself10;
do over startwk;
if self=1 and 0<startwk<=(ag18jan-1) then do;
bself=1;
end;
if self=1 and 0<startwk<=(ag18jan-1) and 0<stopwk<=(ag18jan-1) then do;
eself=1;
end;
end;
do over startwk;
if bself=1 then do;
startwk=ag18jan;
end;
if eself=1 then do;
startwk=.;
stopwk=.;
end;
end;
/* To account for non-interview cases */
if starm01=-5 then do;
do over startwk;
startwk=-5;
stopwk=-5;
end;
end;
/* Correcting for imputed values that resulted in the start date being later than the stop date. In these cases, the imputed
date will be updated to the good date. */
do i=1 to 10;
if startwk>stopwk and (flag1=1 or flag2=1 or flag3=1) then do;
startwk=stopwk;
end;
if startwk>stopwk and (flag4=1 or flag5=1 or flag6=1) then do;
stopwk=startwk;
end;
end;
/* Check for back-reporters, i.e. people that report a new job (UID>200200) that begins before the last interview date. */
do over UID;
if startwk<r6int and startwk>0 and r6int>0 then do;
back6=1;
end;
if startwk<r5int and startwk>0 and r6int=-4 and r5int>0 then do;
back5=1;
end;
if startwk<r4int and startwk>0 and r6int=-4 and r5int=-4 and r4int>0 then do;
back4=1;
end;
if startwk<r3int and startwk>0 and r6int=-4 and r5int=-4 and r4int=-4 and r3int>0 then do;
back3=1;
end;
if startwk<r2int and startwk>0 and r6int=-4 and r5int=-4 and r4int=-4 and r3int=-4 and r2int>0 then do;
back2=1;
end;
if startwk<r1int and startwk>0 and r6int=-4 and r5int=-4 and r4int=-4 and r3int=-4 and r2int=-4 and r1int>0 then do;
back1=1;
end;
end;
array br (i) br01-br10;
do over UID;
if startwk<dliwk and startwk>0 and dliwk>0 then do;
back=1;
br=1;
end;
end;
array uuflag (i) uuflag01-uuflag10;
do i=1 to 10;
if startwk>0 and stopwk>0 and startwk>stopwk and uflag=1 then do;
uuflag=1;
stopwk=startwk;
end;
end;
array sbgdy (i) sBGDY1_1-sBGDY1_2;
array sbgmo (i) sBGMO1_1-sBGMO1_2;
array sbgyr (i) sBGYR1_1-sBGYR1_2;
array segdy (i) sEGDY1_1-sEGDY1_2;
array segmo (i) sEGMO1_1-sEGMO1_2;
array segyr (i) sEGYR1_1-sEGYR1_2;
array bgdy (i) BGDY1_01-BGDY1_10;
array bgmo (i) BGMO1_01-BGMO1_10;
array bgyr (i) BGYR1_01-BGYR1_10;
array egdy (i) EGDY1_01-EGDY1_10;
array egmo (i) EGMO1_01-EGMO1_10;
array egyr (i) EGYR1_01-EGYR1_10;
array bdays (i) bday1_01-bday1_10;
array edays (i) eday1_01-eday1_10;
array bweek (i) bgap1_01-bgap1_10;
array eweek (i) egap1_01-egap1_10;
array bflag (i) bflg1_01-bflg1_10;
array eflag (i) eflg1_01-eflg1_10;
array bgfl (i) bgfl1_01-bgfl1_10;
array egfl (i) egfl1_01-egfl1_10;
/* use the self-employed gap information if it is a self-employed job. */
if self01=1 then do;
gap01=sgap01;
numgap1=snumgap1;
do i=1 to 2;
bgdy = sbgdy;
bgmo = sbgmo;
bgyr = sbgyr;
egdy = segdy;
egmo = segmo;
egyr = segyr;
end;
do i=3 to 10;
bgdy = -4;
bgmo = -4;
bgyr = -4;
egdy = -4;
egmo = -4;
egyr = -4;
end;
end;
/* Missing gap days (start and stop) are now imputed to 1.
Impute start/stop dates if only day is missing.
*/
do over bgyr;
if bgyr>0 then do;
if bgmo>0 and bgdy<=0 then do;
bgdy=1;
bflag=1;
end;
if bgyr=stary01 and bgmo=starm01 and bgdy<stard01 and bflag=1 then bgdy=stard01;
end;
end;
do over egyr;
if egyr>0 then do;
if egmo>0 and egdy<=0 then do;
egdy=1;
eflag=1;
end;
if egyr=stopy01 and egmo=stopm01 and egdy>stopd01 and eflag=1 then egdy=stopd01;
end;
end;
/*Set flag for gap that exists but has invalid dates*/
do over bgyr;
bgfl=-4;
if (-4 < bgmo < 0) or (-4 < bgyr <0) then bgfl=1;
end;
do over egyr;
egfl=-4;
if (-4 < egyr < 0) or (-4 < egmo < 0) then egfl=1;
end;
***Convert START month and day to total days (BDAYS);
do over bgmo;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+59;
if bgmo=4 then bdays=bgdy+90;
if bgmo=5 then bdays=bgdy+120;
if bgmo=6 then bdays=bgdy+151;
if bgmo=7 then bdays=bgdy+181;
if bgmo=8 then bdays=bgdy+212;
if bgmo=9 then bdays=bgdy+243;
if bgmo=10 then bdays=bgdy+273;
if bgmo=11 then bdays=bgdy+304;
if bgmo=12 then bdays=bgdy+334;
end;
end;
***Account for leap years;
do over bgyr;
if bgyr=1980 or bgyr=1984 or bgyr=1988 or bgyr=1992 or bgyr=1996 or bgyr=2000 or bgyr=2004 then do;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+60;
if bgmo=4 then bdays=bgdy+91;
if bgmo=5 then bdays=bgdy+121;
if bgmo=6 then bdays=bgdy+152;
if bgmo=7 then bdays=bgdy+182;
if bgmo=8 then bdays=bgdy+213;
if bgmo=9 then bdays=bgdy+244;
if bgmo=10 then bdays=bgdy+274;
if bgmo=11 then bdays=bgdy+305;
if bgmo=12 then bdays=bgdy+335;
end;
end;
end;
***Convert STOP month and day to total days (EDAYS);
do over egmo;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+59;
if egmo=4 then edays=egdy+90;
if egmo=5 then edays=egdy+120;
if egmo=6 then edays=egdy+151;
if egmo=7 then edays=egdy+181;
if egmo=8 then edays=egdy+212;
if egmo=9 then edays=egdy+243;
if egmo=10 then edays=egdy+273;
if egmo=11 then edays=egdy+304;
if egmo=12 then edays=egdy+334;
end;
end;
***Account for leap years;
do over egyr;
if egyr=1980 or egyr=1984 or egyr=1988 or egyr=1992 or egyr=1996 or egyr=2000 or egyr=2004 then do;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+60;
if egmo=4 then edays=egdy+91;
if egmo=5 then edays=egdy+121;
if egmo=6 then edays=egdy+152;
if egmo=7 then edays=egdy+182;
if egmo=8 then edays=egdy+213;
if egmo=9 then edays=egdy+244;
if egmo=10 then edays=egdy+274;
if egmo=11 then edays=egdy+305;
if egmo=12 then edays=egdy+335;
end;
end;
end;
***Convert days into week numbers;
** Basic Formula: **
** weekno=endweek{specific year}+ceil[(totdays+{# of days remaining in DEC})/7] **
************************************************************************************ ***;
** Note: This program takes the week following the actual start of the gap **
** as the measure of when the non-working period begins. **
************************************************************************************ ***;
do over bgyr;
if bgyr>0 and bdays>0 then do;
if bgyr=1980 then do;
bweek=ceil((bdays+2)/7);
end;
if bgyr=1981 then do;
bweek=52+ceil((bdays+4)/7);
end;
if bgyr=1982 then do;
bweek=104+ceil((bdays+5)/7);
end;
if bgyr=1983 then do;
bweek=156+ceil((bdays+6)/7);
end;
if bgyr=1984 then do;
bweek=209+ceil((bdays)/7);
end;
if bgyr=1985 then do;
bweek=261+ceil((bdays+2)/7);
end;
if bgyr=1986 then do;
bweek=313+ceil((bdays+3)/7);
end;
if bgyr=1987 then do;
bweek=365+ceil((bdays+4)/7);
end;
if bgyr=1988 then do;
bweek=417+ceil((bdays+5)/7);
end;
if bgyr=1989 then do;
bweek=470+ceil((bdays)/7);
end;
if bgyr=1990 then do;
bweek=522+ceil((bdays+1)/7);
end;
if bgyr=1991 then do;
bweek=574+ceil((bdays+2)/7);
end;
if bgyr=1992 then do;
bweek=626+ceil((bdays+3)/7);
end;
if bgyr=1993 then do;
bweek=678+ceil((bdays+5)/7);
end;
if bgyr=1994 then do;
bweek=730+ceil((bdays+6)/7);
end;
if bgyr=1995 then do;
bweek=783+ceil((bdays)/7);
end;
if bgyr=1996 then do;
bweek=835+ceil((bdays+1)/7);
end;
if bgyr=1997 then do;
bweek=887+ceil((bdays+3)/7);
end;
if bgyr=1998 then do;
bweek=939+ceil((bdays+4)/7);
end;
if bgyr=1999 then do;
bweek=991+ceil((bdays+5)/7);
end;
if bgyr=2000 then do;
bweek=1043+ceil((bdays+6)/7);
end;
if bgyr=2001 then do;
bweek=1096+ceil((bdays+1)/7);
end;
if bgyr=2002 then do;
bweek=1148+ceil((bdays+2)/7);
end;
if bgyr=2003 then do;
bweek=1200+ceil((bdays+3)/7);
end;
if bgyr=2004 then do;
bweek=1252+ceil((bdays+4)/7);
end;
if bweek>0 then do;
bweek=bweek+1;
end;
end;
end;
do over egyr;
if egyr>0 and edays>0 then do;
if egyr=1980 then do;
eweek=ceil((edays+2)/7);
end;
if egyr=1981 then do;
eweek=52+ceil((edays+4)/7);
end;
if egyr=1982 then do;
eweek=104+ceil((edays+5)/7);
end;
if egyr=1983 then do;
eweek=156+ceil((edays+6)/7);
end;
if egyr=1984 then do;
eweek=209+ceil((edays)/7);
end;
if egyr=1985 then do;
eweek=261+ceil((edays+2)/7);
end;
if egyr=1986 then do;
eweek=313+ceil((edays+3)/7);
end;
if egyr=1987 then do;
eweek=365+ceil((edays+4)/7);
end;
if egyr=1988 then do;
eweek=417+ceil((edays+5)/7);
end;
if egyr=1989 then do;
eweek=470+ceil((edays)/7);
end;
if egyr=1990 then do;
eweek=522+ceil((edays+1)/7);
end;
if egyr=1991 then do;
eweek=574+ceil((edays+2)/7);
end;
if egyr=1992 then do;
eweek=626+ceil((edays+3)/7);
end;
if egyr=1993 then do;
eweek=678+ceil((edays+5)/7);
end;
if egyr=1994 then do;
eweek=730+ceil((edays+6)/7);
end;
if egyr=1995 then do;
eweek=783+ceil((edays)/7);
end;
if egyr=1996 then do;
eweek=835+ceil((edays+1)/7);
end;
if egyr=1997 then do;
eweek=887+ceil((edays+3)/7);
end;
if egyr=1998 then do;
eweek=939+ceil((edays+4)/7);
end;
if egyr=1999 then do;
eweek=991+ceil((edays+5)/7);
end;
if egyr=2000 then do;
eweek=1043+ceil((edays+6)/7);
end;
if egyr=2001 then do;
eweek=1096+ceil((edays+1)/7);
end;
if egyr=2002 then do;
eweek=1148+ceil((edays+2)/7);
end;
if egyr=2003 then do;
eweek=1200+ceil((edays+3)/7);
end;
if egyr=2004 then do;
eweek=1252+ceil((edays+4)/7);
end;
if eweek>0 then do;
eweek=eweek-1;
end;
end;
end;
/* The following lines omit gap start and stop dates for gaps less than one work week (5 days) */
do over bdays;
if edays-bdays<4 and bweek>=eweek and bdays ne . and edays ne . and bgyr=egyr then do;
bweek=.;
eweek=.;
end;
if -366 le edays-bdays le -363 and bweek>=eweek and bdays ne . and edays ne . then do;
bweek=.;
eweek=.;
end;
end;
/* For self-employed jobs, use the "age18jan" as the left-side-limit for gap dates. */
do over bweek;
if self01=1 and 0<bweek<=(ag18jan-1) then bweek=ag18jan;
if self01=1 and 0<bweek<=(ag18jan-1) and 0<eweek<=(ag18jan-1) then do;
bweek=.;
eweek=.;
end;
end;
/* The following lines are for end gap dates that exceed the interview date due to our rounding methods. */
do over eweek;
if 0<eweek<1400 and eweek>r7int then do;
eweek=r7int;
end;
end;
/* The following omits cases where bweek>eweek, which are caused when missing values are substituted in.
This can cause problems when writing programs for the created variables. This situation will be fixed by making
eweek and bweek the same. This is repeated (without comment) for each job. */
array update (i) updat1_1-updat1_10;
do over bweek;
if 0<eweek<1303 then do;
if bweek>eweek then do;
bweek=eweek;
update=1;
end;
end;
end;
/* The gap before dli week will be disregarded. */
do over bweek;
if UID01>0 and dliwk>0 and bweek>0 and eweek>0 then do;
if dliwk>bweek and dliwk>eweek then do;
bweek=.;
eweek=.;
end;
if dliwk<eweek and dliwk>bweek then do;
bweek=dliwk;
end;
end;
end;
/* The following erases gaps that occur after the job has ended, only in cases where there are no imputed job
start or stop months or years (imputed job start/stop days acceptable) */
do over bweek;
if starw01>0 and stopw01>0 and smof01=0 and emof01=0 then do;
if bweek>stopw01 then do;
bweek=.;
end;
if eweek>stopw01 then do;
eweek=.;
end;
end;
end;
/* To correct for bad gap information.*/
do over bdays;
if eweek>stopw01 and stopw01>0 then eweek=stopw01;
if bweek<starw01 and bweek>0 then do;
bweek=starw01;
if eweek<starw01 and eweek ne . then do;
eweek=bweek;
huh01=1;
end;
end;
if bweek>stopw01 and stopw01>0 then huh01=1;
if eweek<starw01 and eweek ne . and starw01>0 then huh01=1;
end;
* checked: there is no case with huh01=1;
*******************
** JOB 2 GAPS **
*******************;
data emp_gaps2; set emp_gaps1;
/* These variables are read as follows:
BGDY2_1 = Begin day of within-job gap 1 on job 2
EGMO2_6 = End month of within-job gap 6 on job 2
BGAP2_3 = Begin week of within-job gap 3 on job 2 [CREATED] */
array sbgdy (i) sBGDY2_1-sBGDY2_2;
array sbgmo (i) sBGMO2_1-sBGMO2_2;
array sbgyr (i) sBGYR2_1-sBGYR2_2;
array segdy (i) sEGDY2_1-sEGDY2_2;
array segmo (i) sEGMO2_1-sEGMO2_2;
array segyr (i) sEGYR2_1-sEGYR2_2;
array bgdy (i) BGDY2_01-BGDY2_03;
array bgmo (i) BGMO2_01-BGMO2_03;
array bgyr (i) BGYR2_01-BGYR2_03;
array egdy (i) EGDY2_01-EGDY2_03;
array egmo (i) EGMO2_01-EGMO2_03;
array egyr (i) EGYR2_01-EGYR2_03;
array bdays (i) bday2_01-bday2_03;
array edays (i) eday2_01-eday2_03;
array bweek (i) bgap2_01-bgap2_03;
array eweek (i) egap2_01-egap2_03;
array bflag (i) bflg2_01-bflg2_03;
array eflag (i) eflg2_01-eflg2_03;
array bgfl (i) bgfl2_01-bgfl2_03;
array egfl (i) egfl2_01-egfl2_03;
/* use the self-employed gap information if it is a self-employed job. */
if self02=1 then do;
gap02=sgap02;
numgap2=snumgap2;
do i=1 to 2;
bgdy = sbgdy;
bgmo = sbgmo;
bgyr = sbgyr;
egdy = segdy;
egmo = segmo;
egyr = segyr;
end;
do i=3;
bgdy = -4;
bgmo = -4;
bgyr = -4;
egdy = -4;
egmo = -4;
egyr = -4;
end;
end;
/* IMPUTE START/STOP DATES IF only DAY IS MISSING */
do over bgyr;
if bgyr>0 then do;
if bgmo>0 and bgdy<=0 then do;
bgdy=1;
bflag=1;
end;
if bgyr=stary02 and bgmo=starm02 and bgdy<stard02 and bflag=1 then bgdy=stard02;
end;
end;
do over egyr;
if egyr>0 then do;
if egmo>0 and egdy<=0 then do;
egdy=1;
eflag=1;
end;
if egyr=stopy02 and egmo=stopm02 and egdy>stopd02 and eflag=1 then egdy=stopd02;
end;
end;
***Set flag for gap exists but invalid data;
do over bgyr;
bgfl=-4;
if (-4 < bgmo < 0) or (-4 < bgyr < 0) then bgfl=1;
end;
do over egyr;
egfl=-4;
if (-4 < egyr < 0) or (-4 < egmo < 0) then egfl=1;
end;
***Convert START month and day to total days (BDAYS);
do over bgmo;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+59;
if bgmo=4 then bdays=bgdy+90;
if bgmo=5 then bdays=bgdy+120;
if bgmo=6 then bdays=bgdy+151;
if bgmo=7 then bdays=bgdy+181;
if bgmo=8 then bdays=bgdy+212;
if bgmo=9 then bdays=bgdy+243;
if bgmo=10 then bdays=bgdy+273;
if bgmo=11 then bdays=bgdy+304;
if bgmo=12 then bdays=bgdy+334;
end;
end;
***Account for leap years;
do over bgyr;
if bgyr=1980 or bgyr=1984 or bgyr=1988 or bgyr=1992 or bgyr=1996 or bgyr=2000 then do;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+60;
if bgmo=4 then bdays=bgdy+91;
if bgmo=5 then bdays=bgdy+121;
if bgmo=6 then bdays=bgdy+152;
if bgmo=7 then bdays=bgdy+182;
if bgmo=8 then bdays=bgdy+213;
if bgmo=9 then bdays=bgdy+244;
if bgmo=10 then bdays=bgdy+274;
if bgmo=11 then bdays=bgdy+305;
if bgmo=12 then bdays=bgdy+335;
end;
end;
end;
***Convert STOP month and day to total days (EDAYS);
do over egmo;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+59;
if egmo=4 then edays=egdy+90;
if egmo=5 then edays=egdy+120;
if egmo=6 then edays=egdy+151;
if egmo=7 then edays=egdy+181;
if egmo=8 then edays=egdy+212;
if egmo=9 then edays=egdy+243;
if egmo=10 then edays=egdy+273;
if egmo=11 then edays=egdy+304;
if egmo=12 then edays=egdy+334;
end;
end;
***Account for leap years;
do over egyr;
if egyr=1980 or egyr=1984 or egyr=1988 or egyr=1992 or egyr=1996 or egyr=2000 or egyr=2004 then do;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+60;
if egmo=4 then edays=egdy+91;
if egmo=5 then edays=egdy+121;
if egmo=6 then edays=egdy+152;
if egmo=7 then edays=egdy+182;
if egmo=8 then edays=egdy+213;
if egmo=9 then edays=egdy+244;
if egmo=10 then edays=egdy+274;
if egmo=11 then edays=egdy+305;
if egmo=12 then edays=egdy+335;
end;
end;
end;
***Convert days into week numbers;
** Basic Formula: **
** weekno=endweek{specific year}+ceil[(totdays+{# of days remaining in DEC})/7] **
do over bgyr;
if bgyr>0 and bdays>0 then do;
if bgyr=1980 then do;
bweek=ceil((bdays+2)/7);
end;
if bgyr=1981 then do;
bweek=52+ceil((bdays+4)/7);
end;
if bgyr=1982 then do;
bweek=104+ceil((bdays+5)/7);
end;
if bgyr=1983 then do;
bweek=156+ceil((bdays+6)/7);
end;
if bgyr=1984 then do;
bweek=209+ceil((bdays)/7);
end;
if bgyr=1985 then do;
bweek=261+ceil((bdays+2)/7);
end;
if bgyr=1986 then do;
bweek=313+ceil((bdays+3)/7);
end;
if bgyr=1987 then do;
bweek=365+ceil((bdays+4)/7);
end;
if bgyr=1988 then do;
bweek=417+ceil((bdays+5)/7);
end;
if bgyr=1989 then do;
bweek=470+ceil((bdays)/7);
end;
if bgyr=1990 then do;
bweek=522+ceil((bdays+1)/7);
end;
if bgyr=1991 then do;
bweek=574+ceil((bdays+2)/7);
end;
if bgyr=1992 then do;
bweek=626+ceil((bdays+3)/7);
end;
if bgyr=1993 then do;
bweek=678+ceil((bdays+5)/7);
end;
if bgyr=1994 then do;
bweek=730+ceil((bdays+6)/7);
end;
if bgyr=1995 then do;
bweek=783+ceil((bdays)/7);
end;
if bgyr=1996 then do;
bweek=835+ceil((bdays+1)/7);
end;
if bgyr=1997 then do;
bweek=887+ceil((bdays+3)/7);
end;
if bgyr=1998 then do;
bweek=939+ceil((bdays+4)/7);
end;
if bgyr=1999 then do;
bweek=991+ceil((bdays+5)/7);
end;
if bgyr=2000 then do;
bweek=1043+ceil((bdays+6)/7);
end;
if bgyr=2001 then do;
bweek=1096+ceil((bdays+1)/7);
end;
if bgyr=2002 then do;
bweek=1148+ceil((bdays+2)/7);
end;
if bgyr=2003 then do;
bweek=1200+ceil((bdays+3)/7);
end;
if bgyr=2004 then do;
bweek=1252+ceil((bdays+4)/7);
end;
if bweek>0 then do;
bweek=bweek+1;
end;
end;
end;
do over egyr;
if egyr>0 and edays>0 then do;
if egyr=1980 then do;
eweek=ceil((edays+2)/7);
end;
if egyr=1981 then do;
eweek=52+ceil((edays+4)/7);
end;
if egyr=1982 then do;
eweek=104+ceil((edays+5)/7);
end;
if egyr=1983 then do;
eweek=156+ceil((edays+6)/7);
end;
if egyr=1984 then do;
eweek=209+ceil((edays)/7);
end;
if egyr=1985 then do;
eweek=261+ceil((edays+2)/7);
end;
if egyr=1986 then do;
eweek=313+ceil((edays+3)/7);
end;
if egyr=1987 then do;
eweek=365+ceil((edays+4)/7);
end;
if egyr=1988 then do;
eweek=417+ceil((edays+5)/7);
end;
if egyr=1989 then do;
eweek=470+ceil((edays)/7);
end;
if egyr=1990 then do;
eweek=522+ceil((edays+1)/7);
end;
if egyr=1991 then do;
eweek=574+ceil((edays+2)/7);
end;
if egyr=1992 then do;
eweek=626+ceil((edays+3)/7);
end;
if egyr=1993 then do;
eweek=678+ceil((edays+5)/7);
end;
if egyr=1994 then do;
eweek=730+ceil((edays+6)/7);
end;
if egyr=1995 then do;
eweek=783+ceil((edays)/7);
end;
if egyr=1996 then do;
eweek=835+ceil((edays+1)/7);
end;
if egyr=1997 then do;
eweek=887+ceil((edays+3)/7);
end;
if egyr=1998 then do;
eweek=939+ceil((edays+4)/7);
end;
if egyr=1999 then do;
eweek=991+ceil((edays+5)/7);
end;
if egyr=2000 then do;
eweek=1043+ceil((edays+6)/7);
end;
if egyr=2001 then do;
eweek=1096+ceil((edays+1)/7);
end;
if egyr=2002 then do;
eweek=1148+ceil((edays+2)/7);
end;
if egyr=2003 then do;
eweek=1200+ceil((edays+3)/7);
end;
if egyr=2004 then do;
eweek=1252+ceil((edays+4)/7);
end;
if eweek>0 then do;
eweek=eweek-1;
end;
end;
end;
/* The following lines omit gap start and stop dates for gaps less than one work week (5 days) */
do over bdays;
if edays-bdays<4 and bweek>=eweek and bdays ne . and edays ne . and bgyr=egyr then do;
bweek=.;
eweek=.;
end;
end;
/* For self-employed jobs, use the "age18jan" as the left-side-limit for gap dates. */
do over bweek;
if self02=1 and 0<bweek<=(ag18jan-1) then bweek=ag18jan;
if self02=1 and 0<bweek<=(ag18jan-1) and 0<eweek<=(ag18jan-1) then do;
bweek=.;
eweek=.;
end;
end;
/* The following lines are for end gap dates that exceed the interview date due to our rounding methods. */
do over eweek;
if 0<eweek<1400 and eweek>r7int then do;
eweek=r7int;
end;
end;
array update (i) updat2_1-updat2_3;
do over bweek;
if 0<eweek<1252 then do;
if bweek>eweek then do;
bweek=eweek;
update=1;
end;
end;
end;
do over bweek;
if UID02>0 and dliwk>0 and bweek>0 and eweek>0 then do;
if dliwk>bweek and dliwk>eweek then do;
bweek=.;
eweek=.;
end;
if dliwk<eweek and dliwk>bweek then do;
bweek=dliwk;
end;
end;
end;
/* The following erases gaps that occur after the job has ended, only in cases where there are no imputed job
start or stop months or years (imputed job start/stop days acceptable) */
do over bweek;
if starw02>0 and stopw02>0 and smof02=0 and emof02=0 then do;
if bweek>stopw02 then do;
bweek=.;
end;
if eweek>stopw02 then do;
eweek=.;
end;
end;
end;
/* To correct for bad gap information */
do over bdays;
if eweek>stopw02 and stopw02>0 then eweek=stopw02;
if bweek<starw02 and bweek>0 then do;
bweek=starw02;
if eweek<starw02 and eweek ne . then do;
eweek=bweek;
huh02=1;
end;
end;
if bweek>stopw02 and stopw02>0 then huh02=1;
if eweek<starw02 and eweek ne . and starw02>0 then huh02=1;
end;
* checked: there is no case with huh02=1;
******************
** JOB 3 GAPS **
******************;
data emp_gaps3; set emp_gaps1;
/* These variables are read as follows:
BGDY3_1 = Begin day of within-job gap 1 on job 3
EGMO3_6 = End month of within-job gap 6 on job 3
BGAP3_2 = Begin week of within-job gap 2 on job 3 [CREATED] */
array sbgdy (i) sBGDY3_1-sBGDY3_2;
array sbgmo (i) sBGMO3_1-sBGMO3_2;
array sbgyr (i) sBGYR3_1-sBGYR3_2;
array segdy (i) sEGDY3_1-sEGDY3_2;
array segmo (i) sEGMO3_1-sEGMO3_2;
array segyr (i) sEGYR3_1-sEGYR3_2;
array bgdy (i) BGDY3_01-BGDY3_02;
array bgmo (i) BGMO3_01-BGMO3_02;
array bgyr (i) BGYR3_01-BGYR3_02;
array egdy (i) EGDY3_01-EGDY3_02;
array egmo (i) EGMO3_01-EGMO3_02;
array egyr (i) EGYR3_01-EGYR3_02;
array bdays (i) bday3_01-bday3_02;
array edays (i) eday3_01-eday3_02;
array bweek (i) bgap3_01-bgap3_02;
array eweek (i) egap3_01-egap3_02;
array bflag (i) bflg3_01-bflg3_02;
array eflag (i) eflg3_01-eflg3_02;
array bgfl (i) bgfl3_01-bgfl3_02;
array egfl (i) egfl3_01-egfl3_02;
if self03=1 then do;
gap03=sgap03;
numgap3=snumgap3;
do i=1 to 2;
bgdy = sbgdy;
bgmo = sbgmo;
bgyr = sbgyr;
egdy = segdy;
egmo = segmo;
egyr = segyr;
end;
end;
/* ONLY IMPUTE START/STOP DATES IF DAY IS MISSING */
***Fill-in start day for those missing;
do over bgyr;
if bgyr>0 then do;
if bgmo>0 and bgdy<=0 then do;
bgdy=1;
bflag=1;
end;
if bgyr=stary03 and bgmo=starm03 and bgdy<stard03 and bflag=1 then bgdy=stard03;
end;
end;
/* Fill-in stop day for those missing */
do over egyr;
if egyr>0 then do;
if egmo>0 and egdy<=0 then do;
egdy=1;
eflag=1;
end;
if egyr=stopy03 and egmo=stopm03 and egdy>stopd03 and eflag=1 then egdy=stopd03;
end;
end;
***Set flag for gap exists but invalid data;
do over bgyr;
bgfl=-4;
if (-4 < bgmo < 0) or (-4 < bgyr < 0) then bgfl=1;
end;
do over egyr;
egfl=-4;
if (-4 < egyr < 0) or (-4 < egmo < 0) then egfl=1;
end;
***Convert START month and day to total days (BDAYS);
do over bgmo;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+59;
if bgmo=4 then bdays=bgdy+90;
if bgmo=5 then bdays=bgdy+120;
if bgmo=6 then bdays=bgdy+151;
if bgmo=7 then bdays=bgdy+181;
if bgmo=8 then bdays=bgdy+212;
if bgmo=9 then bdays=bgdy+243;
if bgmo=10 then bdays=bgdy+273;
if bgmo=11 then bdays=bgdy+304;
if bgmo=12 then bdays=bgdy+334;
end;
end;
***Account for leap years;
do over bgyr;
if bgyr=1980 or bgyr=1984 or bgyr=1988 or bgyr=1992 or bgyr=1996 or bgyr=2000 then do;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+60;
if bgmo=4 then bdays=bgdy+91;
if bgmo=5 then bdays=bgdy+121;
if bgmo=6 then bdays=bgdy+152;
if bgmo=7 then bdays=bgdy+182;
if bgmo=8 then bdays=bgdy+213;
if bgmo=9 then bdays=bgdy+244;
if bgmo=10 then bdays=bgdy+274;
if bgmo=11 then bdays=bgdy+305;
if bgmo=12 then bdays=bgdy+335;
end;
end;
end;
***Convert STOP month and day to total days (EDAYS);
do over egmo;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+59;
if egmo=4 then edays=egdy+90;
if egmo=5 then edays=egdy+120;
if egmo=6 then edays=egdy+151;
if egmo=7 then edays=egdy+181;
if egmo=8 then edays=egdy+212;
if egmo=9 then edays=egdy+243;
if egmo=10 then edays=egdy+273;
if egmo=11 then edays=egdy+304;
if egmo=12 then edays=egdy+334;
end;
end;
***Account for leap years;
do over egyr;
if egyr=1980 or egyr=1984 or egyr=1988 or egyr=1992 or egyr=1996 or egyr=2000 or egyr=2004 then do;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+60;
if egmo=4 then edays=egdy+91;
if egmo=5 then edays=egdy+121;
if egmo=6 then edays=egdy+152;
if egmo=7 then edays=egdy+182;
if egmo=8 then edays=egdy+213;
if egmo=9 then edays=egdy+244;
if egmo=10 then edays=egdy+274;
if egmo=11 then edays=egdy+305;
if egmo=12 then edays=egdy+335;
end;
end;
end;
***Convert days into week numbers;
** Basic Formula: **
** weekno=endweek{specific year}+ceil[(totdays+{# of days remaining in DEC})/7] **
do over bgyr;
if bgyr>0 and bdays>0 then do;
if bgyr=1980 then do;
bweek=ceil((bdays+2)/7);
end;
if bgyr=1981 then do;
bweek=52+ceil((bdays+4)/7);
end;
if bgyr=1982 then do;
bweek=104+ceil((bdays+5)/7);
end;
if bgyr=1983 then do;
bweek=156+ceil((bdays+6)/7);
end;
if bgyr=1984 then do;
bweek=209+ceil((bdays)/7);
end;
if bgyr=1985 then do;
bweek=261+ceil((bdays+2)/7);
end;
if bgyr=1986 then do;
bweek=313+ceil((bdays+3)/7);
end;
if bgyr=1987 then do;
bweek=365+ceil((bdays+4)/7);
end;
if bgyr=1988 then do;
bweek=417+ceil((bdays+5)/7);
end;
if bgyr=1989 then do;
bweek=470+ceil((bdays)/7);
end;
if bgyr=1990 then do;
bweek=522+ceil((bdays+1)/7);
end;
if bgyr=1991 then do;
bweek=574+ceil((bdays+2)/7);
end;
if bgyr=1992 then do;
bweek=626+ceil((bdays+3)/7);
end;
if bgyr=1993 then do;
bweek=678+ceil((bdays+5)/7);
end;
if bgyr=1994 then do;
bweek=730+ceil((bdays+6)/7);
end;
if bgyr=1995 then do;
bweek=783+ceil((bdays)/7);
end;
if bgyr=1996 then do;
bweek=835+ceil((bdays+1)/7);
end;
if bgyr=1997 then do;
bweek=887+ceil((bdays+3)/7);
end;
if bgyr=1998 then do;
bweek=939+ceil((bdays+4)/7);
end;
if bgyr=1999 then do;
bweek=991+ceil((bdays+5)/7);
end;
if bgyr=2000 then do;
bweek=1043+ceil((bdays+6)/7);
end;
if bgyr=2001 then do;
bweek=1096+ceil((bdays+1)/7);
end;
if bgyr=2002 then do;
bweek=1148+ceil((bdays+2)/7);
end;
if bgyr=2003 then do;
bweek=1200+ceil((bdays+3)/7);
end;
if bgyr=2004 then do;
bweek=1252+ceil((bdays+4)/7);
end;
if bweek>0 then do;
bweek=bweek+1;
end;
end;
end;
do over egyr;
if egyr>0 and edays>0 then do;
if egyr=1980 then do;
eweek=ceil((edays+2)/7);
end;
if egyr=1981 then do;
eweek=52+ceil((edays+4)/7);
end;
if egyr=1982 then do;
eweek=104+ceil((edays+5)/7);
end;
if egyr=1983 then do;
eweek=156+ceil((edays+6)/7);
end;
if egyr=1984 then do;
eweek=209+ceil((edays)/7);
end;
if egyr=1985 then do;
eweek=261+ceil((edays+2)/7);
end;
if egyr=1986 then do;
eweek=313+ceil((edays+3)/7);
end;
if egyr=1987 then do;
eweek=365+ceil((edays+4)/7);
end;
if egyr=1988 then do;
eweek=417+ceil((edays+5)/7);
end;
if egyr=1989 then do;
eweek=470+ceil((edays)/7);
end;
if egyr=1990 then do;
eweek=522+ceil((edays+1)/7);
end;
if egyr=1991 then do;
eweek=574+ceil((edays+2)/7);
end;
if egyr=1992 then do;
eweek=626+ceil((edays+3)/7);
end;
if egyr=1993 then do;
eweek=678+ceil((edays+5)/7);
end;
if egyr=1994 then do;
eweek=730+ceil((edays+6)/7);
end;
if egyr=1995 then do;
eweek=783+ceil((edays)/7);
end;
if egyr=1996 then do;
eweek=835+ceil((edays+1)/7);
end;
if egyr=1997 then do;
eweek=887+ceil((edays+3)/7);
end;
if egyr=1998 then do;
eweek=939+ceil((edays+4)/7);
end;
if egyr=1999 then do;
eweek=991+ceil((edays+5)/7);
end;
if egyr=2000 then do;
eweek=1043+ceil((edays+6)/7);
end;
if egyr=2001 then do;
eweek=1096+ceil((edays+1)/7);
end;
if egyr=2002 then do;
eweek=1148+ceil((edays+2)/7);
end;
if egyr=2003 then do;
eweek=1200+ceil((edays+3)/7);
end;
if egyr=2004 then do;
eweek=1252+ceil((edays+4)/7);
end;
if eweek>0 then do;
eweek=eweek-1;
end;
end;
end;
/* The following lines omit gap start and stop dates for gaps less than one work week (5 days) */
do over bdays;
if edays-bdays<4 and bweek>=eweek and bdays ne . and edays ne . and bgyr=egyr then do;
bweek=.;
eweek=.;
end;
end;
/* For self-employed jobs, use the "age18jan" as the left-side-limit for gap dates. */
do over bweek;
if self03=1 and 0<bweek<=(ag18jan-1) then bweek=ag18jan;
if self03=1 and 0<bweek<=(ag18jan-1) and 0<eweek<=(ag18jan-1) then do;
bweek=.;
eweek=.;
end;
end;
/* The following lines are for end gap dates that exceed the interview date due to our rounding methods. */
do over eweek;
if 0<eweek<1400 and eweek>r7int then do;
eweek=r7int;
end;
end;
array update (i) updat3_1-updat3_2;
do over bweek;
if 0<eweek<1252 then do;
if bweek>eweek then do;
bweek=eweek;
update=1;
end;
end;
end;
do over bweek;
if UID03>0 and dliwk>0 and bweek>0 and eweek>0 then do;
if dliwk>bweek and dliwk>eweek then do;
bweek=.;
eweek=.;
end;
if dliwk<eweek and dliwk>bweek then do;
bweek=dliwk;
end;
end;
end;
/* The following erases gaps that occur after the job has ended, only in cases where there are no imputed job
start or stop months or years (imputed job start/stop days acceptable) */
do over bweek;
if starw03>0 and stopw03>0 and smof03=0 and emof03=0 then do;
if bweek>stopw03 then do;
bweek=.;
end;
if eweek>stopw03 then do;
eweek=.;
end;
end;
end;
/* To correct for bad gap information */
do over bdays;
if eweek>stopw03 and stopw03>0 then eweek=stopw03;
if bweek<starw03 and bweek>0 then do;
bweek=starw03;
if eweek<starw03 and eweek ne . then do;
eweek=bweek;
huh03=1;
end;
end;
if bweek>stopw03 and stopw03>0 then huh03=1;
if eweek<starw03 and eweek ne . and starw03>0 then huh03=1;
end;
******************
** JOB 4 GAPS **
******************;
data emp_gaps4; set emp_gaps1;
/* These variables are read as follows:
BGDY4_1 = Begin day of within-job gap 1 on job 4
EGMO4_6 = End month of within-job gap 6 on job 4
BGAP4_2 = Begin week of within-job gap 2 on job 4 [CREATED] */
array sbgdy (i) sBGDY4_1-sBGDY4_2;
array sbgmo (i) sBGMO4_1-sBGMO4_2;
array sbgyr (i) sBGYR4_1-sBGYR4_2;
array segdy (i) sEGDY4_1-sEGDY4_2;
array segmo (i) sEGMO4_1-sEGMO4_2;
array segyr (i) sEGYR4_1-sEGYR4_2;
array bgdy (i) BGDY4_01-BGDY4_02;
array bgmo (i) BGMO4_01-BGMO4_02;
array bgyr (i) BGYR4_01-BGYR4_02;
array egdy (i) EGDY4_01-EGDY4_02;
array egmo (i) EGMO4_01-EGMO4_02;
array egyr (i) EGYR4_01-EGYR4_02;
array bdays (i) bday4_01-bday4_02;
array edays (i) eday4_01-eday4_02;
array bweek (i) bgap4_01-bgap4_02;
array eweek (i) egap4_01-egap4_02;
array bflag (i) bflg4_01-bflg4_02;
array eflag (i) eflg4_01-eflg4_02;
array bgfl (i) bgfl4_01-bgfl4_02;
array egfl (i) egfl4_01-egfl4_02;
if self04=1 then do;
gap04=sgap04;
numgap4=snumgap4;
do i=1 to 2;
bgdy = sbgdy;
bgmo = sbgmo;
bgyr = sbgyr;
egdy = segdy;
egmo = segmo;
egyr = segyr;
end;
end;
/* ONLY IMPUTE START/STOP DATES IF DAY IS MISSING */
***Fill-in start day for those missing;
do over bgyr;
if bgyr>0 then do;
if bgmo>0 and bgdy<=0 then do;
bgdy=1;
bflag=1;
end;
if bgyr=stary04 and bgmo=starm04 and bgdy<stard04 and bflag=1 then bgdy=stard04;
end;
end;
/* Fill-in stop day for those missing */
do over egyr;
if egyr>0 then do;
if egmo>0 and egdy<=0 then do;
egdy=1;
eflag=1;
end;
if egyr=stopy04 and egmo=stopm04 and egdy>stopd04 and eflag=1 then egdy=stopd04;
end;
end;
***Set flag for gap exists but invalid data;
do over bgyr;
bgfl=-4;
if (-4 < bgmo < 0) or (-4 < bgyr < 0) then bgfl=1;
end;
do over egyr;
egfl=-4;
if (-4 < egyr < 0) or (-4 < egmo < 0) then egfl=1;
end;
***Convert START month and day to total days (BDAYS);
do over bgmo;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+59;
if bgmo=4 then bdays=bgdy+90;
if bgmo=5 then bdays=bgdy+120;
if bgmo=6 then bdays=bgdy+151;
if bgmo=7 then bdays=bgdy+181;
if bgmo=8 then bdays=bgdy+212;
if bgmo=9 then bdays=bgdy+243;
if bgmo=10 then bdays=bgdy+273;
if bgmo=11 then bdays=bgdy+304;
if bgmo=12 then bdays=bgdy+334;
end;
end;
***Account for leap years;
do over bgyr;
if bgyr=1980 or bgyr=1984 or bgyr=1988 or bgyr=1992 or bgyr=1996 or bgyr=2000 then do;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+60;
if bgmo=4 then bdays=bgdy+91;
if bgmo=5 then bdays=bgdy+121;
if bgmo=6 then bdays=bgdy+152;
if bgmo=7 then bdays=bgdy+182;
if bgmo=8 then bdays=bgdy+213;
if bgmo=9 then bdays=bgdy+244;
if bgmo=10 then bdays=bgdy+274;
if bgmo=11 then bdays=bgdy+305;
if bgmo=12 then bdays=bgdy+335;
end;
end;
end;
***Convert STOP month and day to total days (EDAYS);
do over egmo;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+59;
if egmo=4 then edays=egdy+90;
if egmo=5 then edays=egdy+120;
if egmo=6 then edays=egdy+151;
if egmo=7 then edays=egdy+181;
if egmo=8 then edays=egdy+212;
if egmo=9 then edays=egdy+243;
if egmo=10 then edays=egdy+273;
if egmo=11 then edays=egdy+304;
if egmo=12 then edays=egdy+334;
end;
end;
***Account for leap years;
do over egyr;
if egyr=1980 or egyr=1984 or egyr=1988 or egyr=1992 or egyr=1996 or egyr=2000 or egyr=2004 then do;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+60;
if egmo=4 then edays=egdy+91;
if egmo=5 then edays=egdy+121;
if egmo=6 then edays=egdy+152;
if egmo=7 then edays=egdy+182;
if egmo=8 then edays=egdy+213;
if egmo=9 then edays=egdy+244;
if egmo=10 then edays=egdy+274;
if egmo=11 then edays=egdy+305;
if egmo=12 then edays=egdy+335;
end;
end;
end;
***Convert days into week numbers;
** Basic Formula: **
** weekno=endweek{specific year}+ceil[(totdays+{# of days remaining in DEC})/7] **
do over bgyr;
if bgyr>0 and bdays>0 then do;
if bgyr=1980 then do;
bweek=ceil((bdays+2)/7);
end;
if bgyr=1981 then do;
bweek=52+ceil((bdays+4)/7);
end;
if bgyr=1982 then do;
bweek=104+ceil((bdays+5)/7);
end;
if bgyr=1983 then do;
bweek=156+ceil((bdays+6)/7);
end;
if bgyr=1984 then do;
bweek=209+ceil((bdays)/7);
end;
if bgyr=1985 then do;
bweek=261+ceil((bdays+2)/7);
end;
if bgyr=1986 then do;
bweek=313+ceil((bdays+3)/7);
end;
if bgyr=1987 then do;
bweek=365+ceil((bdays+4)/7);
end;
if bgyr=1988 then do;
bweek=417+ceil((bdays+5)/7);
end;
if bgyr=1989 then do;
bweek=470+ceil((bdays)/7);
end;
if bgyr=1990 then do;
bweek=522+ceil((bdays+1)/7);
end;
if bgyr=1991 then do;
bweek=574+ceil((bdays+2)/7);
end;
if bgyr=1992 then do;
bweek=626+ceil((bdays+3)/7);
end;
if bgyr=1993 then do;
bweek=678+ceil((bdays+5)/7);
end;
if bgyr=1994 then do;
bweek=730+ceil((bdays+6)/7);
end;
if bgyr=1995 then do;
bweek=783+ceil((bdays)/7);
end;
if bgyr=1996 then do;
bweek=835+ceil((bdays+1)/7);
end;
if bgyr=1997 then do;
bweek=887+ceil((bdays+3)/7);
end;
if bgyr=1998 then do;
bweek=939+ceil((bdays+4)/7);
end;
if bgyr=1999 then do;
bweek=991+ceil((bdays+5)/7);
end;
if bgyr=2000 then do;
bweek=1043+ceil((bdays+6)/7);
end;
if bgyr=2001 then do;
bweek=1096+ceil((bdays+1)/7);
end;
if bgyr=2002 then do;
bweek=1148+ceil((bdays+2)/7);
end;
if bgyr=2003 then do;
bweek=1200+ceil((bdays+3)/7);
end;
if bgyr=2004 then do;
bweek=1252+ceil((bdays+4)/7);
end;
if bweek>0 then do;
bweek=bweek+1;
end;
end;
end;
do over egyr;
if egyr>0 and edays>0 then do;
if egyr=1980 then do;
eweek=ceil((edays+2)/7);
end;
if egyr=1981 then do;
eweek=52+ceil((edays+4)/7);
end;
if egyr=1982 then do;
eweek=104+ceil((edays+5)/7);
end;
if egyr=1983 then do;
eweek=156+ceil((edays+6)/7);
end;
if egyr=1984 then do;
eweek=209+ceil((edays)/7);
end;
if egyr=1985 then do;
eweek=261+ceil((edays+2)/7);
end;
if egyr=1986 then do;
eweek=313+ceil((edays+3)/7);
end;
if egyr=1987 then do;
eweek=365+ceil((edays+4)/7);
end;
if egyr=1988 then do;
eweek=417+ceil((edays+5)/7);
end;
if egyr=1989 then do;
eweek=470+ceil((edays)/7);
end;
if egyr=1990 then do;
eweek=522+ceil((edays+1)/7);
end;
if egyr=1991 then do;
eweek=574+ceil((edays+2)/7);
end;
if egyr=1992 then do;
eweek=626+ceil((edays+3)/7);
end;
if egyr=1993 then do;
eweek=678+ceil((edays+5)/7);
end;
if egyr=1994 then do;
eweek=730+ceil((edays+6)/7);
end;
if egyr=1995 then do;
eweek=783+ceil((edays)/7);
end;
if egyr=1996 then do;
eweek=835+ceil((edays+1)/7);
end;
if egyr=1997 then do;
eweek=887+ceil((edays+3)/7);
end;
if egyr=1998 then do;
eweek=939+ceil((edays+4)/7);
end;
if egyr=1999 then do;
eweek=991+ceil((edays+5)/7);
end;
if egyr=2000 then do;
eweek=1043+ceil((edays+6)/7);
end;
if egyr=2001 then do;
eweek=1096+ceil((edays+1)/7);
end;
if egyr=2002 then do;
eweek=1148+ceil((edays+2)/7);
end;
if egyr=2003 then do;
eweek=1200+ceil((edays+3)/7);
end;
if egyr=2004 then do;
eweek=1252+ceil((edays+4)/7);
end;
if eweek>0 then do;
eweek=eweek-1;
end;
end;
end;
/* The following lines omit gap start and stop dates for gaps less than one work week (5 days) */
do over bdays;
if edays-bdays<4 and bweek>=eweek and bdays ne . and edays ne . and bgyr=egyr then do;
bweek=.;
eweek=.;
end;
end;
/* For self-employed jobs, use the "age18jan" as the left-side-limit for gap dates. */
do over bweek;
if self04=1 and 0<bweek<=(ag18jan-1) then bweek=ag18jan;
if self04=1 and 0<bweek<=(ag18jan-1) and 0<eweek<=(ag18jan-1) then do;
bweek=.;
eweek=.;
end;
end;
/* The following lines are for end gap dates that exceed the interview date due to our rounding methods. */
do over eweek;
if 0<eweek<1400 and eweek>r7int then do;
eweek=r7int;
end;
end;
array update (i) updat4_1-updat4_2;
do over bweek;
if 0<eweek<1252 then do;
if bweek>eweek then do;
bweek=eweek;
update=1;
end;
end;
end;
do over bweek;
if UID04>0 and dliwk>0 and bweek>0 and eweek>0 then do;
if dliwk>bweek and dliwk>eweek then do;
bweek=.;
eweek=.;
end;
if dliwk<eweek and dliwk>bweek then do;
bweek=dliwk;
end;
end;
end;
/* The following erases gaps that occur after the job has ended, only in cases where there are no imputed job
start or stop months or years (imputed job start/stop days acceptable) */
do over bweek;
if starw04>0 and stopw04>0 and smof04=0 and emof04=0 then do;
if bweek>stopw04 then do;
bweek=.;
end;
if eweek>stopw04 then do;
eweek=.;
end;
end;
end;
/* To correct for bad gap information */
do over bdays;
if eweek>stopw04 and stopw04>0 then eweek=stopw04;
if bweek<starw04 and bweek>0 then do;
bweek=starw04;
if eweek<starw04 and eweek ne . then do;
eweek=bweek;
huh04=1;
end;
end;
if bweek>stopw04 and stopw04>0 then huh04=1;
if eweek<starw04 and eweek ne . and starw04>0 then huh04=1;
end;
* checked: no case has "huh04=1";
******************
** JOB 5 GAPS **
******************;
/* no within job gaps for the self-employed job from job 5. */
data emp_gaps5;
set emp_gaps1;
/* These variables are read as follows:
BGDY5_1 = Begin day of within-job gap 1 on job 5
EGMO5_6 = End month of within-job gap 6 on job 5
BGAP5_2 = Begin week of within-job gap 2 on job 5 [CREATED] */
array bgdy (i) BGDY5_01-BGDY5_02;
array bgmo (i) BGMO5_01-BGMO5_02;
array bgyr (i) BGYR5_01-BGYR5_02;
array egdy (i) EGDY5_01-EGDY5_02;
array egmo (i) EGMO5_01-EGMO5_02;
array egyr (i) EGYR5_01-EGYR5_02;
array bdays (i) bday5_01-bday5_02;
array edays (i) eday5_01-eday5_02;
array bweek (i) bgap5_01-bgap5_02;
array eweek (i) egap5_01-egap5_02;
array bflag (i) bflg5_01-bflg5_02;
array eflag (i) eflg5_01-eflg5_02;
array bgfl (i) bgfl5_01-bgfl5_02;
array egfl (i) egfl5_01-egfl5_02;
/* ONLY IMPUTE START/STOP DATES IF DAY IS MISSING */
***Fill-in start day for those missing;
do over bgyr;
if bgyr>0 then do;
if bgmo>0 and bgdy<=0 then do;
bgdy=1;
bflag=1;
end;
if bgyr=stary05 and bgmo=starm05 and bgdy<stard05 and bflag=1 then bgdy=stard05;
end;
end;
/* Fill-in stop day for those missing */
do over egyr;
if egyr>0 then do;
if egmo>0 and egdy<=0 then do;
egdy=1;
eflag=1;
end;
if egyr=stopy05 and egmo=stopm05 and egdy>stopd05 and eflag=1 then egdy=stopd05;
end;
end;
***Set flag for gap exists but invalid data;
do over bgyr;
bgfl=-4;
if (-4 < bgmo < 0) or (-4 < bgyr < 0) then bgfl=1;
end;
do over egyr;
egfl=-4;
if (-4 < egyr < 0) or (-4 < egmo < 0) then egfl=1;
end;
***Convert START month and day to total days (BDAYS);
do over bgmo;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+59;
if bgmo=4 then bdays=bgdy+90;
if bgmo=5 then bdays=bgdy+120;
if bgmo=6 then bdays=bgdy+151;
if bgmo=7 then bdays=bgdy+181;
if bgmo=8 then bdays=bgdy+212;
if bgmo=9 then bdays=bgdy+243;
if bgmo=10 then bdays=bgdy+273;
if bgmo=11 then bdays=bgdy+304;
if bgmo=12 then bdays=bgdy+334;
end;
end;
***Account for leap years;
do over bgyr;
if bgyr=1980 or bgyr=1984 or bgyr=1988 or bgyr=1992 or bgyr=1996 or bgyr=2000 then do;
if bgmo>0 and bgdy>0 then do;
if bgmo=1 then bdays=bgdy;
if bgmo=2 then bdays=bgdy+31;
if bgmo=3 then bdays=bgdy+60;
if bgmo=4 then bdays=bgdy+91;
if bgmo=5 then bdays=bgdy+121;
if bgmo=6 then bdays=bgdy+152;
if bgmo=7 then bdays=bgdy+182;
if bgmo=8 then bdays=bgdy+213;
if bgmo=9 then bdays=bgdy+244;
if bgmo=10 then bdays=bgdy+274;
if bgmo=11 then bdays=bgdy+305;
if bgmo=12 then bdays=bgdy+335;
end;
end;
end;
***Convert STOP month and day to total days (EDAYS);
do over egmo;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+59;
if egmo=4 then edays=egdy+90;
if egmo=5 then edays=egdy+120;
if egmo=6 then edays=egdy+151;
if egmo=7 then edays=egdy+181;
if egmo=8 then edays=egdy+212;
if egmo=9 then edays=egdy+243;
if egmo=10 then edays=egdy+273;
if egmo=11 then edays=egdy+304;
if egmo=12 then edays=egdy+334;
end;
end;
***Account for leap years;
do over egyr;
if egyr=1980 or egyr=1984 or egyr=1988 or egyr=1992 or egyr=1996 or egyr=2000 or egyr=2004 then do;
if egmo>0 and egdy>0 then do;
if egmo=1 then edays=egdy;
if egmo=2 then edays=egdy+31;
if egmo=3 then edays=egdy+60;
if egmo=4 then edays=egdy+91;
if egmo=5 then edays=egdy+121;
if egmo=6 then edays=egdy+152;
if egmo=7 then edays=egdy+182;
if egmo=8 then edays=egdy+213;
if egmo=9 then edays=egdy+244;
if egmo=10 then edays=egdy+274;
if egmo=11 then edays=egdy+305;
if egmo=12 then edays=egdy+335;
end;
end;
end;
***Convert days into week numbers;
** Basic Formula: **
** weekno=endweek{specific year}+ceil[(totdays+{# of days remaining in DEC})/7] **
do over bgyr;
if bgyr>0 and bdays>0 then do;
if bgyr=1980 then do;
bweek=ceil((bdays+2)/7);
end;
if bgyr=1981 then do;
bweek=52+ceil((bdays+4)/7);
end;
if bgyr=1982 then do;
bweek=104+ceil((bdays+5)/7);
end;
if bgyr=1983 then do;
bweek=156+ceil((bdays+6)/7);
end;
if bgyr=1984 then do;
bweek=209+ceil((bdays)/7);
end;
if bgyr=1985 then do;
bweek=261+ceil((bdays+2)/7);
end;
if bgyr=1986 then do;
bweek=313+ceil((bdays+3)/7);
end;
if bgyr=1987 then do;
bweek=365+ceil((bdays+4)/7);
end;
if bgyr=1988 then do;
bweek=417+ceil((bdays+5)/7);
end;
if bgyr=1989 then do;
bweek=470+ceil((bdays)/7);
end;
if bgyr=1990 then do;
bweek=522+ceil((bdays+1)/7);
end;
if bgyr=1991 then do;
bweek=574+ceil((bdays+2)/7);
end;
if bgyr=1992 then do;
bweek=626+ceil((bdays+3)/7);
end;
if bgyr=1993 then do;
bweek=678+ceil((bdays+5)/7);
end;
if bgyr=1994 then do;
bweek=730+ceil((bdays+6)/7);
end;
if bgyr=1995 then do;
bweek=783+ceil((bdays)/7);
end;
if bgyr=1996 then do;
bweek=835+ceil((bdays+1)/7);
end;
if bgyr=1997 then do;
bweek=887+ceil((bdays+3)/7);
end;
if bgyr=1998 then do;
bweek=939+ceil((bdays+4)/7);
end;
if bgyr=1999 then do;
bweek=991+ceil((bdays+5)/7);
end;
if bgyr=2000 then do;
bweek=1043+ceil((bdays+6)/7);
end;
if bgyr=2001 then do;
bweek=1096+ceil((bdays+1)/7);
end;
if bgyr=2002 then do;
bweek=1148+ceil((bdays+2)/7);
end;
if bgyr=2003 then do;
bweek=1200+ceil((bdays+3)/7);
end;
if bgyr=2004 then do;
bweek=1252+ceil((bdays+4)/7);
end;
if bweek>0 then do;
bweek=bweek+1;
end;
end;
end;
do over egyr;
if egyr>0 and edays>0 then do;
if egyr=1980 then do;
eweek=ceil((edays+2)/7);
end;
if egyr=1981 then do;
eweek=52+ceil((edays+4)/7);
end;
if egyr=1982 then do;
eweek=104+ceil((edays+5)/7);
end;
if egyr=1983 then do;
eweek=156+ceil((edays+6)/7);
end;
if egyr=1984 then do;
eweek=209+ceil((edays)/7);
end;
if egyr=1985 then do;
eweek=261+ceil((edays+2)/7);
end;
if egyr=1986 then do;
eweek=313+ceil((edays+3)/7);
end;
if egyr=1987 then do;
eweek=365+ceil((edays+4)/7);
end;
if egyr=1988 then do;
eweek=417+ceil((edays+5)/7);
end;
if egyr=1989 then do;
eweek=470+ceil((edays)/7);
end;
if egyr=1990 then do;
eweek=522+ceil((edays+1)/7);
end;
if egyr=1991 then do;
eweek=574+ceil((edays+2)/7);
end;
if egyr=1992 then do;
eweek=626+ceil((edays+3)/7);
end;
if egyr=1993 then do;
eweek=678+ceil((edays+5)/7);
end;
if egyr=1994 then do;
eweek=730+ceil((edays+6)/7);
end;
if egyr=1995 then do;
eweek=783+ceil((edays)/7);
end;
if egyr=1996 then do;
eweek=835+ceil((edays+1)/7);
end;
if egyr=1997 then do;
eweek=887+ceil((edays+3)/7);
end;
if egyr=1998 then do;
eweek=939+ceil((edays+4)/7);
end;
if egyr=1999 then do;
eweek=991+ceil((edays+5)/7);
end;
if egyr=2000 then do;
eweek=1043+ceil((edays+6)/7);
end;
if egyr=2001 then do;
eweek=1096+ceil((edays+1)/7);
end;
if egyr=2002 then do;
eweek=1148+ceil((edays+2)/7);
end;
if egyr=2003 then do;
eweek=1200+ceil((edays+3)/7);
end;
if egyr=2004 then do;
eweek=1252+ceil((edays+4)/7);
end;
if eweek>0 then do;
eweek=eweek-1;
end;
end;
end;
do over bdays;
if edays-bdays<4 and bweek>=eweek and bdays ne . and edays ne . and bgyr=egyr then do;
bweek=.;
eweek=.;
end;
end;
/* The following lines are for end gap dates that exceed the interview date due to our rounding methods. */
do over eweek;
if 0<eweek<1400 and eweek>r7int then do;
eweek=r7int;
end;
end;
array update (i) updat5_1-updat5_2;
do over bweek;
if 0<eweek<1252 then do;
if bweek>eweek then do;
bweek=eweek;
update=1;
end;
end;
end;
do over bweek;
if UID05>0 and dliwk>0 and bweek>0 and eweek>0 then do;
if dliwk>bweek and dliwk>eweek then do;
bweek=.;
eweek=.;
end;
if dliwk<eweek and dliwk>bweek then do;
bweek=dliwk;
end;
end;
end;
/* The following erases gaps that occur after the job has ended, only in cases where there are no imputed job
start or stop months or years (imputed job start/stop days acceptable) */
do over bweek;
if starw05>0 and stopw05>0 and smof05=0 and emof05=0 then do;
if bweek>stopw05 then do;
bweek=.;
end;
if eweek>stopw05 then do;
eweek=.;
end;
end;
end;
/* To correct for bad gap information */
do over bdays;
if eweek>stopw05 and stopw05>0 then eweek=stopw05;
if bweek<starw05 and bweek>0 then do;
bweek=starw05;
if eweek<starw05 and eweek ne . then do;
eweek=bweek;
huh05=1;
end;
end;
if bweek>stopw05 and stopw05>0 then huh05=1;
if eweek<starw05 and eweek ne . and starw05>0 then huh05=1;
end;
* checked: no cases has "huh05=1";
array job1wks (i) w1_1-w1_1280;
array job2wks (i) w2_1-w2_1280;
array job3wks (i) w3_1-w3_1280;
array job4wks (i) w4_1-w4_1280;
array job5wks (i) w5_1-w5_1280;
array job6wks (i) w6_1-w6_1280;
array job7wks (i) w7_1-w7_1280;
array job8wks (i) w8_1-w8_1280;
array job9wks (i) w9_1-w9_1280;
array job10wks (i)w10_1-w10_1280;
* Default Settings;
do i=1 to 1280;
job1wks=0;
job2wks=0;
job3wks=0;
job4wks=0;
job5wks=0;
job6wks=0;
job7wks=0;
job8wks=0;
job9wks=0;
job10wks=0;
end;
* Change military start and stop dates to missing since only civilian jobs are counted ;
if milflag01=1 then do;
starw01=.;
stopw01=.;
end;
if milflag02=1 then do;
starw02=.;
stopw02=.;
end;
if milflag03=1 then do;
starw03=.;
stopw03=.;
end;
if milflag04=1 then do;
starw04=.;
stopw04=.;
end;
if milflag05=1 then do;
starw05=.;
stopw05=.;
end;
if milflag06=1 then do;
starw06=.;
stopw06=.;
end;
if milflag07=1 then do;
starw07=.;
stopw07=.;
end;
if milflag08=1 then do;
starw08=.;
stopw08=.;
end;
if milflag09=1 then do;
starw09=.;
stopw09=.;
end;
if milflag10=1 then do;
starw10=.;
stopw10=.;
end;
/* Define rd7wk as the maximum of dliwk and age14wk. This is used for bad start/stop weeks. */
if dliwk>0 then do;
if dliwk>age14wk then do;
rd7wk=dliwk;
end;
if age14wk=>dliwk then do;
rd7wk=age14wk;
end;
end;
***********************************
*** TOTAL WEEKS WORKED ON JOB 1 ***
***********************************;
starf_1=0;
stopf_1=0;
if starw01=-3 and uid01 ne -5 then do;
starw01=rd7wk;
starf_1=1;
end;
* "begwk01" is . for this group;
if stopw01=-3 and uid01 ne -5 then do;
stopw01=r7int;
stopf_1=1;
end;
* "endwk01" is . for this group;
if smof01=1 and bself01 ne 1 then do;
starf_1=1;
if stary01=1980 then begwk01=52;
if stary01=1981 then begwk01=104;
if stary01=1982 then begwk01=156;
if stary01=1983 then begwk01=209;
if stary01=1984 then begwk01=261;
if stary01=1985 then begwk01=313;
if stary01=1986 then begwk01=365;
if stary01=1987 then begwk01=417;
if stary01=1988 then begwk01=470;
if stary01=1989 then begwk01=522;
if stary01=1990 then begwk01=574;
if stary01=1991 then begwk01=626;
if stary01=1992 then begwk01=678;
if stary01=1993 then begwk01=730;
if stary01=1994 then begwk01=783;
if stary01=1995 then begwk01=835;
if stary01=1996 then begwk01=887;
if stary01=1997 then begwk01=939;
if stary01=1998 then begwk01=991;
if stary01=1999 then begwk01=1043;
if stary01=2000 then begwk01=1096;
if stary01=2001 then begwk01=1148;
if stary01=2002 then begwk01=1200;
if stary01=2003 then begwk01=1252;
if stary01=2004 then begwk01=1304;
end;
if emof01=1 then do;
stopf_1=1;
if stopy01=1980 then endwk01=1;
if stopy01=1981 then endwk01=53;
if stopy01=1982 then endwk01=105;
if stopy01=1983 then endwk01=157;
if stopy01=1984 then endwk01=210;
if stopy01=1985 then endwk01=262;
if stopy01=1986 then endwk01=314;
if stopy01=1987 then endwk01=366;
if stopy01=1988 then endwk01=418;
if stopy01=1989 then endwk01=471;
if stopy01=1990 then endwk01=523;
if stopy01=1991 then endwk01=575;
if stopy01=1992 then endwk01=627;
if stopy01=1993 then endwk01=679;
if stopy01=1994 then endwk01=731;
if stopy01=1995 then endwk01=784;
if stopy01=1996 then endwk01=836;
if stopy01=1997 then endwk01=888;
if stopy01=1998 then endwk01=940;
if stopy01=1999 then endwk01=992;
if stopy01=2000 then endwk01=1044;
if stopy01=2001 then endwk01=1097;
if stopy01=2002 then endwk01=1149;
if stopy01=2003 then endwk01=1201;
if stopy01=2004 then endwk01=1253;
end;
if starw01>0 and stopw01>0 then do;
do i=(starw01) to (stopw01);
job1wks=1;
end;
*** Remove gaps on job 1;
array bweek1 bgap1_01-bgap1_10;
array bweek1l1 bgap1_02-bgap1_11;
array bweek1l2 bgap1_03-bgap1_12;
array bweek1l3 bgap1_04-bgap1_13;
array bweek1l4 bgap1_05-bgap1_14;
array eweek1 egap1_01-egap1_10;
array eweek1l1 egap1_02-egap1_11;
array eweek1l2 egap1_03-egap1_12;
array eweek1l3 egap1_04-egap1_13;
array eweek1l4 egap1_05-egap1_14;
array bflag1 bgfl1_01-bgfl1_10;
array eflag1 egfl1_01-egfl1_10;
array gpfl1 gpfl1_01-gpfl1_10;
do over gpfl1;
if bweek1>0 & eweek1>0 then do;
do i=(bweek1) to (eweek1);
job1wks=0;
end;
end;
if bflag1=1 and eweek1>0 then do;
do i=(starw01) to (eweek1);
job1wks=-3;
gpfl1=1;
end;
end;
if bweek1>0 and eflag1=1 then do;
do i=(bweek1) to min(stopw01,bweek1l1-1,bweek1l2-1,bweek1l3-1,bweek1l4-1,
eweek1l1+1,eweek1l2+1,eweek1l3+1,eweek1l4+1);
job1wks=-3;
gpfl1=1;
end;
end;
if bflag1=1 and eflag1=1 then do;
do i=(starw01) to min (stopw01,bweek1l1-1,bweek1l2-1,bweek1l3-1,bweek1l4-1,
eweek1l1+1,eweek1l2+1,eweek1l3+1,eweek1l4+1);
job1wks=-3;
gpfl1=1;
end;
end;
if starf_1=1 then do;
do i=(starw01) to min(stopw01,begwk01,bweek1-1,bweek1l1-1,bweek1l2-1,
bweek1l3-1,bweek1l4-1,eweek1+1,eweek1l1+1,eweek1l2+1,eweek1l3+1,eweek1l4+1);
job1wks=-3;
end;
end;
if stopf_1=1 then do;
do i=max(starw01,endwk01,bweek1-1,bweek1l1-1,bweek1l2-1,bweek1l3-1,bweek1l4-1,
eweek1+1,eweek1l1+1,eweek1l2+1,eweek1l3+1,eweek1l4+1)
to (stopw01);
job1wks=-3;
end;
end;
end; end;
***********************************
*** TOTAL WEEKS WORKED ON JOB 2 ***
***********************************;
starf_2=0;
stopf_2=0;
if starw02=-3 and uid02 ne -5 then do;
starw02=rd7wk;
starf_2=1;
end;
* "begwk02" is . for this group;
if stopw02=-3 and uid02 ne -5 then do;
stopw02=r7int;
stopf_2=1;
end;
* "endwk02" is . for this group;
if smof02=1 and bself02 ne 1 then do;
starf_2=1;
if stary02=1980 then begwk02=52;
if stary02=1981 then begwk02=104;
if stary02=1982 then begwk02=156;
if stary02=1983 then begwk02=209;
if stary02=1984 then begwk02=261;
if stary02=1985 then begwk02=313;
if stary02=1986 then begwk02=365;
if stary02=1987 then begwk02=417;
if stary02=1988 then begwk02=470;
if stary02=1989 then begwk02=522;
if stary02=1990 then begwk02=574;
if stary02=1991 then begwk02=626;
if stary02=1992 then begwk02=678;
if stary02=1993 then begwk02=730;
if stary02=1994 then begwk02=783;
if stary02=1995 then begwk02=835;
if stary02=1996 then begwk02=887;
if stary02=1997 then begwk02=939;
if stary02=1998 then begwk02=991;
if stary02=1999 then begwk02=1043;
if stary02=2000 then begwk02=1096;
if stary02=2001 then begwk02=1148;
if stary02=2002 then begwk02=1200;
if stary02=2003 then begwk02=1252;
if stary02=2004 then begwk02=1304;
end;
if emof02=1 then do;
stopf_2=1;
if stopy02=1980 then endwk02=1;
if stopy02=1981 then endwk02=53;
if stopy02=1982 then endwk02=105;
if stopy02=1983 then endwk02=157;
if stopy02=1984 then endwk02=210;
if stopy02=1985 then endwk02=262;
if stopy02=1986 then endwk02=314;
if stopy02=1987 then endwk02=366;
if stopy02=1988 then endwk02=418;
if stopy02=1989 then endwk02=471;
if stopy02=1990 then endwk02=523;
if stopy02=1991 then endwk02=575;
if stopy02=1992 then endwk02=627;
if stopy02=1993 then endwk02=679;
if stopy02=1994 then endwk02=731;
if stopy02=1995 then endwk02=784;
if stopy02=1996 then endwk02=836;
if stopy02=1997 then endwk02=888;
if stopy02=1998 then endwk02=940;
if stopy02=1999 then endwk02=992;
if stopy02=2000 then endwk02=1044;
if stopy02=2001 then endwk02=1097;
if stopy02=2002 then endwk02=1149;
if stopy02=2003 then endwk02=1201;
if stopy02=2004 then endwk02=1253;
end;
if starw02>0 and stopw02>0 then do;
do i=(starw02) to (stopw02);
job2wks=1;
end;
*** Remove gaps on job 2;
array bweek2 bgap2_01-bgap2_03;
array bweek2l1 bgap2_02-bgap2_04;
array bweek2l2 bgap2_03-bgap2_05;
array eweek2 egap2_01-egap2_03;
array eweek2l1 egap2_02-egap2_04;
array eweek2l2 egap2_03-egap2_05;
array bflag2 bgfl2_01-bgfl2_03;
array eflag2 egfl2_01-egfl2_03;
array gpfl2 gpfl2_01-gpfl2_03;
do over gpfl2;
if bweek2>0 & eweek2>0 then do;
do i=(bweek2) to (eweek2);
job2wks=0;
end;
end;
if bflag2=1 and eweek2>0 then do;
do i=(starw02) to (eweek2);
job2wks=-3;
gpfl2=1;
end;
end;
if bweek2>0 and eflag2=1 then do;
do i=(bweek2) to min(stopw02,bweek2l1-1,bweek2l2-1,eweek2l1+1,eweek2l2+1);
job2wks=-3;
gpfl2=1;
end;
end;
if bflag2=1 and eflag2=1 then do;
do i=(starw02) to min (stopw02,bweek2l1-1,bweek2l2-1,eweek2l1+1,eweek2l2+1);
job2wks=-3;
gpfl2=1;
end;
end;
if starf_2=1 then do;
do i=(starw02) to min(stopw02,begwk02,bweek2-1,bweek2l1-1,bweek2l2-1,eweek2+1,eweek2l1+1,eweek2l2+1);
job2wks=-3;
end;
end;
if stopf_2=1 then do;
do i=max(starw02,endwk02,bweek2-1,bweek2l1-1,bweek2l2-1,eweek2+1,eweek2l1+1,eweek2l2+1)
to (stopw02);
job2wks=-3;
end;
end;
end; end;
***********************************
*** TOTAL WEEKS WORKED ON JOB 3 ***
***********************************;
starf_3=0;
stopf_3=0;
if starw03=-3 and uid03 ne -5 then do;
starw03=rd7wk;
starf_3=1;
end;
* "begwk03" is . for this group;
if stopw03=-3 and uid03 ne -5 then do;
stopw03=r7int;
stopf_3=1;
end;
* "endwk03" is . for this group;
if smof03=1 and bself03 ne 1 then do;
starf_3=1;
if stary03=1980 then begwk03=52;
if stary03=1981 then begwk03=104;
if stary03=1982 then begwk03=156;
if stary03=1983 then begwk03=209;
if stary03=1984 then begwk03=261;
if stary03=1985 then begwk03=313;
if stary03=1986 then begwk03=365;
if stary03=1987 then begwk03=417;
if stary03=1988 then begwk03=470;
if stary03=1989 then begwk03=522;
if stary03=1990 then begwk03=574;
if stary03=1991 then begwk03=626;
if stary03=1992 then begwk03=678;
if stary03=1993 then begwk03=730;
if stary03=1994 then begwk03=783;
if stary03=1995 then begwk03=835;
if stary03=1996 then begwk03=887;
if stary03=1997 then begwk03=939;
if stary03=1998 then begwk03=991;
if stary03=1999 then begwk03=1043;
if stary03=2000 then begwk03=1096;
if stary03=2001 then begwk03=1148;
if stary03=2002 then begwk03=1200;
if stary03=2003 then begwk03=1252;
if stary03=2004 then begwk03=1304;
end;
if emof03=1 then do;
stopf_3=1;
if stopy03=1980 then endwk03=1;
if stopy03=1981 then endwk03=53;
if stopy03=1982 then endwk03=105;
if stopy03=1983 then endwk03=157;
if stopy03=1984 then endwk03=210;
if stopy03=1985 then endwk03=262;
if stopy03=1986 then endwk03=314;
if stopy03=1987 then endwk03=366;
if stopy03=1988 then endwk03=418;
if stopy03=1989 then endwk03=471;
if stopy03=1990 then endwk03=523;
if stopy03=1991 then endwk03=575;
if stopy03=1992 then endwk03=627;
if stopy03=1993 then endwk03=679;
if stopy03=1994 then endwk03=731;
if stopy03=1995 then endwk03=784;
if stopy03=1996 then endwk03=836;
if stopy03=1997 then endwk03=888;
if stopy03=1998 then endwk03=940;
if stopy03=1999 then endwk03=992;
if stopy03=2000 then endwk03=1044;
if stopy03=2001 then endwk03=1097;
if stopy03=2002 then endwk03=1149;
if stopy03=2003 then endwk03=1201;
if stopy03=2004 then endwk03=1253;
end;
if starw03>0 and stopw03>0 then do;
do i=(starw03) to (stopw03);
job3wks=1;
end;
*** Remove gaps on job 3;
array bweek3 bgap3_01-bgap3_02;
array bweek3l1 bgap3_02-bgap3_03;
array eweek3 egap3_01-egap3_02;
array eweek3l1 egap3_02-egap3_03;
array bflag3 bgfl3_01-bgfl3_02;
array eflag3 egfl3_01-egfl3_02;
array gpfl3 gpfl3_01-gpfl3_02;
do over gpfl3;
if bweek3>0 & eweek3>0 then do;
do i=(bweek3) to (eweek3);
job3wks=0;
end;
end;
if bflag3=1 and eweek3>0 then do;
do i=(starw03) to (eweek3);
job3wks=-3;
gpfl3=1;
end;
end;
if bweek3>0 and eflag3=1 then do;
do i=(bweek3) to min(stopw03,bweek3l1-1,eweek3l1+1);
job3wks=-3;
gpfl3=1;
end;
end;
if bflag3=1 and eflag3=1 then do;
do i=(starw03) to min (stopw03,bweek3l1-1,eweek3l1+1);
job3wks=-3;
gpfl3=1;
end;
end;
if starf_3=1 then do;
do i=(starw03) to min(stopw03,begwk03,bweek3-1,bweek3l1-1,eweek3+1,eweek3l1+1);
job3wks=-3;
end;
end;
if stopf_3=1 then do;
do i=max(starw03,endwk03,bweek3-1,bweek3l1-1,eweek3+1,eweek3l1+1)
to (stopw03);
job3wks=-3;
end;
end;
end; end;
***********************************
*** TOTAL WEEKS WORKED ON JOB 4 ***
***********************************;
starf_4=0;
stopf_4=0;
if starw04=-3 and uid04 ne -5 then do;
starw04=rd7wk;
starf_4=1;
end;
* "begwk04" is . for this group;
if stopw04=-3 and uid04 ne -5 then do;
stopw04=r7int;
stopf_4=1;
end;
* "endwk04" is . for this group;
if smof04=1 and bself04 ne 1 then do;
starf_4=1;
if stary04=1980 then begwk04=52;
if stary04=1981 then begwk04=104;
if stary04=1982 then begwk04=156;
if stary04=1983 then begwk04=209;
if stary04=1984 then begwk04=261;
if stary04=1985 then begwk04=313;
if stary04=1986 then begwk04=365;
if stary04=1987 then begwk04=417;
if stary04=1988 then begwk04=470;
if stary04=1989 then begwk04=522;
if stary04=1990 then begwk04=574;
if stary04=1991 then begwk04=626;
if stary04=1992 then begwk04=678;
if stary04=1993 then begwk04=730;
if stary04=1994 then begwk04=783;
if stary04=1995 then begwk04=835;
if stary04=1996 then begwk04=887;
if stary04=1997 then begwk04=939;
if stary04=1998 then begwk04=991;
if stary04=1999 then begwk04=1043;
if stary04=2000 then begwk04=1096;
if stary04=2001 then begwk04=1148;
if stary04=2002 then begwk04=1200;
if stary04=2003 then begwk04=1252;
if stary04=2004 then begwk04=1304;
end;
if emof04=1 then do;
stopf_4=1;
if stopy04=1980 then endwk04=1;
if stopy04=1981 then endwk04=53;
if stopy04=1982 then endwk04=105;
if stopy04=1983 then endwk04=157;
if stopy04=1984 then endwk04=210;
if stopy04=1985 then endwk04=262;
if stopy04=1986 then endwk04=314;
if stopy04=1987 then endwk04=366;
if stopy04=1988 then endwk04=418;
if stopy04=1989 then endwk04=471;
if stopy04=1990 then endwk04=523;
if stopy04=1991 then endwk04=575;
if stopy04=1992 then endwk04=627;
if stopy04=1993 then endwk04=679;
if stopy04=1994 then endwk04=731;
if stopy04=1995 then endwk04=784;
if stopy04=1996 then endwk04=836;
if stopy04=1997 then endwk04=888;
if stopy04=1998 then endwk04=940;
if stopy04=1999 then endwk04=992;
if stopy04=2000 then endwk04=1044;
if stopy04=2001 then endwk04=1097;
if stopy04=2002 then endwk04=1149;
if stopy04=2003 then endwk04=1201;
if stopy04=2004 then endwk04=1253;
end;
if starw04>0 and stopw04>0 then do;
do i=(starw04) to (stopw04);
job4wks=1;
end;
*** Remove gaps on job 4;
array bweek4 bgap4_01-bgap4_02;
array bweek4l1 bgap4_02-bgap4_03;
array eweek4 egap4_01-egap4_02;
array eweek4l1 egap4_02-egap4_03;
array bflag4 bgfl4_01-bgfl4_02;
array eflag4 egfl4_01-egfl4_02;
array gpfl4 gpfl4_01-gpfl4_02;
do over gpfl4;
if bweek4>0 & eweek4>0 then do;
do i=(bweek4) to (eweek4);
job4wks=0;
end;
end;
if bflag4=1 and eweek4>0 then do;
do i=(starw04) to (eweek4);
job4wks=-3;
gpfl4=1;
end;
end;
if bweek4>0 and eflag4=1 then do;
do i=(bweek4) to min(stopw04,bweek4l1-1,eweek4l1+1);
job4wks=-3;
gpfl4=1;
end;
end;
if bflag4=1 and eflag4=1 then do;
do i=(starw04) to min (stopw04,bweek4l1-1,eweek4l1+1);
job4wks=-3;
gpfl4=1;
end;
end;
if starf_4=1 then do;
do i=(starw04) to min(stopw04,begwk04,bweek4-1,bweek4l1-1,eweek4+1,eweek4l1+1);
job4wks=-3;
end;
end;
if stopf_4=1 then do;
do i=max(starw04,endwk04,bweek4-1,bweek4l1-1,eweek4+1,eweek4l1+1) to (stopw04);
job4wks=-3;
end;
end;
end; end;
***********************************
*** TOTAL WEEKS WORKED ON JOB 5 ***
***********************************;
starf_5=0;
stopf_5=0;
if starw05=-3 and uid05 ne -5 then do;
starw05=rd7wk;
starf_5=1;
end;
* "begwk05" is . for this group;
if stopw05=-3 and uid05 ne -5 then do;
stopw05=r7int;
stopf_5=1;
end;
* "endwk05" is . for this group;
if smof05=1 and bself05 ne 1 then do;
starf_5=1;
if stary05=1980 then begwk05=52;
if stary05=1981 then begwk05=104;
if stary05=1982 then begwk05=156;
if stary05=1983 then begwk05=209;
if stary05=1984 then begwk05=261;
if stary05=1985 then begwk05=313;
if stary05=1986 then begwk05=365;
if stary05=1987 then begwk05=417;
if stary05=1988 then begwk05=470;
if stary05=1989 then begwk05=522;
if stary05=1990 then begwk05=574;
if stary05=1991 then begwk05=626;
if stary05=1992 then begwk05=678;
if stary05=1993 then begwk05=730;
if stary05=1994 then begwk05=783;
if stary05=1995 then begwk05=835;
if stary05=1996 then begwk05=887;
if stary05=1997 then begwk05=939;
if stary05=1998 then begwk05=991;
if stary05=1999 then begwk05=1043;
if stary05=2000 then begwk05=1096;
if stary05=2001 then begwk05=1148;
if stary05=2002 then begwk05=1200;
if stary05=2003 then begwk05=1252;
if stary05=2004 then begwk05=1304;
end;
if emof05=1 then do;
stopf_5=1;
if stopy05=1980 then endwk05=1;
if stopy05=1981 then endwk05=53;
if stopy05=1982 then endwk05=105;
if stopy05=1983 then endwk05=157;
if stopy05=1984 then endwk05=210;
if stopy05=1985 then endwk05=262;
if stopy05=1986 then endwk05=314;
if stopy05=1987 then endwk05=366;
if stopy05=1988 then endwk05=418;
if stopy05=1989 then endwk05=471;
if stopy05=1990 then endwk05=523;
if stopy05=1991 then endwk05=575;
if stopy05=1992 then endwk05=627;
if stopy05=1993 then endwk05=679;
if stopy05=1994 then endwk05=731;
if stopy05=1995 then endwk05=784;
if stopy05=1996 then endwk05=836;
if stopy05=1997 then endwk05=888;
if stopy05=1998 then endwk05=940;
if stopy05=1999 then endwk05=992;
if stopy05=2000 then endwk05=1044;
if stopy05=2001 then endwk05=1097;
if stopy05=2002 then endwk05=1149;
if stopy05=2003 then endwk05=1201;
if stopy05=2004 then endwk05=1253;
end;
if starw05>0 and stopw05>0 then do;
do i=(starw05) to (stopw05);
job5wks=1;
end;
*** Remove gaps on job 5;
array bweek5 bgap5_01-bgap5_02;
array bweek5l1 bgap5_02-bgap5_03;
array eweek5 egap5_01-egap5_02;
array eweek5l1 egap5_02-egap5_03;
array bflag5 bgfl5_01-bgfl5_02;
array eflag5 egfl5_01-egfl5_02;
array gpfl5 gpfl5_01-gpfl5_02;
do over gpfl5;
if bweek5>0 & eweek5>0 then do;
do i=(bweek5) to (eweek5);
job5wks=0;
end;
end;
if bflag5=1 and eweek5>0 then do;
do i=(starw05) to (eweek5);
job5wks=-3;
gpfl5=1;
end;
end;
if bweek5>0 and eflag5=1 then do;
do i=(bweek5) to min(stopw05,bweek5l1-1,eweek5l1+1);
job5wks=-3;
gpfl5=1;
end;
end;
if bflag5=1 and eflag5=1 then do;
do i=(starw05) to min (stopw05,bweek5l1-1,eweek5l1+1);
job5wks=-3;
gpfl5=1;
end;
end;
if starf_5=1 then do;
do i=(starw05) to min(stopw05,begwk05,bweek5-1,bweek5l1-1,eweek5+1,eweek5l1+1);
job5wks=-3;
end;
end;
if stopf_5=1 then do;
do i=max(starw05,endwk05,bweek5-1,bweek5l1-1,eweek5+1,eweek5l1+1) to (stopw05);
job5wks=-3;
end;
end;
end; end;
***********************************
*** TOTAL WEEKS WORKED ON JOB 6-10 ***
***********************************;
array starf_ starf_6-starf_10;
array stopf_ stopf_6-stopf_10;
array uid_ uid06-uid10;
array starw_ starw06-starw10;
array stopw_ stopw06-stopw10;
array jobwks job6wks job7wks job8wks job9wks job10wks;
do over starf_;
starf_=0; stopf_=0;
if starw_=-3 and uid_ ne -5 then do; starw_=rd7wk; starf_=1; end;
if stopw_=-3 and uid_ ne -5 then do; stopw_=r7int; stopf_=1; end;
/*no smof=1 or emof=1 for these jobs*/
if starw_>0 and stopw_>0 then do;
do i=(starw_) to (stopw_);
jobwks=1;
end; end;
if starf_=1 then do;
do i=(starw_) to (stopw_);
jobwks=-3;
end;
end;
if stopf_=1 then do;
do i=(starw_) to (stopw_);
jobwks=-3;
end;
end;
end;
***************************
** Calulate Age 18 year **
***************************;
AGE18YR=birthyr+18;
if age18yr=1997 then ag18jan=888;
if age18yr=1998 then ag18jan=940;
if age18yr=1999 then ag18jan=992;
if age18yr=2000 then ag18jan=1044;
if age18yr=2001 then ag18jan=1097;
if age18yr=2002 then ag18jan=1149;
if age18yr=2003 then ag18jan=1200;
end;