I have a panel of the following structure
. list, sepby(Id)
+--------------------+
| Id Year parent |
|--------------------|
1. | 1 2007 Yes |
2. | 1 2008 Yes |
3. | 1 2009 Yes |
4. | 1 2010 . |
5. | 1 2011 Yes |
|--------------------|
6. | 2 2007 No |
7. | 2 2008 No |
8. | 2 2009 . |
9. | 2 2010 No |
10. | 2 2011 No |
|--------------------|
11. | 3 2007 No |
12. | 3 2008 No |
13. | 3 2009 No |
14. | 3 2010 . |
15. | 3 2011 Yes |
+--------------------+
What I would like to do is to fill in, wherever possible, the missing values for the parent indicator based on the preceding AND following values.
That is, for Id 1, . should be replaced with "Yes". For Id 2, replaced with "No". But for Id 3, it should remain missing because it is not possible to determine if 2010 is the first year during which the respondent became a parent.
I have tried
Code:
. bysort Id (Year): replace parent = parent[_n-1] if parent == .
Thanks
0 Response to Fill in missing value in panel based on preceding & following values
Post a Comment