'PCA with panel data in R

I want to apply Principal Component Analysis on a panel data set in R but I am having trouble with the time and entity dimension. My data has the form of

    city year x1_gdp x2_unempl
1 Berlin 2012   1000      0.20
2 Berlin 2013   1003      0.21
3 Berlin 2014   1010      0.30
4 Berlin 2015   1100      0.27
5 London 2012   2733      0.11
6 London 2013   2755      0.12
7 London 2014   2832      0.14
8 London 2015   2989      0.14

Applying standard PCA on x1 and x2 does not seem to be a good idea because the observations withing group (e.g. gdp of Berlin 2012 and 2013) are not independent from each other and pca commands like prcomp cannot deal with this form of autocorrelation.

I started to read into Dynamic PCA models but R commands like dpca {freqdom} which "decomposes multivariate time series into uncorrelated components". However, they require a time series as input. How can I apply DPCA or any other dimension reduction technique in this panel setting?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source