Hello,
I have an unbalanced panel data set named "df" (n individuals and 8 years). I want to create a dummy variable that takes 1 if the value of variable 1 for each "Name" does not change for all years and 0 otherwise.
For example:
| years | Names | Variable1 | Dummy variable |
|---|---|---|---|
| 2008 | A | 1 | 1 |
| 2009 | A | 1 | 1 |
| 2011 | A | 1 | 1 |
| 2012 | A | 1 | 1 |
| 2013 | A | 1 | 1 |
| 2014 | A | 1 | 1 |
| 2015 | A | 1 | 1 |
| 2008 | B | 0 | 0 |
| 2009 | B | 1 | 1 |
| 2010 | B | 0 | 1 |
| 2012 | B | 1 | 1 |
| 2015 | B | 1 | 1 |
Could you please help me?
Thanks