Mother's Age at First Birth/Respondent's Birth

National Longitudinal Survey of Youth - 1997 Cohort

Mother's Age at First Birth/Respondent's Birth

These variables were only created in Round 1.

Variables Created

  • CV_BIO_MOM_AGE_CHILD1 
  • CV_BIO_MOM_AGE_YOUTH

This program creates two variables which identify the age of the youth’s biological mother when she gave birth to her first child and when the youth was born. Note that this program uses data from the Round 1 Parent Questionnaire, so it is only available for respondents who have a completed parent interview.

Variables Used

/*Variable Names in Program    Variable Names in Gator*/     

  pubid                        PUBID
  saq13                        YSAQ-013
  saq14                        YSAQ-014
  saq34                        YSAQ-034
  saq35                        YSAQ-035
  yid                          YOUTH_ID.01
  YMOMID                       YOUTH_MOMID.01
  YNRMOMID                     YOUTH_NRMOMID.01
  birthd, m, y                 KEY!BDATE_D, _M, Y
  yAGE                         KEY!AGE
  PNRMOMID                     PARYOUTH_MOMID
  ScrD, M, Y                   SE-1_D, _M, _Y
  SN701-05                     SN-70.01-.05
  SN761-3                      SN-76.01-.03
  SN791-3                      SN-79.01-.03
  AGE1-16                      HHI2_AGE.01-.16
  DOBD1-15                     HHI2_DOB.01_D-.15_D
  DOBM1-15                     HHI2_DOB.01_M-.15_M
  DOBY1-15                     HHI2_DOB.01_Y-.15_Y
  REL1_1-16                    HHI2_REL1.01-.16
  REL10_1-16                   HHI2_REL10.01-10.16
  REL11_1-16                   HHI2_REL11.01-11.16
  REL12_1-16                   HHI2_REL12.01-.16
  REL13_1-16                   HHI2_REL13.02-.16
  REL14_1-16                   HHI2_REL14.01-.16
  REL15_1-16                   HHI2_REL15.01-.16
  REL16_1-16                   HHI2_REL16.01-.16
  REL2_1-16                    HHI2_REL2.01-.16
  REL3_1-16                    HHI2_REL3.01-.16
  REL4_1-16                    HHI2_REL4.01-.16
  REL5_1-16                    HHI2_REL5.01-.16
  REL6_1-16                    HHI2_REL6.01-.16
  REL7_1-16                    HHI2_REL7.01-.16
  REL8_1-16                    HHI2_REL8.01-.16
  REL9_1-16                    HHI2_REL9.01-.16
  NAGE1-23                     NONHHI_AGE.01-.23
  NREL1-21                     NONHHI_RELATION.01-.21
  PI017                        PINF-017
  PI018                        PINF-018
  PI020                        PINF-020
  PI025                        PINF-025
  PI0455                       PINF-045_005
  PI058D, M, Y                 PINF-058_D, _M, _Y
  gender1-16                   HHI2_SEX.01-.16
  ngend1-23                    NONHHI_SEX.01-.23

SAS Code for Variable Creation

/* We first establish the relationship between youth and biomom */
/* these are people that say they live with a bio mom - need to figure out what to do when R believe bio mom in hh but not */

agemomfy=-3;
smomage=-3;
momage=-3;
momid=-3;

array rela1 (i) rel1_1-rel1_19;
array rela2 (i) rel2_1-rel2_19;
array rela3 (i) rel3_1-rel3_19;
array rela4 (i) rel4_1-rel4_19;
array rela5 (i) rel5_1-rel5_19;
array rela6 (i) rel6_1-rel6_19;
array rela7 (i) rel7_1-rel7_19;
array rela8 (i) rel8_1-rel8_19;
array rela9 (i) rel9_1-rel9_19;
array rela10 (i) rel10_1-rel10_19;
array rela11 (i) rel11_1-rel11_19;
array rela12 (i) rel12_1-rel12_19;
array rela13 (i) rel13_1-rel13_19;
array rela14 (i) rel14_1-rel14_19;
array rela15 (i) rel15_1-rel15_19;
array rela16 (i) rel16_1-rel16_19;
array rela17 (i) rel17_1-rel17_19;
array rela18 (i) rel18_1-rel18_19;
array rela19 (i) rel19_1-rel19_19;
array parid (i) parid1-parid19;

/* put in corrects from parent */

