面板数据与 R 中 plm 包的相关性

Correlation in panel data with plm package in R

My question was: I'm trying to calculate the correlation between "ftd" and "ici" variables but I can't figure out how to use cortab function and I couldn't find any example in web about that.

对于那些想学习如何使用 cortab 功能的人,感谢 Giovanni Millo(plm 包的作者之一),我找到了例子。我已经发布了它的数据库,以防万一我也把代码放在这里。

http://qed.econ.queensu.ca/jae/2015-v30.4/millo/

这是包 plm 中的 cortab 函数的玩具示例:

library(plm)
data("Grunfeld", package = "plm")
pGrunfeld <- pdata.frame(Grunfeld)
grp <- c(rep(1, 100), rep(2, 50), rep(3, 50)) # make 3 groups
cortab(pGrunfeld$value, grouping = grp, groupnames = c("A", "B", "C"))

#           A         B          C
# A 0.5562310        NA         NA
# B 0.5431652 0.5406152         NA
# C 0.3799585 0.2999645 -0.1665637

输出矩阵包含组内(对角线)和组间(非对角线)的平均横截面相关系数。