Hi, I have a dataset, wherein there is an ID variable for each mother, and then it is repeated as many times as she has given birth.
So, for example if she has given 3 births, it would look like this -
ID Kidbirthyr
1. 1972
1. 1978
1. 1980
Kidbirthyr goes from 1970-2016.
Then it has other columns about the kid, their sex, mortality rates, etc.
Now I want to expand this by creating years from 1970 to 2016 for each mother so it would look like this
ID Years Value
1. 1970. 0
1. 1971. 0
1. 1972. 1
1. 1973. 0
1. 1974. 0
1. 1975. 0
1. 1976. 0
1. 1977. 0
1. 1978. 1
1. 1979. 0
1. .
.
.
1. 2016. 0
I want this to repeat for each mother ID and a value variable be created which takes the value 0 if the mother did not give birth that year or 1 if the mother did give birth. I want the other variables such as sex to remain consistent for the values where 1 is present and be missing for values wherein the value is 0.
I have tried using the expand command but it repeats the ID variable more times than I want so for mothers who have 3 births it expands 3X times I want and for mothers who have 2 births, it expands 2X times I want.
How can I achieve this dataset, can someone please help, thank you so much!!!
So, for example if she has given 3 births, it would look like this -
ID Kidbirthyr
1. 1972
1. 1978
1. 1980
Kidbirthyr goes from 1970-2016.
Then it has other columns about the kid, their sex, mortality rates, etc.
Now I want to expand this by creating years from 1970 to 2016 for each mother so it would look like this
ID Years Value
1. 1970. 0
1. 1971. 0
1. 1972. 1
1. 1973. 0
1. 1974. 0
1. 1975. 0
1. 1976. 0
1. 1977. 0
1. 1978. 1
1. 1979. 0
1. .
.
.
1. 2016. 0
I want this to repeat for each mother ID and a value variable be created which takes the value 0 if the mother did not give birth that year or 1 if the mother did give birth. I want the other variables such as sex to remain consistent for the values where 1 is present and be missing for values wherein the value is 0.
I have tried using the expand command but it repeats the ID variable more times than I want so for mothers who have 3 births it expands 3X times I want and for mothers who have 2 births, it expands 2X times I want.
How can I achieve this dataset, can someone please help, thank you so much!!!
Comment