1

I'm trying to create a Panel data using the plm function for pooling a model from a balanced Panel data that I imported from Excel.

When I run the code I get the following error:

Error in class(x) <- setdiff(class(x), "pseries") : invalid to set the class to matrix unless the dimension attribute is of length 2 (was 0)

library(plm)
library(readxl)
library(tidyr)
library(rJava)
library(xlsx)
library(xlsxjars)

all_met<- read_excel("data.xlsx", sheet = "all_met")
attach(all_met)

Y_all_met <- cbind(methane)
X_all_met <- cbind(gdp, ecogr, trade)

pdata_all_met <- plm.data(all_met, index=c("id","time"))

pooling_all_met <- plm(Y_all_met ~ X_all_met, data=pdata_all_met, model= "pooling")

After running the code I was supposed to get summary statistics of a pooled ols regression of my data. Can someone tell me how I can fix this issue? Thanks in advance.

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
jdoe
  • 13
  • 1
  • 3

2 Answers2

3

1st:

Avoid plm.data and use pdata.frame instead:

pdata_all_met <- pdata.frame(all_met, index=c("id","time"))

If plm.data does not give you a deprecation warning, use a newer version of the package.

2nd (and addressing the question):

Specify the column names in the formula, not the variables from the global environment if you use the data argument of plm, i.e., try this:

plm(methane ~ gdp + ecogr + trade, data=pdata_all_met, model= "pooling")
Helix123
  • 3,502
  • 2
  • 16
  • 36
-1

check in the structure of your data if variables used in the regression are declared as factor, you can do that by typing: str(all_met).

if yes, then you should declare it as double, or as numeric, (try not to use as.numeric() function, it could change values in your data).

personally i've changed that by the next specification in the import code:

data <- read_csv("C:/Users/Uness/Desktop/Mydata.csv", 
    col_types = cols(variable1 = col_double(), 
        variable2 = col_double()))
View(data)

where variable1 and variable2 are the names of the variables I use, make sure you change that if you copy the code ;)