Please excuse this very beginner question, but much help would be appreciated!

I want to create a variable for all 2018 observations that indicates its value in 2017 (if there is a value there). I only want to go back to 2017, no further. If there's no value for 2017 or for 2018, the variable value should just be missing.

Using "if year==2017" doesn't work because then it just creates the variable for observations in 2017 (not 2018), and using "[_n-1]" doesn't work because then I think it may go back further than 2017 if there is a value available for an earlier year but not for 2017.

Thank you in advance!