Hi Statalist,

I want to calculate the highest and lowest quartile for mental health (stdMentalHealth) of people for the waves of available data before people have a child. An example of the dataset is the following:

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float wave long pidp float(stdMentalHealth gotFirstChild timingBirthOne)
 7    76165  -.1682427 0  7
 8    76165  -.2205372 0  8
 9    76165  1.4913077 1  9
10    76165  .29066837 0 10
 3  4794685  -2.734943 0  6
 4  4794685 -2.4201086 0  7
 5  4794685 -1.5108243 0  8
 6  4794685 -1.8128518 1  9
 2 68002049  .29066837 0  4
 7 68002049  -.4489255 1  9
 8 68002049  -.5311026 0 10
 1 68009527   .9406145 0  2
 2 68009527  -.2664283 0  3
 3 68009527 -1.0679218 0  4
 4 68009527   .2127602 0  5
 5 68009527   .6247129 0  6
 6 68009527 -.07859495 0  7
 7 68009527    -.26963 0  8
 8 68009527  -2.099938 1  9
 9 68009527  -.4702702 0 10
10 68009527  -.8352646 0 11
 1 68035367  -.0252332 0  1
 2 68035367  -.5439094 0  2
 3 68035367  .27572706 0  3
 4 68035367   .3536352 0  4
 5 68035367    .457157 0  5
 6 68035367  -.0252332 0  6
 7 68035367  -.6815827 0  7
 8 68035367  .05587666 0  8
 9 68035367   .3536352 1  9
10 68035367  .05587666 0 10
 1 68051687  1.0281277 0  6
 2 68051687   .3066769 0  7
 3 68051687  -.4425221 0  8
 4 68051687  .59589756 1  9
 1 68051691   .9224715 0  6
 2 68051691   .6065699 0  7
 3 68051691    .652461 0  8
 4 68051691 -.20346144 1  9
 5 68061288  -.7840373 0  6
 6 68061288  -2.512958 0  7
 7 68061288   .2223653 0  8
 8 68061288   -.215201 1  9
 9 68061288    -.31979 0 10
10 68061288 -.27710065 0 11
 1 68111527   .8082773 0  8
 2 68111527   .7282347 1  9
 3 68111527  .29066837 0 10
 4 68111527 -1.0860648 0 11
 5 68111527   .9224715 0 12
 6 68111527   .9833038 0 13
 7 68111527  1.2362386 0 14
 8 68111527   .2095585 0 15
 9 68111527  1.0441363 0 16
10 68111527   1.229835 0 17
 1 68120375   .5329307 0  2
 2 68120375  .59589756 0  3
 3 68120375   .9117991 0  4
 4 68120375   .9117991 0  5
 5 68120375   .6588644 0  6
 6 68120375   .6588644 0  7
 7 68120375   .9117991 0  8
 8 68120375   .6588644 1  9
 9 68120375   -.215201 0 10
10 68120375 .027061317 0 11
 2 68133289  -.2899075 0  1
 3 68133289  -.6634397 0  2
 4 68133289  -.6901206 0  3
 5 68133289 -1.3710165 0  4
 6 68133289  .13591929 0  5
 7 68133289 -2.2055943 0  6
 8 68133289 -1.0999389 0  7
 9 68133289   -.628221 0  8
10 68133289 -1.6111444 1  9
 6 68142890 -.05938471 0  6
 7 68142890   .9117991 0  7
 8 68142890  .19568445 0  8
 9 68142890   .6247129 1  9
 1 68163887   .9117991 0  2
 2 68163887   .9117991 0  3
 3 68163887  1.4806354 0  4
 4 68163887  1.4806354 0  5
 5 68163887   .9117991 0  6
 6 68163887   .9117991 0  7
 7 68163887   .9117991 0  8
 8 68163887    .279996 1  9
 9 68163887  -.2600249 0 10
10 68163887   .9224715 0 11
 1 68174767   1.387786 0  6
 2 68174767  -2.389159 0  7
 3 68174767   .6983521 0  8
 4 68174767   .8904544 1  9
 5 68174767   .9907745 0 10
 6 68174767 -1.0593839 0 11
 7 68174767     .75705 0 12
 8 68174767  .21489467 0 13
 9 68174767 -1.0796614 0 14
10 68174767  1.0622792 0 15
 1 68202647   -.165041 0  6
 2 68202647  .29066837 0  7
end
In my dataset, every individual gets a child when timingBirthOne equals 9. I thus want to calculate which people (pidp) belong to the lowest quartile of mental health (stdMentalHealth) and which people belong to highest quartile of mental health for the available data of the waves before, thus when timingBirthOne equals 1-8 (for the values/waves available). Does anyone have an idea how to perform this?

Many thanks in advance!

Kind regards,

Vincent van Marrewijk