do i=1 to 19;
   if yid=1 then do;
      if rela1=49 or rela1=50 then do;
         parid=1;
      end;
   end;
   if yid=2 then do;
      if rela2=49 or rela2=50 then do;
         parid=1;
      end;
   end;
   if yid=3 then do;
      if rela3=49 or rela3=50 then do;
         parid=1;
      end;
   end;
   if yid=4 then do;
      if rela4=49 or rela4=50 then do;
         parid=1;
      end;
   end;
   if yid=5 then do;
      if rela5=49 or rela5=50 then do;
         parid=1;
      end;
   end;
end;

*correct youth's age;
if yid=1 then do;
   if birthm>scrm or (birthm=scrm and birthd>scrd) then do;
      age1=scry-birthy-1;
   end;
   if (birthm<=scrm or (birthm=scrm and birthd<=scrd)) then do;
      age1=scry-birthy;
   end;
end;

if yid=2 then do;
   if birthm>scrm or (birthm=scrm and birthd>scrd) then do;
      age2=scry-birthy-1;
   end;
   if (birthm<=scrm or (birthm=scrm and birthd<=scrd)) then do;
      age2=scry-birthy;
   end;
end;
   
if yid=3 then do;
   if birthm>scrm or (birthm=scrm and birthd>scrd) then do;
      age3=scry-birthy-1;
   end;
   if (birthm<=scrm or (birthm=scrm and birthd<=scrd)) then do;
      age3=scry-birthy;
   end;
end;

if yid=4 then do;
   if birthm>scrm or (birthm=scrm and birthd>scrd) then do;
      age4=scry-birthy-1;
   end;
   if (birthm<=scrm or (birthm=scrm and birthd<=scrd)) then do;
      age4=scry-birthy;
   end;
end;

if yid=5 then do;
   if birthm>scrm or (birthm=scrm and birthd>scrd) then do;
      age5=scry-birthy-1;
   end;
   if (birthm<=scrm or (birthm=scrm and birthd<=scrd)) then do;
      age5=scry-birthy;
   end;
end;

