我在R:
中使用plm-package时遇到问题假设data1是我的数据集,我决定估算合并的OLS模型:
plm(demand ~ storage + ABB ,data=data1, model="pooling", index = c("country","month"))
但收到错误消息:
> plm(demand ~ storage + ABB ,data=data1, model="pooling", index = c("country","month"))
Error in model.frame.default(formula = y ~ X - 1, drop.unused.levels = TRUE) :
variable lengths differ (found for 'X')
以下是有关我的数据集的一些信息:
> summary(data1)
country month demand storage ABB
Australia: 362 01.01.1984: 47 0,75 : 47 0,100000000000009: 4 101052266666667,00: 2
Austria : 362 01.01.1985: 47 2,17 : 32 1,2 : 3 10308680,00 : 2
Belgium : 362 01.01.1986: 47 1,25 : 26 10,8 : 3 10332560,00 : 2
Brazil : 362 01.01.1987: 47 0,83 : 24 19,8 : 3 10335710,00 : 2
Canada : 362 01.01.1988: 47 3,25 : 17 464,4 : 3 10336160,00 : 2
Chile : 362 01.01.1989: 47 (Other):11393 (Other) : 6097 (Other) :15544
(Other) :14816 (Other) :16706 NA's : 5449 NA's :10875 NA's : 1434
> class(data1)
[1] "data.frame"
> str(data1)
'data.frame': 16988 obs. of 5 variables:
$ country: Factor w/ 47 levels "Australia","Austria",..: 1 1 1 1 1 1 1 1 1 1 ...
$ month : Factor w/ 362 levels "01.01.1984","01.01.1985",..: 1 32 63 93 123 153 183 213 243 273 ...
$ demand : Factor w/ 8907 levels "-0,25","-85,17",..: 8198 8639 8870 8639 463 605 898 807 599 302 ...
$ storage: Factor w/ 6041 levels "0,0274661240604858",..: NA NA NA NA NA NA NA NA NA NA ...
$ ABB : Factor w/ 15541 levels "100.054.416.666.667",..: 4192 4200 4210 4221 4232 4244 4257 4272 4278 4283 ...
有人可以帮助我吗?
答案 0 :(得分:1)
您的变量需求似乎是一个因素。由于您正在使用plm
,我认为您希望将其作为数字。您可以使用as.numeric
进行转换。