I'm working with some historical data on NFL players. I want to create a dummy variable indicating whether a player is still active or not. Basically, I want Stata to produce active == 1 if a given player has an observation when year == 2019 and active == 0 otherwise.
I feel like this should be simple, but I'm struggling to code this. What I tried was:
, but this just put active == 1 for all 2019 observations and active == 0 for all other observations regardless of whether the player was active in 2019.
Does anyone have any advice here?
I feel like this should be simple, but I'm struggling to code this. What I tried was:
Code:
by id: gen active = 1 if year == 2019 by id: replace active = 0 if year != 2019
Does anyone have any advice here?
Comment