Solution

Your first task is to find the age of the youngest adult in each household. You can do that with:

by household: egen ageYoungestAdult=min(age) if age>=18

Next, find the age of the oldest child:

by household: egen ageFirstChild=max(age) if rel2head==3

(Yes, if age<18 would work too for this data. In real data sets you'd have to consider the possibility of adult children still living at home, and instead of "youngest adult" you'd have to think about "youngest parent," which could be hard to identify. But never mind all that for now.)

In principle, all you need is ageYoungestAdult-ageFirstChild. The trouble is, the first is only defined for adults and the second is only defined for children. Thus some result spreading is required.

by household: egen ageYoungestAdult2=mean(ageYoungestAdult)
by household: egen ageFirstChild2=max(ageFirstChild)

The second command gives three missing values: the three people living in households with no children. Now we're ready to find the answer:

gen ageYoungestAdultAtFirstBirth= ageYoungestAdult2-ageFirstChild2

Last Revised: 1/25/2010