2014-03-25 63 views
1

我使用PLM-包中的R有一個問題:錯誤消息:變量長度不同

假設DATA1是我的數據集,我TREID估計彙集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

將所有迴歸變量與as.numeric()解決了我的問題。 plm() - 命令現在正在工作。謝謝! –

+0

請非常小心你的數據,但:對* N *清理(記錄數)的輸出,以確保您的迴歸集是什麼,你認爲它是。 –

回答

1

你的變量需求似乎是一個因素。由於您使用plm我假設你想,作爲一個數字。您可以使用as.numeric進行轉換。