I have long data that is unique at the person_id and year level. I have a binary variable "treated"... 1 for whether they receive treatment that year, and 0 if they do not receive treatment that year. I want to make a new column in which all subsequent years (meaning rows) should have a treated value of 1 after the first treated year (row) for each person.
here are my two current ideas how to create this indicator, but they are both wrong:
data %>% group_by(person_id) %>% mutate(treated_recoded_idea1 = cummax(treated), treated_recoded_idea2 = ifelse(lag(treated, default = 0) == 1, 1, treated))
I appreciate and welcome your advices thank you. very much!