I have yearly time series data in a long format at a Group-State-Brand level. I want to apply a function that would calculate the growth rates YOY for every level.
basically the (currentvalue/previous value) -1
Find below an extract of the data:
Grp Sta Brnd Yr Sls
A AL Ben's 2012 29770
A AL Ben's 2013 23357
A AL Ben's 2014 22442
A AL Ben's 2015 21848
A AL Ben's 2016 13799
B CA Scott's 2012 1079
B CA Scott's 2013 11178
B CA Scott's 2014 14778
B CA Scott's 2015 15241
B CA Scott's 2016 10569
C TX Joey's 2012 1673
C TX Joey's 2013 1290
C TX Joey's 2014 899
C TX Joey's 2015 732
C TX Joey's 2016 294
Basically, each unique level of grp-state-brand is 5 rows.
Grp Sta Brnd Yr Sls Grwth
A AL Ben's 2012 29770
A AL Ben's 2013 23357 -22%
A AL Ben's 2014 22442 -4%
A AL Ben's 2015 21848 -3%
A AL Ben's 2016 13799 -37%
B CA Scott's 2012 1079
B CA Scott's 2013 11178 936%
B CA Scott's 2014 14778 32%
B CA Scott's 2015 15241 3%
B CA Scott's 2016 10569 -23%
C TX Joey's 2012 1673
C TX Joey's 2013 1290 -23%
C TX Joey's 2014 899 -30%
C TX Joey's 2015 732 -19%
C TX Joey's 2016 294 -60%