Hello,

I'm trying to create four new variables in the following dataset:

Code:
input long pidp float(wave gotABaby)
   76165  7 0
   76165  8 0
   76165  9 1
   76165 10 0
 4794685  3 0
 4794685  4 0
 4794685  5 0
 4794685  6 1
68002049  2 0
68002049  7 1
68002049  8 0
68009527  1 0
68009527  2 0
68009527  3 0
68009527  4 0
68009527  5 0
68009527  6 0
68009527  7 0
68009527  8 1
68009527  9 0
68009527 10 0
68035367  1 0
68035367  2 0
68035367  3 0
68035367  4 0
68035367  5 0
68035367  6 0
68035367  7 0
68035367  8 0
68035367  9 1
68035367 10 0
68051687  1 0
68051687  2 0
68051687  3 0
68051687  4 1
68051691  1 0
68051691  2 0
68051691  3 0
68051691  4 1
68061288  5 0
68061288  6 0
68061288  7 0
68061288  8 1
68061288  9 0
68061288 10 0
68111527  1 0
68111527  2 1
68111527  3 0
68111527  4 0
68111527  5 0
68111527  6 0
68111527  7 0
68111527  8 0
68111527  9 0
68111527 10 0
68120375  1 0
68120375  2 0
68120375  3 0
68120375  4 0
68120375  5 0
68120375  6 0
68120375  7 0
68120375  8 1
68120375  9 0
68120375 10 0
68133289  2 0
68133289  3 0
68133289  4 0
68133289  5 0
68133289  6 0
68133289  7 0
68133289  8 0
68133289  9 0
68133289 10 1
68142890  6 0
68142890  7 0
68142890  8 0
68142890  9 1
68163887  1 0
68163887  2 0
68163887  3 0
68163887  4 0
68163887  5 0
68163887  6 0
68163887  7 0
68163887  8 1
68163887  9 0
68163887 10 0
68174767  1 0
68174767  2 0
68174767  3 0
68174767  4 1
68174767  5 0
68174767  6 0
68174767  7 1
68174767  8 0
68174767  9 1
68174767 10 0
68202647  1 0
68202647  2 0
end
I want to create the following variables out of the gotABaby variable (which is 1 in every wave an individual got a baby): 1. firstBaby , which denotes when people got their first baby (which is 1 in the same wave as gotABaby).
2. secondBaby (1 in the wave an individual got a second baby, otherwise 0 every wave) , 3. thirdBaby, 4. fourthBaby. The maximum amount of baby's and individual got in my dataset is four. Is there anyone with an idea how to do this?

Thanks in advance!

Kind regards,

Vincent van Marrewijk