Hi All, Please I would like to ask you help. I have an unbalanced panel with id, months, years, course_type and absences. I need to create three new variables one for each course_type which will contain the absences for each id in a given month and year and school type. So, instead of having repeated months for the same id in the same year, I would have less observations, without the repeated id month and more variables.
The data is like:
| id |
year |
month |
school_type |
absences |
| 1 |
2004 |
9 |
2 |
5 |
| 2 |
2005 |
8 |
1 |
1 |
| 3 |
2005 |
8 |
2 |
2 |
| 3 |
2005 |
8 |
3 |
1 |
| 4 |
2005 |
10 |
3 |
4 |
| 5 |
2006 |
2 |
1 |
3 |
| 5 |
2006 |
2 |
2 |
7 |
| 6 |
2006 |
5 |
3 |
2 |
And I would like it to become.
| id |
year |
absence_course1 |
absence_course2 |
absence_course3 |
| 1 |
2004 |
0 |
5 |
0 |
| 2 |
2005 |
1 |
0 |
0 |
| 3 |
2005 |
0 |
2 |
1 |
| 3 |
2005 |
|
|
|
| 4 |
2005 |
0 |
0 |
4 |
| 5 |
2006 |
3 |
7 |
0 |
| 5 |
2006 |
|
|
|
| 6 |
2006 |
0 |
0 |
2 |
where the empty rows would drop and the final result would be:
| id |
year |
month |
absence_course1 |
absence_course2 |
absence_course3 |
| 1 |
2004 |
9 |
0 |
5 |
0 |
| 2 |
2005 |
8 |
1 |
0 |
0 |
| 3 |
2005 |
8 |
0 |
2 |
1 |
| 4 |
2005 |
10 |
0 |
0 |
4 |
| 5 |
2006 |
2 |
3 |
7 |
0 |
| 6 |
2006 |
5 |
0 |
0 |
2 |
Thank you very much !
Cheers,
Juliana
0 Response to creating new variables for duplicates observations
Post a Comment