I have the following data:
structure(list(`Product Name` = c("A", "A", "A", "B", "B", "B",
"C", "C", "C"), Year = c(2018L, 2019L, 2020L, 2018L, 2019L, 2020L,
2018L, 2019L, 2020L), Price = c(200L, 300L, 250L, 304L, 320L,
103L, 203L, 203L, 402L)), class = "data.frame", row.names = c(NA,
-9L))
Now I would like to compute the yearly continuous return based on the following formula: ln(Price_t /Price_(t-1)) where t represents the year.
I came across the following question: Calculating monthly returns based on Panel Data R However, I have a different formula for the return.
Could someone help me with the code? Thanks a lot in advance.