面板数据的相关矩阵

问题描述 投票:-1回答:1

我想为我的面板日期集创建一个相关矩阵。我的数据集按以下方式构建,我对公司的8年时间框架有以下数据:LEV,DOI,INDU,GROWTH,SIZE,ROE,AGE:

因此,我的输入文件看起来像

company ----year -----LEV-----DOI

x-----------1 ---------6 -----10

x-----------2 ---------6 -----10

y-----------1 ---------6 -----10

y-----------2 ---------6 -----10

现在我想为变量的数据集创建一个相关矩阵,它应该如下所示:

---LEV------DOI----INDU----GROWTH

LEV

DOI

INDU

GROWTH

到目前为止我做了什么:

Leverage_alle  <- pdata.frame(Leverage, index=c("company", "year"))
Lev_data       <- Leverage_alle[Leverage_alle$id %in% c(1,2),c(1:4, 6:10)]

cor:如果我按以下方式使用它,函数不起作用:

cor(Leverage_alle,use = "pairwise.complete.obs")
Error in cor(Leverage_alle, use = "pairwise.complete.obs"):'x' muss numerisch sein

我找到了以下编码,但不知道如何将它应用到我的案例中,因为它

> cor(acast(Lev_data, year ~ id, value.var = 'XY'), use = 'pairwise.complete.obs')

我也尝试过:

Lev_data %>%
     spread(year, company) %>%
     select(-year) %>%
     cor(., use = "pairwise.complete.obs")

Error in eval(lhs, parent, parent) : object 'paneldata' not found
r regression panel correlation
1个回答
0
投票

相关矩阵中的所有项都必须是数字变量。我的德语生锈了,但错误信息“muss numerische sein”的意思是“必须是数字”。检查您尝试在cor()函数中使用的每列的数据类型。您可能已经读过一些列作为因子,因此需要使用as.numeric()函数将它们转换为数字。

© www.soinside.com 2019 - 2024. All rights reserved.