do i=1 to 19;
   if yid=1 then do;
      if parid19=1 and rel19_1=3 and gender19=2 then momid=19;
      if parid18=1 and rel18_1=3 and gender18=2 then momid=18;
      if parid17=1 and rel17_1=3 and gender17=2 then momid=17;
      if parid16=1 and rel16_1=3 and gender16=2 then momid=16;
      if parid15=1 and rel15_1=3 and gender15=2 then momid=15;
      if parid14=1 and rel14_1=3 and gender14=2 then momid=14;
      if parid13=1 and rel13_1=3 and gender13=2 then momid=13;
      if parid12=1 and rel12_1=3 and gender12=2 then momid=12;
      if parid11=1 and rel11_1=3 and gender11=2 then momid=11;
      if parid10=1 and rel10_1=3 and gender10=2 then momid=10;
      if parid9=1 and rel9_1=3 and gender9=2 then momid=9;
      if parid8=1 and rel8_1=3 and gender8=2 then momid=8;
      if parid7=1 and rel7_1=3 and gender7=2 then momid=7;
      if parid6=1 and rel6_1=3 and gender6=2 then momid=6;
      if parid5=1 and rel5_1=3 and gender5=2 then momid=5;
      if parid4=1 and rel4_1=3 and gender4=2 then momid=4;
      if parid3=1 and rel3_1=3 and gender3=2 then momid=3;
      if parid2=1 and rel2_1=3 and gender2=2 then momid=2;
      if parid1=1 and rel1_1=3 and gender1=2 then momid=1;
   end;
   if yid=2 then do;
      if parid19=1 and rel19_2=3 and gender19=2 then momid=19;   
      if parid18=1 and rel18_2=3 and gender18=2 then momid=18;   
      if parid17=1 and rel17_2=3 and gender17=2 then momid=17;   
      if parid16=1 and rel16_2=3 and gender16=2 then momid=16;   
      if parid15=1 and rel15_2=3 and gender15=2 then momid=15;   
      if parid14=1 and rel14_2=3 and gender14=2 then momid=14;   
      if parid13=1 and rel13_2=3 and gender13=2 then momid=13;   
      if parid12=1 and rel12_2=3 and gender12=2 then momid=12;   
      if parid11=1 and rel11_2=3 and gender11=2 then momid=11;   
      if parid10=1 and rel10_2=3 and gender10=2 then momid=10;   
      if parid9=1 and rel9_2=3 and gender9=2 then momid=9;      
      if parid8=1 and rel8_2=3 and gender8=2 then momid=8;      
      if parid7=1 and rel7_2=3 and gender7=2 then momid=7;      
      if parid6=1 and rel6_2=3 and gender6=2 then momid=6;      
      if parid5=1 and rel5_2=3 and gender5=2 then momid=5;      
      if parid4=1 and rel4_2=3 and gender4=2 then momid=4;      
      if parid3=1 and rel3_2=3 and gender3=2 then momid=3;      
      if parid2=1 and rel2_2=3 and gender2=2 then momid=2;      
      if parid1=1 and rel1_2=3 and gender1=2 then momid=1;      
   end;
   if yid=3 then do;
      if parid19=1 and rel19_3=3 and gender19=2 then momid=19;   
      if parid18=1 and rel18_3=3 and gender18=2 then momid=18;   
      if parid17=1 and rel17_3=3 and gender17=2 then momid=17;   
      if parid16=1 and rel16_3=3 and gender16=2 then momid=16;   
      if parid15=1 and rel15_3=3 and gender15=2 then momid=15;   
      if parid14=1 and rel14_3=3 and gender14=2 then momid=14;   
      if parid13=1 and rel13_3=3 and gender13=2 then momid=13;   
      if parid12=1 and rel12_3=3 and gender12=2 then momid=12;   
      if parid11=1 and rel11_3=3 and gender11=2 then momid=11;   
      if parid10=1 and rel10_3=3 and gender10=2 then momid=10;   
      if parid9=1 and rel9_3=3 and gender9=2 then momid=9;      
      if parid8=1 and rel8_3=3 and gender8=2 then momid=8;      
      if parid7=1 and rel7_3=3 and gender7=2 then momid=7;      
      if parid6=1 and rel6_3=3 and gender6=2 then momid=6;      
      if parid5=1 and rel5_3=3 and gender5=2 then momid=5;      
      if parid4=1 and rel4_3=3 and gender4=2 then momid=4;      
      if parid3=1 and rel3_3=3 and gender3=2 then momid=3;      
      if parid2=1 and rel2_3=3 and gender2=2 then momid=2;      
      if parid1=1 and rel1_3=3 and gender1=2 then momid=1;      
   end;
   if yid=4 then do;
      if parid19=1 and rel19_4=3 and gender19=2 then momid=19;   
      if parid18=1 and rel18_4=3 and gender18=2 then momid=18;   
      if parid17=1 and rel17_4=3 and gender17=2 then momid=17;   
      if parid16=1 and rel16_4=3 and gender16=2 then momid=16;   
      if parid15=1 and rel15_4=3 and gender15=2 then momid=15;   
      if parid14=1 and rel14_4=3 and gender14=2 then momid=14;   
      if parid13=1 and rel13_4=3 and gender13=2 then momid=13;   
      if parid12=1 and rel12_4=3 and gender12=2 then momid=12;   
      if parid11=1 and rel11_4=3 and gender11=2 then momid=11;   
      if parid10=1 and rel10_4=3 and gender10=2 then momid=10;   
      if parid9=1 and rel9_4=3 and gender9=2 then momid=9;      
      if parid8=1 and rel8_4=3 and gender8=2 then momid=8;      
      if parid7=1 and rel7_4=3 and gender7=2 then momid=7;      
      if parid6=1 and rel6_4=3 and gender6=2 then momid=6;      
      if parid5=1 and rel5_4=3 and gender5=2 then momid=5;      
      if parid4=1 and rel4_4=3 and gender4=2 then momid=4;      
      if parid3=1 and rel3_4=3 and gender3=2 then momid=3;      
      if parid2=1 and rel2_4=3 and gender2=2 then momid=2;      
      if parid1=1 and rel1_4=3 and gender1=2 then momid=1;      
   end;
   if yid=5 then do;
      if parid19=1 and rel19_5=3 and gender19=2 then momid=19;   
      if parid18=1 and rel18_5=3 and gender18=2 then momid=18;   
      if parid17=1 and rel17_5=3 and gender17=2 then momid=17;   
      if parid16=1 and rel16_5=3 and gender16=2 then momid=16;   
      if parid15=1 and rel15_5=3 and gender15=2 then momid=15;   
      if parid14=1 and rel14_5=3 and gender14=2 then momid=14;   
      if parid13=1 and rel13_5=3 and gender13=2 then momid=13;   
      if parid12=1 and rel12_5=3 and gender12=2 then momid=12;   
      if parid11=1 and rel11_5=3 and gender11=2 then momid=11;   
      if parid10=1 and rel10_5=3 and gender10=2 then momid=10;   
      if parid9=1 and rel9_5=3 and gender9=2 then momid=9;      
      if parid8=1 and rel8_5=3 and gender8=2 then momid=8;      
      if parid7=1 and rel7_5=3 and gender7=2 then momid=7;      
      if parid6=1 and rel6_5=3 and gender6=2 then momid=6;      
      if parid5=1 and rel5_5=3 and gender5=2 then momid=5;      
      if parid4=1 and rel4_5=3 and gender4=2 then momid=4;      
      if parid3=1 and rel3_5=3 and gender3=2 then momid=3;      
      if parid2=1 and rel2_5=3 and gender2=2 then momid=2;      
      if parid1=1 and rel1_5=3 and gender1=2 then momid=1;      
   end;
