Hello,
How can I replace missing values with previous values + 1 or forward values - 1? I would like to fill out the below data set with the correct ages (age) per individual (id).
If I have data that looks like this:
I have tried something like:
bysort id: replace age = age[_n-1] + 1 if age=.
bysort id: replace age = age[_n+1] - 1 if age=.
Thank you,
Natasha
How can I replace missing values with previous values + 1 or forward values - 1? I would like to fill out the below data set with the correct ages (age) per individual (id).
If I have data that looks like this:
id | age | year |
1 | 20 | 2001 |
1 | . | 2002 |
1 | 22 | 2003 |
1 | 23 | 2004 |
2 | . | 2001 |
2 | 56 | 2002 |
2 | 57 | 2003 |
3 | 42 | 2001 |
3 | . | 2002 |
3 | 44 | 2003 |
I have tried something like:
bysort id: replace age = age[_n-1] + 1 if age=.
bysort id: replace age = age[_n+1] - 1 if age=.
Thank you,
Natasha
Comment