I have a dataset which looks like this -
Unique_ID Years BirthYear
1. 1970. 1972
1 1971. 1972
1 1972. 1973
1 1973. 1972
1 1974. 1973
2. 1970. 1971
2 1971. 1971
2 1972. 1971
2 1973. 1974
2 1974. 1971
Here, the unique ID corresponds to a unique mother and years corrospond to 1970-1974 for every unique mother's ID. Birthyear is the year when that mother has given a birth. I achieved this dataset by using expand function on an existing dataset, so the birthyear got repeated.
Now I want to create a variable, Value which looks like this
Unique_ID Years BirthYear Value
1. 1970. 1972 0
1 1971. 1972 0
1 1972. 1973 1
1 1973. 1972 1
1 1974. 1973 0
2. 1970. 1971 0
2 1971. 1971 1
2 1972. 1971 0
2 1973. 1974 0
2 1974. 1971 1
However, I am unable to create this because the formula, gen Value = 1 if Years == Birthyear does not work as BirthYear can be in a row different than the Year.
So, I want to find a way which can first of all identify the Unique_ID 1 and then within that can identify BirthYear value and match it to all the values applicable in Years to be able to create the Value column as above.
Thank you so much in advance for your help.
Unique_ID Years BirthYear
1. 1970. 1972
1 1971. 1972
1 1972. 1973
1 1973. 1972
1 1974. 1973
2. 1970. 1971
2 1971. 1971
2 1972. 1971
2 1973. 1974
2 1974. 1971
Here, the unique ID corresponds to a unique mother and years corrospond to 1970-1974 for every unique mother's ID. Birthyear is the year when that mother has given a birth. I achieved this dataset by using expand function on an existing dataset, so the birthyear got repeated.
Now I want to create a variable, Value which looks like this
Unique_ID Years BirthYear Value
1. 1970. 1972 0
1 1971. 1972 0
1 1972. 1973 1
1 1973. 1972 1
1 1974. 1973 0
2. 1970. 1971 0
2 1971. 1971 1
2 1972. 1971 0
2 1973. 1974 0
2 1974. 1971 1
However, I am unable to create this because the formula, gen Value = 1 if Years == Birthyear does not work as BirthYear can be in a row different than the Year.
So, I want to find a way which can first of all identify the Unique_ID 1 and then within that can identify BirthYear value and match it to all the values applicable in Years to be able to create the Value column as above.
Thank you so much in advance for your help.
Comment