Hi all,
I have the following data structure:
Where Mgt_dummy is a dummy with a value of 0 if the Director was a manager in a certain year.
I want Stata to create a new variable counting the number of years a director has been manager. For instance, Director 1 is a manager for 2 years, and director 2 as well.
My current code is:
sort DirectorID year
by DirectorID: gen ManagerYears= _N
by DirectorID: keep if _n == 1
But with this code, my variable ManagerYears counts all rows, not just those where the Mgt_dummy variable has a value of 1.
How can I do this?
Thank you so much!
Best,
Carla
I have the following data structure:
DirectorID | Mgt_dummy | Year |
1 | 1 | 2000 |
1 | 1 | 2001 |
1 | 0 | 100000 |
2 | 1 | 2003 |
2 | 1 | 2004 |
2 | 0 | 100000 |
I want Stata to create a new variable counting the number of years a director has been manager. For instance, Director 1 is a manager for 2 years, and director 2 as well.
My current code is:
sort DirectorID year
by DirectorID: gen ManagerYears= _N
by DirectorID: keep if _n == 1
But with this code, my variable ManagerYears counts all rows, not just those where the Mgt_dummy variable has a value of 1.
How can I do this?
Thank you so much!
Best,
Carla
Comment