end;

do i=1 to 19;
   if momid=. and ymomid ne . then do;
      if yid=1 then do;
         if ymomid19=1 and rel19_1=3 and gender19=2 then momid=19;   
         if ymomid18=1 and rel18_1=3 and gender18=2 then momid=18;   
         if ymomid17=1 and rel17_1=3 and gender17=2 then momid=17;   
         if ymomid16=1 and rel16_1=3 and gender16=2 then momid=16;   
         if ymomid15=1 and rel15_1=3 and gender15=2 then momid=15;   
         if ymomid14=1 and rel14_1=3 and gender14=2 then momid=14;   
         if ymomid13=1 and rel13_1=3 and gender13=2 then momid=13;   
         if ymomid12=1 and rel12_1=3 and gender12=2 then momid=12;   
         if ymomid11=1 and rel11_1=3 and gender11=2 then momid=11;   
         if ymomid10=1 and rel10_1=3 and gender10=2 then momid=10;   
         if ymomid9=1 and rel9_1=3 and gender9=2 then momid=9;      
         if ymomid8=1 and rel8_1=3 and gender8=2 then momid=8;      
         if ymomid7=1 and rel7_1=3 and gender7=2 then momid=7;      
         if ymomid6=1 and rel6_1=3 and gender6=2 then momid=6;      
         if ymomid5=1 and rel5_1=3 and gender5=2 then momid=5;      
         if ymomid4=1 and rel4_1=3 and gender4=2 then momid=4;      
         if ymomid3=1 and rel3_1=3 and gender3=2 then momid=3;      
         if ymomid2=1 and rel2_1=3 and gender2=2 then momid=2;      
         if ymomid1=1 and rel1_1=3 and gender1=2 then momid=1;      
      end;
      if yid=2 then do;
         if ymomid19=1 and rel19_2=3 and gender19=2 then momid=19;   
         if ymomid18=1 and rel18_2=3 and gender18=2 then momid=18;   
         if ymomid17=1 and rel17_2=3 and gender17=2 then momid=17;   
         if ymomid16=1 and rel16_2=3 and gender16=2 then momid=16;   
         if ymomid15=1 and rel15_2=3 and gender15=2 then momid=15;   
         if ymomid14=1 and rel14_2=3 and gender14=2 then momid=14;   
         if ymomid13=1 and rel13_2=3 and gender13=2 then momid=13;   
         if ymomid12=1 and rel12_2=3 and gender12=2 then momid=12;   
         if ymomid11=1 and rel11_2=3 and gender11=2 then momid=11;   
         if ymomid10=1 and rel10_2=3 and gender10=2 then momid=10;   
         if ymomid9=1 and rel9_2=3 and gender9=2 then momid=9;      
         if ymomid8=1 and rel8_2=3 and gender8=2 then momid=8;      
         if ymomid7=1 and rel7_2=3 and gender7=2 then momid=7;      
         if ymomid6=1 and rel6_2=3 and gender6=2 then momid=6;      
         if ymomid5=1 and rel5_2=3 and gender5=2 then momid=5;      
         if ymomid4=1 and rel4_2=3 and gender4=2 then momid=4;      
         if ymomid3=1 and rel3_2=3 and gender3=2 then momid=3;      
         if ymomid2=1 and rel2_2=3 and gender2=2 then momid=2;      
         if ymomid1=1 and rel1_2=3 and gender1=2 then momid=1;      
      end;
      if yid=3 then do;
         if ymomid19=1 and rel19_3=3 and gender19=2 then momid=19;   
         if ymomid18=1 and rel18_3=3 and gender18=2 then momid=18;   
         if ymomid17=1 and rel17_3=3 and gender17=2 then momid=17;   
         if ymomid16=1 and rel16_3=3 and gender16=2 then momid=16;   
         if ymomid15=1 and rel15_3=3 and gender15=2 then momid=15;   
         if ymomid14=1 and rel14_3=3 and gender14=2 then momid=14;   
         if ymomid13=1 and rel13_3=3 and gender13=2 then momid=13;   
         if ymomid12=1 and rel12_3=3 and gender12=2 then momid=12;   
         if ymomid11=1 and rel11_3=3 and gender11=2 then momid=11;   
         if ymomid10=1 and rel10_3=3 and gender10=2 then momid=10;   
         if ymomid9=1 and rel9_3=3 and gender9=2 then momid=9;      
         if ymomid8=1 and rel8_3=3 and gender8=2 then momid=8;      
         if ymomid7=1 and rel7_3=3 and gender7=2 then momid=7;      
         if ymomid6=1 and rel6_3=3 and gender6=2 then momid=6;      
         if ymomid5=1 and rel5_3=3 and gender5=2 then momid=5;      
         if ymomid4=1 and rel4_3=3 and gender4=2 then momid=4;      
         if ymomid3=1 and rel3_3=3 and gender3=2 then momid=3;      
         if ymomid2=1 and rel2_3=3 and gender2=2 then momid=2;      
         if ymomid1=1 and rel1_3=3 and gender1=2 then momid=1;      
      end;
      if yid=4 then do;
         if ymomid19=1 and rel19_4=3 and gender19=2 then momid=19;   
         if ymomid18=1 and rel18_4=3 and gender18=2 then momid=18;   
         if ymomid17=1 and rel17_4=3 and gender17=2 then momid=17;   
         if ymomid16=1 and rel16_4=3 and gender16=2 then momid=16;   
         if ymomid15=1 and rel15_4=3 and gender15=2 then momid=15;   
         if ymomid14=1 and rel14_4=3 and gender14=2 then momid=14;   
         if ymomid13=1 and rel13_4=3 and gender13=2 then momid=13;   
         if ymomid12=1 and rel12_4=3 and gender12=2 then momid=12;   
         if ymomid11=1 and rel11_4=3 and gender11=2 then momid=11;   
         if ymomid10=1 and rel10_4=3 and gender10=2 then momid=10;   
         if ymomid9=1 and rel9_4=3 and gender9=2 then momid=9;      
         if ymomid8=1 and rel8_4=3 and gender8=2 then momid=8;      
         if ymomid7=1 and rel7_4=3 and gender7=2 then momid=7;      
         if ymomid6=1 and rel6_4=3 and gender6=2 then momid=6;      
         if ymomid5=1 and rel5_4=3 and gender5=2 then momid=5;      
         if ymomid4=1 and rel4_4=3 and gender4=2 then momid=4;      
         if ymomid3=1 and rel3_4=3 and gender3=2 then momid=3;      
         if ymomid2=1 and rel2_4=3 and gender2=2 then momid=2;      
         if ymomid1=1 and rel1_4=3 and gender1=2 then momid=1;      
      end;
      if yid=5 then do;
         if ymomid19=1 and rel19_5=3 and gender19=2 then momid=19;   
         if ymomid18=1 and rel18_5=3 and gender18=2 then momid=18;   
         if ymomid17=1 and rel17_5=3 and gender17=2 then momid=17;   
         if ymomid16=1 and rel16_5=3 and gender16=2 then momid=16;   
         if ymomid15=1 and rel15_5=3 and gender15=2 then momid=15;   
         if ymomid14=1 and rel14_5=3 and gender14=2 then momid=14;   
         if ymomid13=1 and rel13_5=3 and gender13=2 then momid=13;   
         if ymomid12=1 and rel12_5=3 and gender12=2 then momid=12;   
         if ymomid11=1 and rel11_5=3 and gender11=2 then momid=11;   
         if ymomid10=1 and rel10_5=3 and gender10=2 then momid=10;   
         if ymomid9=1 and rel9_5=3 and gender9=2 then momid=9;      
         if ymomid8=1 and rel8_5=3 and gender8=2 then momid=8;      
         if ymomid7=1 and rel7_5=3 and gender7=2 then momid=7;      
         if ymomid6=1 and rel6_5=3 and gender6=2 then momid=6;      
         if ymomid5=1 and rel5_5=3 and gender5=2 then momid=5;      
         if ymomid4=1 and rel4_5=3 and gender4=2 then momid=4;      
         if ymomid3=1 and rel3_5=3 and gender3=2 then momid=3;      
         if ymomid2=1 and rel2_5=3 and gender2=2 then momid=2;      
         if ymomid1=1 and rel1_5=3 and gender1=2 then momid=1;      
      end;
   end;
