I am working with longitudinal household data and am (very) stuck at creating a dummy variable that takes the value 1 if a woman is having a child in the following year (so first baby next year is the variable I want to create). Here is a description of the data, where HID is the household ID, PID is the personal ID, and mother ID is the PID of the mother of the person. Any help would be greatly appreciated.
year | HID | PID | Sex | Age | MotherID | First baby next year |
2019 | 115 | 1151 | F | 30 | . | 1 |
2020 | 115 | 1151 | F | 31 | . | 0 |
2021 | 115 | 1151 | F | 32 | . | 0 |
2020 | 115 | 1152 | M | 1 | 1151 | . |
2021 | 115 | 1152 | M | 2 | 1151 | . |
2021 | 115 | 1153 | F | 1 | 1151 | . |
Comment