Hello, I am new in Stata.

I have stock price data of many companies. I would like to get the return by using this code gen return= price/ price[_n-1]-1, however when I perform it in my data it runs for all companies mixing them. I would like to know which code I have to use to generate this variable based on the company id since I need to get the daily returns by company. I tried this code bysort gvkey datadate: gen return= price/ price[_n-1] , but it did not solve my issue. I hope someone can help me. Thanks in advance.
(Stata 16.0)