end;

/* Connect the age of the mom to the correct id */

/*define for nonresident mom */

if ynrmomid=9 and ngend9=2 then momage=nage9;
if ynrmomid=8 and ngend8=2 then momage=nage8;
if ynrmomid=7 and ngend7=2 then momage=nage7;
if ynrmomid=6 and ngend6=2 then momage=nage6;
if ynrmomid=5 and ngend5=2 then momage=nage5;
if ynrmomid=4 and ngend4=2 then momage=nage4;
if ynrmomid=3 and ngend3=2 then momage=nage3;
if ynrmomid=2 and ngend2=2 then momage=nage2;
if ynrmomid=1 and ngend1=2 then momage=nage1;

if pnrmomid=9 and ngend9=2 then momage=nage9;
if pnrmomid=8 and ngend8=2 then momage=nage8;
if pnrmomid=7 and ngend7=2 then momage=nage7;
if pnrmomid=6 and ngend6=2 then momage=nage6;
if pnrmomid=5 and ngend5=2 then momage=nage5;
if pnrmomid=4 and ngend4=2 then momage=nage4;
if pnrmomid=3 and ngend3=2 then momage=nage3;
if pnrmomid=2 and ngend2=2 then momage=nage2;
if pnrmomid=1 and ngend1=2 then momage=nage1;

