I want to combine multiple observations with same unique ID into a single observation and replace the missing values of the variables if the value exists in any of the duplicates.
I have tried to search in the forum, however most solutions offered work if there is 1 copy of duplicate based on ID. However, in my dataset the ID has multiple copies of duplicates and it is not a fixed number (copies = 0 to 9).
My current dataset looks like this
ID | var1 | var2 | var3 | var4 | var5 |
1 | . | 1 | . | 5 | . |
1 | 2 | . | . | . | . |
1 | . | . | . | . | 3 |
2 | 1 | . | . | . | . |
2 | . | 3 | . | . | . |
3 | 5 | . | . | . | . |
3 | . | 7 | . | . | . |
3 | . | . | 6 | . | . |
3 | . | . | . | 7 | . |
Required output is
ID | var1 | var2 | var3 | var4 | var5 |
1 | 2 | 1 | . | 5 | 3 |
2 | 1 | 3 | . | . | . |
3 | 5 | 7 | 6 | 7 | . |
0 Response to Combining multiple observations with same unique ID into one observation
Post a Comment