I have an unbalanced panel data of which the following is a representative sample:
ID | Year | Gender |
1 | 2007 | M |
1 | 2008 | M |
1 | 2009 | M |
2 | 2007 | F |
2 | 2008 | F |
2 | 2009 | F |
2 | 2010 | M |
2 | 2011 | M |
3 | 2007 | F |
4 | 2007 | F |
4 | 2008 | F |
4 | 2009 | F |
5 | 2007 | M |
5 | 2008 | F |
I would like to flag such instances in the following way:
ID | Year | Gender | tag |
1 | 2007 | M | 0 |
1 | 2008 | M | 0 |
1 | 2009 | M | 0 |
2 | 2007 | F | 1 |
2 | 2008 | F | 1 |
2 | 2009 | F | 1 |
2 | 2010 | M | 1 |
2 | 2011 | M | 1 |
3 | 2007 | F | 0 |
4 | 2007 | F | 0 |
4 | 2008 | F | 0 |
4 | 2009 | F | 0 |
5 | 2007 | M | 1 |
5 | 2008 | F | 1 |
Code:
. egen gender_tag = tag(ID gender) . egen gender_ntags = total(gender_tag), by(ID) . browse ID Year Gender if gender_ntags != 1
Could someone please suggest a solution that would give me the results in the 2nd table above?
Thanks.
0 Response to Identify errors in time-invariant variable in panel data
Post a Comment