I'm trying to replicate some Stata code in r. In my df, there is a variable "time" and one "exposure" (both numeric, so with values like 1,2,3 etc.
This is what the original Stata code looks like:
replace time = (time - 31) if exposure == 0
And this is what I tried:
recoded_df <- recoded_df %>% mutate(time = case_when(exposure == 0 ~ (time - 31))
I get the error that there is an "unexpected symbol" in the code. But I have no idea what I am doing wrong.