Return to Appendix 2 main file
**************************************************************
** Preliminary information, setting up arrays, etc. **
**************************************************************;
data emp_bday (keep=pubid birthwk age14wk age18wk ag18jan age20wk);
set two (keep=pubid birthyr birthmo birthdy); by pubid;
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;
data emp_int(keep=pubid r1int r2int r3int r4int r5int r6int r7int r8int);
set two(keep=pubid r1int_m r1int_d r1int_y r2int_m r2int_d r2int_y
r3int_m r3int_d r3int_y r4int_m r4int_d r4int_y
r5int_m r5int_d r5int_y r6int_m r6int_d r6int_y
r7int_m r7int_d r7int_y r8int_m r8int_d r8int_y); by pubid;
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);
if r8int_y>0 then r8mdy=mdy(r8int_m,r8int_d,r8int_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)+1; if r7int=. then r7int=-4;
r8int=intck('week',begmdy,r8mdy)+1; if r8int=. then r8int=-5;
if pubid=7315 then r1int=918;
data emp_week;
merge two emp_bday emp_int; by pubid;
if R8int>-5;
/* Establish dli week*/
if r7int_y>0 then do;
dli_y=r7int_y;
dli_m=r7int_m;
dli_d=r7int_d;
dliwk=r7int;
end;
if r7int_y=-5 and r6int_y>0 then do;
dli_y=r6int_y;
dli_m=r6int_m;
dli_d=r6int_d;
dliwk=r6int;
end;
if r7int_y=-5 and r6int_y=-5 and r5int_y>0 then do;
dli_y=r5int_y;
dli_m=r5int_m;
dli_d=r5int_d;
dliwk=r5int;
end;
if r7int_y=-5 and 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;
end;
if r7int_y=-5 and 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;
end;
if r7int_y=-5 and 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;
end;
if r7int_y=-5 and 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;
end;
/* ostartm represents the "old" start dates, and startm the start dates with
imputed values */
array ostartm (j) &R8STAM;
array ostartd (j) &R8STAD;
array ostarty (j) &R8STAY;
array ostopm (j) &R8STOM;
array ostopd (j) &R8STOD;
array ostopy (j) &R8STOY;
array UID (j) &R8UID;
array self (j) &R8SEL;
array milflag (j) &R8MIL;
array startm (j) starm01-starm07;
array startd (j) stard01-stard07;
array starty (j) stary01-stary07;
array stopm (j) stopm01-stopm07;
array stopd (j) stopd01-stopd07;
array stopy (j) stopy01-stopy07;
array smofl (j) smof01-smof07; /* dummy equals 1 when a start month is imputed
*/
array emofl (j) emof01-emof07; /* dummy equals 1 when a stop month is imputed */
array _strmdy (j) _strmdy01-_strmdy07;
array _stpmdy (j) _stpmdy01-_stpmdy07;
array _startwk (j) starw01-starw07;
array _stopwk (j) stopw01-stopw07;
begmdy=mdy(01,01,1980);
do j=1 to 7;
if uid ge 9701 then do;
if ostartm>0 and ostartd>0 and ostarty>1979 then _strmdy=mdy(ostartm,ostartd,ostarty);
if ostartm>0 and ostartd in (-1,-2,-3) and ostarty>1979 then _strmdy=mdy(ostartm,1,ostarty);
if ostartm in (-1,-2,-3) and ostartd>0 and ostarty>1979 then _strmdy=mdy(1,ostartd,ostarty);
if ostartm in (-1,-2,-3) and ostartd in (-1,-2,-3) and ostarty>1979 then _strmdy=mdy(1,1,ostarty);
if ostopm>0 and ostopd>0 and ostopy>1979 then _stpmdy=mdy(ostopm,ostopd,ostopy);
if ostopm>0 and ostopd in (-1,-2,-3) and ostopy>1979 then _stpmdy=mdy(ostopm,28,ostopy);
if ostopm in (-1,-2,-3) and ostopd>0 and ostopy>1979 then _stpmdy=mdy(12,ostopd,ostopy);
if ostopm in (-1,-2,-3) and ostopd in (-1,-2,-3) and ostopy>1979 then _stpmdy=mdy(12,28,ostopy);
if _strmdy>0 then _startwk=intck('week',begmdy,_strmdy)+1;
if _stpmdy>0 then _stopwk =intck('week',begmdy,_stpmdy)+1;
if 9701 le uid<200400 and _startwk>0 and dliwk>_startwk then _startwk=dliwk;
if 9701 le uid<200400 and _stopwk>0 and dliwk>_stopwk then _stopwk=dliwk;
/*for jobs with start/stop on/after r8int set start/stop to week before r8int*/
if _stopwk ge r8int then _stopwk=r8int-1;
if _startwk ge r8int then _startwk=r8int-1;
if ostarty in (-1,-2,-3,-4) then _startwk=-3;
if ostopy in (-1,-2,-3,-4) then _stopwk=-3;
if _startwk>0 and _stopwk>0 and _startwk>_stopwk then _startwk=_stopwk;
end;
end;
/* Define new start and stop dates */
do j=1 to 7; if uid ge 9701 then do;
startm=ostartm;
startd=ostartd;
starty=ostarty;
stopm=ostopm;
stopd=ostopd;
stopy=ostopy;
end; 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 (j) flag101-flag107;
array flag2 (j) flag201-flag207;
array flag3 (j) flag301-flag307;
array flag4 (j) flag401-flag407;
array flag5 (j) flag501-flag507;
array flag6 (j) flag601-flag607;
/* 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;
if startm>0 and startd<=0 then do;
startd=1;
flag1=1;
end;
if startm<=0 and startd>0 then do;
startm=1;
flag2=1;
smofl=1;
end;
if startm<=0 and startd<=0 then do;
startm=1;
startd=1;
flag3=1;
smofl=1;
end;
end;
end;
do over stopy;
if stopy>0 then do;
if stopm>0 and stopd<=0 then do;
stopd=28;
flag4=1;
end;
if stopm<=0 and stopd>0 then do;
stopm=12;
flag5=1;
emofl=1;
end;
if stopm<=0 and stopd<=0 then do;
stopm=12;
stopd=28;
flag6=1;
emofl=1;
end;
/* The following lines prevent values for stop months and days to exceed the
Round 8 interview date. */
if stopy=r8int_y and stopm=r8int_m and stopd>r8int_d then do;
stopd=r8int_d;
end;
if stopy=r8int_y and stopm>r8int_m then do;
stopm=r8int_m;
stopd=r8int_d;
end;
end;
end;
/* All jobs reported in earlier rounds (UID's begin with
97,98,1999,2000,2001,2002,2003)
have their startdates updated to the dli interview date.*/
do j=1 to 7;
if 9700<uid<200400 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;
end;
if starty=dli_y and startm<dli_m and starty>0 then do;
startm=dli_m;
startd=dli_d;
end;
if starty<dli_y and starty>0 then do;
starty=dli_y;
startm=dli_m;
startd=dli_d;
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. No jobs are affected in 2004. */
array bself (j) bself01-bself07;
do over _startwk;
if milflag ne 1 and self=1 and 0<_startwk<=(ag18jan-1) then do;
bself=1;
end;
end;
/* Check for back-reporters, i.e. people that report a new job (UID>200400)
that begins before the last interview date. */
do over UID;
if milflag ne 1 and uid>200400 then do;
if _startwk<r7int and _startwk>0 and r7int=dliwk then do;
back7=1;
end;
if _startwk<r6int and _startwk>0 and r6int=dliwk then do;
back6=1;
end;
if _startwk<r5int and _startwk>0 and r5int=dliwk then do;
back5=1;
end;
if _startwk<r4int and _startwk>0 and r4int=dliwk then do;
back4=1;
end;
if _startwk<r3int and _startwk>0 and r3int=dliwk then do;
back3=1;
end;
if _startwk<r2int and _startwk>0 and r2int=dliwk then do;
back2=1;
end;
if _startwk<r1int and _startwk>0 and r1int=dliwk then do;
back1=1;
end;
end;
end;
array br (j) br01-br07;
back=0;
do over UID;
if milflag ne 1 and uid>200400 and _startwk<dliwk and _startwk>0 and dliwk>0
then do;
back=back+1;
br=1;
end;
end;
data emp_gaps; merge two emp_bday emp_int emp_week; by pubid;
if r8int>-5;
/* ENT BEG DATE (SELF-EMP WJGAP),1 ENT BEG DT +1 GAP S-EMP WJGAP,2-3*/
array sbgdy &E10591201D &E10591402D &E10591403D;
array sbgmo &E10591201M &E10591402M &E10591403M;
array sbgyr &E10591201Y &E10591402Y &E10591403Y;
array segdy &E10591601D &E10591602D &E10591603D;
array segmo &E10591601M &E10591602M &E10591603M;
array segyr &E10591601Y &E10591602Y &E10591603Y;
/* ENT BEG M/D/Y WJGAP,1 ENT BEG M/D/Y NEXT WJGAP,2-12*/
array bgdy &E10220001D &E10240002D &E10240003D &E10240004D &E10240005D
&E10240006D
&E10240007D &E10240008D &E10240009D &E10240010D &E10240011D &E10240012D;
array bgmo &E10220001M &E10240002M &E10240003M &E10240004M &E10240005M
&E10240006M
&E10240007M &E10240008M &E10240009M &E10240010M &E10240011M &E10240012M;
array bgyr &E10220001Y &E10240002Y &E10240003Y &E10240004Y &E10240005Y
&E10240006Y
&E10240007Y &E10240008Y &E10240009Y &E10240010Y &E10240011Y &E10240012Y;
array egdy &E10270001D &E10270002D &E10270003D &E10270004D &E10270005D
&E10270006D
&E10270007D &E10270008D &E10270009D &E10270010D &E10270011D &E10270012D;
array egmo &E10270001M &E10270002M &E10270003M &E10270004M &E10270005M
&E10270006M
&E10270007M &E10270008M &E10270009M &E10270010M &E10270011M &E10270012M;
array egyr &E10270001Y &E10270002Y &E10270003Y &E10270004Y &E10270005Y
&E10270006Y
&E10270007Y &E10270008Y &E10270009Y &E10270010Y &E10270011Y &E10270012Y;
array bgfl &BGFL_01 &BGFL_02 &BGFL_03 &BGFL_04 &BGFL_05 &BGFL_06
&BGFL_07 &BGFL_08 &BGFL_09 &BGFL_10 &BGFL_11 &BGFL_12;
array egfl &EGFL_01 &EGFL_02 &EGFL_03 &EGFL_04 &EGFL_05 &EGFL_06
&EGFL_07 &EGFL_08 &EGFL_09 &EGFL_10 &EGFL_11 &EGFL_12;
/*YEMP SELF EMPLOYED (ROS ITEM)*/
array self &R8sel &R8sel &R8sel &R8sel &R8sel &R8sel
&R8sel &R8sel &R8sel &R8sel &R8sel &R8sel;
array UID &R8UID &R8UID &R8UID &R8UID &R8UID &R8UID
&R8UID &R8UID &R8UID &R8UID &R8UID &R8UID;
array milflag &R8MIL &R8MIL &R8MIL &R8MIL &R8MIL &R8MIL
&R8MIL &R8MIL &R8MIL &R8MIL &R8MIL &R8MIL;
array stary &R8STAY &R8STAY &R8STAY &R8STAY &R8STAY &R8STAY
&R8STAY &R8STAY &R8STAY &R8STAY &R8STAY &R8STAY;
array starm &R8STAM &R8STAM &R8STAM &R8STAM &R8STAM &R8STAM
&R8STAM &R8STAM &R8STAM &R8STAM &R8STAM &R8STAM;
array stard &R8STAD &R8STAD &R8STAD &R8STAD &R8STAD &R8STAD
&R8STAD &R8STAD &R8STAD &R8STAD &R8STAD &R8STAD;
array stopy &R8STOY &R8STOY &R8STOY &R8STOY &R8STOY &R8STOY
&R8STOY &R8STOY &R8STOY &R8STOY &R8STOY &R8STOY;
array stopm &R8STOM &R8STOM &R8STOM &R8STOM &R8STOM &R8STOM
&R8STOM &R8STOM &R8STOM &R8STOM &R8STOM &R8STOM;
array stopd &R8STOD &R8STOD &R8STOD &R8STOD &R8STOD &R8STOD
&R8STOD &R8STOD &R8STOD &R8STOD &R8STOD &R8STOD;
array starw &STARW &STARW &STARW &STARW &STARW &STARW
&STARW &STARW &STARW &STARW &STARW &STARW;
array stopw &stopW &stopW &stopW &stopW &stopW &stopW
&stopW &stopW &stopW &stopW &stopW &stopW;
array smof &smof &smof &smof &smof &smof &smof
&smof &smof &smof &smof &smof &smof;
array emof &emof &emof &emof &emof &emof &emof
&emof &emof &emof &emof &emof &emof;
/* use the self-employed gap information if it is a self-employed job.
gap dates now include both self- and regular employment*/
do over sbgdy;
if sbgdy>-4 then bgdy = sbgdy;
if sbgmo>-4 then bgmo = sbgmo;
if sbgyr>-4 then bgyr = sbgyr;
if segdy>-4 then egdy = segdy;
if segmo>-4 then egmo = segmo;
if segyr>-4 then egyr = segyr;
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 bgdy=1;
if bgyr=stary and bgmo=starm and bgdy<stard then bgdy=stard;
end;
end;
do over egyr;
if egyr>0 then do;
if egmo>0 and egdy<=0 then egdy=1;
if egyr=stopy and egmo=stopm and egdy>stopd then egdy=stopd;
end;
end;
/*Set flag for valid job with gap that exists but has invalid dates*/
do over bgyr;
if milflag ne 1 and ((-4 < bgmo < 0) or (-4 < bgyr <0)) then bgfl=1;
if milflag ne 1 and ((-4 < egyr < 0) or (-4 < egmo < 0)) then egfl=1;
end;
array _bgmdy &_BGMDY_01 &_BGMDY_02 &_BGMDY_03 &_BGMDY_04 &_BGMDY_05 &_BGMDY_06
&_BGMDY_07 &_BGMDY_08 &_BGMDY_09 &_BGMDY_10 &_BGMDY_11 &_BGMDY_12;
array _egmdy &_EGMDY_01 &_EGMDY_02 &_EGMDY_03 &_EGMDY_04 &_EGMDY_05 &_EGMDY_06
&_EGMDY_07 &_EGMDY_08 &_EGMDY_09 &_EGMDY_10 &_EGMDY_11 &_EGMDY_12;
array _gdays &_gdays_01 &_gdays_02 &_gdays_03 &_gdays_04 &_gdays_05 &_gdays_06
&_gdays_07 &_gdays_08 &_gdays_09 &_gdays_10 &_gdays_11 &_gdays_12;
array _bgap &BGAP_01 &BGAP_02 &BGAP_03 &BGAP_04 &BGAP_05 &BGAP_06
&BGAP_07 &BGAP_08 &BGAP_09 &BGAP_10 &BGAP_11 &BGAP_12;
array _egap &EGAP_01 &EGAP_02 &EGAP_03 &EGAP_04 &EGAP_05 &EGAP_06
&EGAP_07 &EGAP_08 &EGAP_09 &EGAP_10 &EGAP_11 &EGAP_12;
begmdy=mdy(01,01,1980);
dlimdy=mdy(dli_m,dli_d,dli_y);
do over bgyr;
if milflag ne 1 and uid ge 9701 then do;
/*Count the number of days from January 1, 1960 (=0), to the gap begin and end
dates.*/
if bgmo>0 and bgdy>0 and bgyr>1979 then _bgmdy=mdy(bgmo,bgdy,bgyr);
/*Fill missing gap begin day with 1*/
if bgmo>0 and bgdy in (-1,-2,-3) and bgyr>1979 then _bgmdy=mdy(bgmo,1,bgyr);
if egmo>0 and egdy>0 and egyr>1979 then _egmdy=mdy(egmo,egdy,egyr);
/*Fill missing gap end day with 28*/
if egmo>0 and egdy in (-1,-2,-3) and egyr>1979 then _egmdy=mdy(egmo,28,egyr);
/*And count the number of days in the gap*/
if _egmdy>0 and _bgmdy>0 then _gdays=_egmdy-_bgmdy+1;
/* The following line omits gap start and stop dates for gaps less than one
work week (5 days) */
if _gdays ne . and _gdays<5 then do; _bgap=.; _egap=.; end;
/*Count the number of weeks from Jan 1 1980 to gap begin week
and to gap end week to set the week numbers*/
if _bgmdy>0 then _bgap=intck('week',begmdy,_bgmdy)+1;
if _egmdy>0 then _egap =intck('week',begmdy,_egmdy)+1;
/* an entire gap before dli week will be disregarded,
a gap begin before dli is reset to dli. */
if _egap>dliwk and _bgap>0 and _bgap<dliwk then _bgap=dliwk;
if _egap>0 and _egap<dliwk then do; _bgap=.; _egap=.; end;
/* A gap that ends on/after the interview week is reset to the interview week.
*/
if _egap ge r8int then _egap=r8int;
/*Recode the gap begin week and the gap end week to eliminate partial weeks
working*/
_bgap=_bgap+1; _egap=_egap-1;
if _bgap>0 and _egap>0 and _bgap>_egap then _bgap=_egap;
end;
end;
data emp_countweeks;
merge two emp_bday emp_int emp_week emp_gaps; by pubid; if r8int>-5;
array job1wks (i) w1_1-w1_1335;
array job2wks (i) w2_1-w2_1335;
array job3wks (i) w3_1-w3_1335;
array job4wks (i) w4_1-w4_1335;
array job5wks (i) w5_1-w5_1335;
array job6wks (i) w6_1-w6_1335;
array job7wks (i) w7_1-w7_1335;
/* Define rd8wk as the maximum of dliwk and age14wk. This is used for missing
start/stop weeks. */
if dliwk>0 then do;
if dliwk>age14wk then do;
rd8wk=dliwk;
end;
if age14wk=>dliwk then do;
rd8wk=age14wk;
end;
end;
***********************************
*** TOTAL WEEKS WORKED
***********************************;
array starf starf_1-starf_7;
array stopf stopf_1-stopf_7;
array starw &starw;
array stopw &stopw;
array stary &R8STAY;
array stopy &R8STOY;
array smof &smof;
array emof &emof;
array bself bself01-bself07;
array endwk endwk01-endwk07;
array begwk begwk01-begwk07;
array bweek1 &bgap_01;
array eweek1 &egap_01;
array bflag1 &bgfl_01;
array eflag1 &egfl_01;
array bweek2 &bgap_02;
array eweek2 &egap_02;
array bflag2 &bgfl_02;
array eflag2 &egfl_02;
array bweek3 &bgap_03;
array eweek3 &egap_03;
array bweek4 &bgap_04;
array eweek4 &egap_04;
array bweek5 &bgap_05;
array eweek5 &egap_05;
array bweek6 &bgap_06;
array eweek6 &egap_06;
array bweek7 &bgap_07;
array eweek7 &egap_07;
array bweek8 &bgap_08;
array eweek8 &egap_08;
array bweek9 &bgap_09;
array eweek9 &egap_09;
array bweek10 &bgap_10;
array eweek10 &egap_10;
array bweek11 &bgap_11;
array eweek11 &egap_11;
array bweek12 &bgap_12;
array eweek12 &egap_12;
array milflag &R8mil;
array jobwks job1wks job2wks job3wks job4wks job5wks job6wks job7wks;
do over starf;
if milflag=1 then do; starw=.; stopw=.; end;
if starw=-3 then do; starw=rd8wk; starf=1; end;
if stopw=-3 then do; stopw=r8int-1; stopf=1; end; *using week before intwk;
if smof=1 and bself ne 1 then do; starf=1;
if stary=1980 then begwk=52;
if stary=1981 then begwk=104;
if stary=1982 then begwk=156;
if stary=1983 then begwk=209;
if stary=1984 then begwk=261;
if stary=1985 then begwk=313;
if stary=1986 then begwk=365;
if stary=1987 then begwk=417;
if stary=1988 then begwk=470;
if stary=1989 then begwk=522;
if stary=1990 then begwk=574;
if stary=1991 then begwk=626;
if stary=1992 then begwk=678;
if stary=1993 then begwk=730;
if stary=1994 then begwk=783;
if stary=1995 then begwk=835;
if stary=1996 then begwk=887;
if stary=1997 then begwk=939;
if stary=1998 then begwk=991;
if stary=1999 then begwk=1043;
if stary=2000 then begwk=1096;
if stary=2001 then begwk=1148;
if stary=2002 then begwk=1200;
if stary=2003 then begwk=1252;
if stary=2004 then begwk=1304;
if stary=2005 then begwk=1356;
end;
if emof=1 then do; stopf=1;
if stopy=1980 then endwk=1;
if stopy=1981 then endwk=53;
if stopy=1982 then endwk=105;
if stopy=1983 then endwk=157;
if stopy=1984 then endwk=210;
if stopy=1985 then endwk=262;
if stopy=1986 then endwk=314;
if stopy=1987 then endwk=366;
if stopy=1988 then endwk=418;
if stopy=1989 then endwk=471;
if stopy=1990 then endwk=523;
if stopy=1991 then endwk=575;
if stopy=1992 then endwk=627;
if stopy=1993 then endwk=679;
if stopy=1994 then endwk=731;
if stopy=1995 then endwk=784;
if stopy=1996 then endwk=836;
if stopy=1997 then endwk=888;
if stopy=1998 then endwk=940;
if stopy=1999 then endwk=992;
if stopy=2000 then endwk=1044;
if stopy=2001 then endwk=1097;
if stopy=2002 then endwk=1149;
if stopy=2003 then endwk=1201;
if stopy=2004 then endwk=1253;
if stopy=2005 then endwk=1305;
end;
end;
do over starw;
do i=1 to 1335;
jobwks=0;
end;
if starw>0 and stopw>0 then do;
do i=(starw) to (stopw);
jobwks=1;
end; end; end;
do over bweek1;
if bweek1>0 and eweek1>0 then do;
do i=(bweek1) to (eweek1);
jobwks=0;
end; end;
/*Note no cases with a flagged gapend have a later gap*/
if starw ne . and bflag1=1 and eweek1>0 then do;
do i=(starw) to (eweek1);
jobwks=-3;
end; end;
if stopw ne . and bweek1>0 and eflag1=1 then do;
do i=(bweek1) to (stopw);
jobwks=-3;
end; end;
if starw ne . and bflag1=1 and eflag1=1 then do;
do i=(starw) to (stopw);
jobwks=-3;
end; end;
if bweek2>0 and eweek2>0 then do;
do i=(bweek2) to (eweek2);
jobwks=0;
end; end;
if starw ne . and bflag2=1 and eweek2>0 then do;
do i=(starw) to (eweek2);
jobwks=-3;
end; end;
if stopw ne . and bweek2>0 and eflag2=1 then do;
do i=(bweek2) to (stopw);
jobwks=-3;
end; end;
if starw ne . and bflag2=1 and eflag2=1 then do;
do i=(starw) to (stopw);
jobwks=-3;
end; end;
if bweek3>0 & eweek3>0 then do;
do i=(bweek3) to (eweek3);
jobwks=0;
end; end;
if bweek4>0 & eweek4>0 then do;
do i=(bweek4) to (eweek4);
jobwks=0;
end; end;
if bweek5>0 & eweek5>0 then do;
do i=(bweek5) to (eweek5);
jobwks=0;
end; end;
if bweek6>0 & eweek6>0 then do;
do i=(bweek6) to (eweek6);
jobwks=0;
end; end;
if bweek7>0 & eweek7>0 then do;
do i=(bweek7) to (eweek7);
jobwks=0;
end; end;
if bweek8>0 & eweek8>0 then do;
do i=(bweek8) to (eweek8);
jobwks=0;
end; end;
if bweek9>0 & eweek9>0 then do;
do i=(bweek9) to (eweek9);
jobwks=0;
end; end;
if bweek10>0 & eweek10>0 then do;
do i=(bweek10) to (eweek10);
jobwks=0;
end; end;
if bweek11>0 & eweek11>0 then do;
do i=(bweek11) to (eweek11);
jobwks=0;
end; end;
if bweek12>0 & eweek12>0 then do;
do i=(bweek12) to (eweek12);
jobwks=0;
end; end; end;
do over starf;
if starf=1 then do;
do i=(starw) to min(stopw,begwk,bweek1-1,bweek2-1,eweek1+1,eweek2+1);
jobwks=-3;
end; end;
if stopf=1 then do;
do i=max(starw,endwk,bweek1-1,bweek2-1,eweek1+1,eweek2+1) to (stopw);
jobwks=-3;
end; end;
end;