I've a panel dataset of several banks, each from 1997 to 2015, with annual observations s.t.:
CODE COUNTRY YEAR LOANS_NET ...other variables
671405 AT 1997 39028938
671405 AT 1998 41033237
671405 AT 1999 35735062
...
...
671405 AT 2015 130701872
...
30885R DE 2004 200024673
...
...
Using R, I need to compute additional two columns:
1) LOANS_NET growth rate at 1-year horizon
2) LOANS_NET growth rate at 3-years horizon, which must be annualized, once calculated.
E.g.:
Loan Growth 3-year = [Bank's(i) LOANS_NET Year(t) / Bank's(i) LOANS_NET Year(t-3)] -1
nb: data contains lots of missing values, code must consider that issue! :)
@Dan Do you use any packages? I recommend you using zoo and data.table packages and transform dates in the following way:
DT[, YearNumeric := as.numeric(YEAR)]
DT[, PreviousYearLoanNet := .SD[match(YearNumeric - 1, .SD$YearNumeric), LOANS_NET], by=CODE]
Here, you create a column with previous (-1 year) loan values. Then you create a new column with growth:
DT[,Growth1Y:= (YEARLOANNET- PreviousYearLoanNet)/PreviousYearLoanNet]
And then you do whatever you want:) Cheers!