Hi all,
I am trying to merge two datasets and Stata doesn't allow me because I have duplicate individuals. I'll go straight to the issue:
My data looks like this:
Note how person A has two role 1 in different years. In this case, I would only like to keep the most recent one (2014).
What I want my data to look like is the following:
As you can see, here I have 1 observation per person and year. When a person doesn't have either Role1 or Role 2 in a given year (see person A in 2016-2017), my 2 dummies (Role1_dummy and Role2_dummy) will have values of 0.
How could I solve this?
Thank you so much.
Best,
Carla
I am trying to merge two datasets and Stata doesn't allow me because I have duplicate individuals. I'll go straight to the issue:
My data looks like this:
PersonID | YearRole | Role1_dummy | Role2_dummy |
A | 2015 | 0 | 1 |
A | 2013 | 1 | 0 |
A | 2014 | 1 | 0 |
B | 2013 | 1 | 0 |
B | 2017 | 0 | 1 |
What I want my data to look like is the following:
PersonID | Year | Role1_dummy | Role2_dummy |
A | 2013 | 1 | 0 |
A | 2014 | 1 | 0 |
A | 2015 | 0 | 1 |
A | 2016 | 0 | 0 |
A | 2017 | 0 | 0 |
B | 2013 | 1 | 0 |
B | 2014 | 0 | 0 |
B | 2015 | 0 | 0 |
B | 2016 | 0 | 0 |
B | 2017 | 0 | 1 |
How could I solve this?
Thank you so much.
Best,
Carla
Comment