/* define for mom in household */

if momid=1 and doby1 ne -3 then momage=age1;
if momid=2 and doby2 ne -3 then momage=age2;
if momid=3 and doby3 ne -3 then momage=age3;
if momid=4 and doby4 ne -3 then momage=age4;
if momid=5 and doby5 ne -3 then momage=age5;
if momid=6 and doby6 ne -3 then momage=age6;
if momid=7 and doby7 ne -3 then momage=age7;
if momid=8 and doby8 ne -3 then momage=age8;
if momid=9 and doby9 ne -3 then momage=age9;
if momid=10 and doby10 ne -3 then momage=age10;
if momid=11 and doby11 ne -3 then momage=age11;
if momid=12 and doby12 ne -3 then momage=age12;
if momid=13 and doby13 ne -3 then momage=age13;
if momid=14 and doby14 ne -3 then momage=age14;
if momid=15 and doby15 ne -3 then momage=age15;
if momid=16 and doby16 ne -3 then momage=age16;
if momid=17 and doby17 ne -3 then momage=age17;
if momid=18 and doby18 ne -3 then momage=age18;
if momid=19 and doby19 ne -3 then momage=age19;
if momid=20 and doby20 ne -3 then momage=age20;

if pi025=0 and pi058y>0 or pi058m>0 then do;
   if momid=pi020 or (momid=parentid and pi020=-4) then do;
      if pi058y>0 and scry>1996 and (pi058m>scrm or (pi058m=scrm and pi058d>scrd)) then do;
         momage=scry-pi058y-1;
         agefl=1;
      end;
      if pi058y>0 and scry>1996 and (pi058m<=scrm or (pi058m=scrm and pi058d<=scrd)) then do;
         momage=scry-pi058y;
         agefl=1;
      end;
   end;
end;

/* basically loop through looking for brothers and sisters (13, 14, 15, 18),
  if we have these - and there are no negative value relationships, and we
  have a valid year of birth on everyone, then we can find the oldests age
  and subtract from mom's age)*/

array age (i) age1-age19;
array sage (i) sage1-sage19;

do i=1 to 19;
  sage=-4;
     if yid=1 and momage>0 then do;
        if (rela1=13 or rela1=14 or rela1=15 or rela1=18) and age ge 0
           then sage=momage-age;
        if rela1=20 or rela1=17 then sage=-3;
        if (rela1=13 or rela1=14 or rela1=15 or rela1=18) and age<0
           then sage=-4;
     end;
     if yid=2 and momage>0 then do;
        if (rela2=13 or rela2=14 or rela2=15 or rela2=18) and age ge 0
           then sage=momage-age;
        if rela2=20 or rela2=17 then sage=-3;
        if (rela2=13 or rela2=14 or rela2=15 or rela2=18) and age<0
           then sage=-4;
     end;
     if yid=3 and momage>0 then do;
        if (rela3=13 or rela3=14 or rela3=15 or rela3=18) and age ge 0
           then sage=momage-age;
        if rela3=20 or rela3=17 then sage=-3;
        if (rela3=13 or rela3=14 or rela3=15 or rela3=18) and age<0
           then sage=-4;
     end;
     if yid=4 and momage>0 then do;
        if (rela4=13 or rela4=14 or rela4=15 or rela4=18) and age ge 0
           then sage=momage-age;
        if rela4=20 or rela4=17 then sage=-3;
        if (rela4=13 or rela4=14 or rela4=15 or rela4=18) and age<0
           then sage=-4;
     end;
     if yid=5 and momage>0 then do;
        if (rela5=13 or rela5=14 or rela5=15 or rela5=18) and age ge 0
           then sage=momage-age;
        if rela5=20 or rela5=17 then sage=-3;
        if (rela5=13 or rela5=14 or rela5=15 or rela5=18) and age<0
           then sage=-4;
     end;
