Hi, thanks so much for your kind information.
suppose there are data frame such that:
c1_Year=c(1,2,3,4,1,2,1,2,3)
c2_ID=c(1,1,1,1,2,2,3,3,3)
c3_a=c(1,2,3,4,5,6,7,8,9)
c4_b=c(1,2,1,2,1,2,1,2,1)
mydata=cbind(c1_Year,c2_ID,c3_a,c4_b)
I want to create a new variable in a new column (e.g. x=a_{t-1}/b_t) in which it should be calculated for different IDs separately, such that x equals a of the last year t-1 divided by b of the current year t. Could you help me? Thanks!!