【发布时间】:2021-12-24 01:28:20
【问题描述】:
我正在研究国家和行业因素(例如 GDP、进口、出口)对工资差异的影响。我在 5 年内收集了 75 个国家、19 个行业的行业级数据,并尝试使用固定效应模型进行分析。
我想知道如何使用 R 将数据集识别为按部门和时间划分的面板数据。我了解到以下代码将用于 Stata。 R有类似的代码吗?
egen country_industry = group(country industry)
xtset country_industry time
我尝试在 R 中使用以下代码,但没有成功:
library(plm)
panel8 =pdata.frame(sampledata7_industry, index=c("id","industry","year"))
错误代码如下:
> library(plm)
> panel8 =pdata.frame(sampledata7_industry, index=c("id","industry","year"))
Warning message:
In pdata.frame(sampledata7_industry, index = c("id", "industry", :
duplicate couples (id-time) in resulting pdata.frame
to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
我的数据前几行如下: sampledata7_industry
我应该重新编号ID以结合国家和行业吗?一种思路如下:
【问题讨论】:
-
请提供数据。至少有几行,所以我们可以重现它。您可以使用函数
dput()发布最小数据集。 -
@Bloxx 感谢您的评论。如上所述,我添加了我的数据集“sampledata7_industry”的前几行。
标签: r panel-data plm