end;

array nrel (i) nrel1-nrel23;
array nage (i) nage1-nage23;
array nrsage (i) nrsage1-nrsage23;

do i=1 to 23;
      nrsage=-4;
      if momage>0 then do;
         if (nrel=13 or nrel=14 or nrel=15 or nrel=18) and nage ge 0
            then nrsage=momage-nage;
         if nrel=20 or nrel=17 then nrsage=-3;
         if (nrel=13 or nrel=14 or nrel=15 or nrel=18) and nage<0
            then nrsage=-3;
      end;
end;

/* To get youths birth: if mom died, find yeardif by subtracting the year of death from the
   Rs birthyear, they subtract this difference from the age at the time of death to get to
   the bio mom's age at Rs birth */

if yid=1 and momage>0 and age1>0 then do;
   sage1=momage-age1;
end;
if yid=2 and momage>0 and age2>0 then do;
   sage2=momage-age2;
end;
if yid=3 and momage>0 and age3>0 then do;
   sage3=momage-age3;
end;
if yid=4 and momage>0 and age4>0 then do;
   sage4=momage-age4;
end;
if yid=5 and momage>0 and age5>0 then do;
   sage5=momage-age5;
end;

unadj1=sage1;
unadj2=sage2;
unadj3=sage3;
unadj4=sage4;
unadj5=sage5;

array sn76 (i) sn761-sn763;
array sn79 (i) sn791-sn793;

do i=1 to 3;
   if sn701=0 and yid=1 and (sn76 ge birthy) then do;
      yeardif=sn76-birthy;
      sage1=sn79-yeardif;
   end;
   if sn702=0 and yid=2 and (sn76 ge birthy) then do;
      yeardif=sn76-birthy;
      sage2=sn79-yeardif;
   end;
   if sn703=0 and yid=3 and (sn76 ge birthy) then do;
      yeardif=sn76-birthy;
      sage3=sn79-yeardif;
   end;
   if sn704=0 and yid=4 and (sn76 ge birthy) then do;
      yeardif=sn76-birthy;
      sage4=sn79-yeardif;
   end;
   if sn705=0 and yid=5 and (sn76 ge birthy) then do;
      yeardif=sn76-birthy;
      sage5=sn79-yeardif;
   end;
end;

array sdif (i) sdif1-sdif23;

do i=1 to 23;
   if sn701=0 and yid=1 and yeardif>0 and yeardif ne . and nrsage>0 then do;
      sdif=unadj1-nrsage;
      nrsage=sage1-sdif;
   end;
   if sn702=0 and yid=2 and yeardif>0 and yeardif ne . and nrsage>0 then do;
      sdif=unadj2-nrsage;
      nrsage=sage2-sdif;
   end;
   if sn703=0 and yid=3 and yeardif>0 and yeardif ne . and nrsage>0 then do;
      sdif=unadj3-nrsage;
      nrsage=sage3-sdif;
   end;
   if sn704=0 and yid=4 and yeardif>0 and yeardif ne . and nrsage>0 then do;
      sdif=unadj4-nrsage;
      nrsage=sage4-sdif;
   end;
   if sn705=0 and yid=5 and yeardif>0 and yeardif ne . and nrsage>0 then do;
      sdif=unadj5-nrsage;
      nrsage=sage5-sdif;
   end;
end;               
      
array sibdif (i) sibdif1-sibdif23;
do i=1 to 19;
sibdif=0;
end;

do i=2 to 19;
   if sn701=0 and yid=1 and yeardif>0 and yeardif ne . and sage>0 then do;
      sibdif=unadj1-sage;
      sage=sage1-sibdif;
   end;
end;
do i=3 to 19;
   if sn702=0 and yid=2 and yeardif>0 and yeardif ne . and sage>0 then do;
      sibdif=unadj2-sage;
      sibdif1=unadj2-unadj1;
      sage=sage2-sibdif;
      sage1=sage2-sibdif1;
   end;
end;
do i=4 to 19;
   if sn703=0 and yid=3 and yeardif>0 and yeardif ne . and sage>0 then do;
      sibdif=unadj3-sage;
      sibdif1=unadj3-unadj1;
      sibdif2=unadj3-unadj2;
      sage=sage3-sibdif;
      sage1=sage3-sibdif1;
      sage2=sage3-sibdif2;
   end;
