Hello. I have string data in the format described below. I want to generate a new variable "Pregnancy" based on the following logic: Pregnancy = 1 if Marriage is followed by Death in the variable Event, and if Death has a corresponding entry of Child in the variable Details. Is isn't necessary that Marriage is always followed by Death sequentially for the same ID. Basically, Pregnancy should equal 1 for both IDs 1 and 3 in the table below.

ID Date Event Details
1 24apr2008 Marriage
1 6jun2015 Death Child
2 3may1985 Birth
2 23jan2005 Graduated School
2 25sep2015 Marriage
2 1nov2019 Death
3 1jan1997 Marriage
3 3feb2002 Graduated college
3 13may2020 Death Child
Thanks,
Karishma