Hi, Assume I have data set like the one below: ID Year Var1 Var2 123 2012 345 24 310 2012 4 324 400 2012 234 456 123 2013 675 46 200 2013 577 89 310 2013 46 45 400 2013 45 76 123 2014 123 234 200 2014 1234 35 400 2014 435 645 123 2015 231 236 200 2015 456 87 310 2015 435 534 400 2015 232 235 123 2016 123 679 200 2016 354 523 310 2016 233 754 400 2016 200 342 Now suppose, I want to create a new data set from this data set where for each year and ID I want to get the summation of the previous three years values for var 1 and var2...so that I get an output like this: ID Year Var1 Var2 123 2015 1143 304 200 2015 1811 124 310 2015 50 369 400 2015 714 1177 123 2016 1029 516 200 2016 2267 211 310 2016 481 579 400 2016 712 956 So for example, for ID 400 in 2016 I get the sum of the values for VAR 1 and VAR 2 in years 2015, 2014, 2013. Notice that not in all years do all the IDs appear. Also suppose I have a large number of variables (VAR1 TO VARn) so I don't want to be typing in all their names. How do I go about this? Thank you!
... View more