loop #i=1 to 8.
loop #j=1 to 4.
if ((birdat(5*#i-4+#j)-birdat(5*#i-4) ge 273) or (birdat(5*#i-4)-birdat(5*#i-4+#j) ge
273))bunched=1.
end loop.
end loop.
*Flag up all cases where there is an ongoing pregnancy.
compute stilpreg=0.
format stilpreg (f1.0).
loop #i=1 to 40.
if (vprega(#i)=5)stilpreg=1.
end loop.
* Get all valid birth dates in chronological order, up to a maximum of 8 births.
* Use 'key' vector to keep track of which birthslot the date was originally placed in, so as to
* line up all the other pregnancy variables corresponding with this birth into their correct slots.
* After each of the 8 iterations resulting in determining a 'key' number, set the outcome date
* for the slot that key points to, to zero, so it will no longer be the most recent in the next
iteration.
loop #j=1 to 8.
compute outdat(#j)=0.
compute key(#j)=0.
loop #i=1 to 40.
Do if (birdat(#i)>outdat(#j)).
compute outdat(#j)=birdat(#i).
compute key(#j)=#i.
end if.
end loop.
if (key(#j) ne 0)birdat(key(#j))=0.
end loop.
* As a check that everything worked OK, look at whether any birdat values are still non-zero.
compute missdany=0.
format missdany (f1.0).
loop #i=1 to 40.
If (birdat(#i) ne 0)missdany=1.
end loop.
* Create variable truemult to flag up all cases with true multiple births: i.e. those where the
outcome date is the same,
* or no more than 3 days apart.
compute truemult=0.
format truemult (f1.0).
loop #i=1 to 7.
if ((outdat(#i)-outdat(#i+1) le 3) and (outdat(#i+1) ne 0))truemult=1.
end loop.
* Create warning flag variable oddmult to flag outcome dates less than nine months apart, but
greater than 3 days apart.
compute oddmult=0.