How to calculate percentage change from different rows over different spans
问题 I am trying to calculate the percentage change in price for quarterly data of companies recognized by a gvkey (1001, 1384, etc...). and it's corresponding quarterly stock price, PRCCQ . gvkey PRCCQ 1 1004 23.750 2 1004 13.875 3 1004 11.250 4 1004 10.375 5 1004 13.600 6 1004 14.000 7 1004 17.060 8 1004 8.150 9 1004 7.400 10 1004 11.440 11 1004 6.200 12 1004 5.500 13 1004 4.450 14 1004 4.500 15 1004 8.010 What I am trying to do is add 8 columns showing 1 quarter return, 2 quarter return, etc.