end;
do i=5 to 19;
   if sn704=0 and yid=4 and yeardif>0 and yeardif ne . and sage>0 then do;
      sibdif=unadj4-sage;
      sibdif1=unadj4-unadj1;
      sibdif2=unadj4-unadj2;
      sibdif3=unadj4-unadj3;
      sage=sage4-sibdif;
      sage1=sage4-sibdif1;      
      sage2=sage4-sibdif2;      
      sage3=sage4-sibdif3;
   end;
end;
do i=6 to 19;
   if sn705=0 and yid=5 and yeardif>0 and yeardif ne . and sage>0 then do;
      sibdif=unadj5-sage;
      sibdif1=unadj5-unadj1;
      sibdif2=unadj5-unadj2;
      sibdif3=unadj5-unadj3;
      sibdif4=unadj5-unadj4;
      sage=sage5-sibdif;
      sage1=sage5-sibdif1;
      sage2=sage5-sibdif2;
      sage3=sage5-sibdif3;
      sage4=sage5-sibdif4;
   end;
end;               

/* Recalculate Youth variable and age */
if yid=1 and sage1>0 then do;
   smomage=sage1;
end;
if yid=2 and sage2>0 then do;
   smomage=sage2;
end;
if yid=3 and sage3>0 then do;
   smomage=sage3;
end;
if yid=4 and sage4>0 then do;
   smomage=sage4;
end;
if yid=5 and sage5>0 then do;
   smomage=sage5;
end;

do i=1 to 19;
   if sage=-4 then do;
      sage=999;
   end;
   if (sage<0 and sage ne -4) or sage=0 then do;
      sage=0;
   end;
end;
do i=1 to 23;
   if nrsage=-4 then do;
      nrsage=999;
   end;
   if (nrsage<0 and nrsage ne -4) or nrsage=0 then do;
   end;
end;

if sage1>0 and sage2>0 and sage3>0 and sage4>0 and sage5>0 and sage6>0 and sage7>0 and sage8>0 and sage9>0
   and sage10>0 and sage11>0 and sage12>0 and sage13>0 and sage14>0 and sage15>0 and sage16>0 and sage17>0
   and sage18>0 and sage19>0 and nrsage1>0 and nrsage2>0 and nrsage3>0 and nrsage4>0 and nrsage5>0 and nrsage6>0
   and nrsage7>0 and nrsage8>0 and nrsage9>0 and nrsage10>0 and nrsage11>0 and nrsage12>0 and nrsage13>0 and
   nrsage14>0 and nrsage15>0 and nrsage16>0 and nrsage17>0 and nrsage18>0 and nrsage19>0 and nrsage20>0 and
   nrsage21>0 and nrsage22>0 and nrsage23>0 then do;
     agemomfy=min(sage1, sage2, sage3, sage4, sage5, sage6, sage7, sage8, sage9, sage10, sage11, sage12, sage13,
     sage14, sage15, sage16, sage17, sage18, sage19, nrsage1, nrsage2, nrsage3, nrsage4, nrsage5, nrsage6,
     nrsage7, nrsage8, nrsage9, nrsage10, nrsage11, nrsage12, nrsage13, nrsage14, nrsage15, nrsage16, nrsage17,
     nrsage18, nrsage19, nrsage20, nrsage21, nrsage22, nrsage23);
end;

if agemomfy=999 then agemomfy=-3;

/*youth says doesn't live with bio mom and no survey information collected on non-res bio mom*/
if sn701=1 and yid=1 then do;
   if (saq13=1 and saq14 ne 1) or (saq13<1 and saq13>-4) then do;
    smomage=-3;
    agemomfy=-3;
   end;
end;
if sn702=1 and yid=2 then do;
   if (saq13=1 and saq14 ne 1) or (saq13<1 and saq13>-4) then do;
    smomage=-3;
    agemomfy=-3;
   end;
end;
if sn703=1 and yid=3 then do;
   if (saq13=1 and saq14 ne 1) or (saq13<1 and saq13>-4) then do;
    smomage=-3;
    agemomfy=-3;
   end;
end;
if sn704=1 and yid=4 then do;
   if (saq13=1 and saq14 ne 1) or (saq13<1 and saq13>-4) then do;
    smomage=-3;
    agemomfy=-3;
   end;
end;
if sn705=5 and yid=5 then do;
   if (saq13=1 and saq14 ne 1) or (saq13<1 and saq13>-4) then do;
    smomage=-3;
    agemomfy=-3;
   end;
end;
endsas;