I am using a panel data set:
- y is my independent variable equal to 0 or 1 --> numeric
- x1 are my individuals --> numeric
- x2 are my time indicators --> numeric
- x3,x4,...,x65 are my independent variables --> character
In the code below I convert all variables to characters and want to let R know that I am using panel data by the pdata.frame command on the last line. However, the problem now is that the command pdata.frame converts the variables x2 and x3 (the individuals and time indicator) to factors even when stringsAsFactors=FALSE.
#Regressions
df=read_excel("C:/Users/Luuk/Desktop/Master Thesis EME/Data/indep_dep_indlevel.xlsx")
df_dep=data.frame(df[,79])
count=as.data.frame(rep(1:3669, times=1, each=3))
df=cbind(count,df[,3:79])
df_indep=data.frame(df[,c(1:5,8,10:15,17:25,27:44,45,53:77)])
dflm=cbind(df_dep,df_indep)
dflm1 <- data.frame(lapply(dflm, as.character), stringsAsFactors=FALSE)
names(dflm1)[c(2:66)] <- c(paste("x", 1:65, sep=""))
names(dflm1)[1] <- "y"
dflm2=pdata.frame(dflm1,index=c("x1","x2"),stringsAsFactors=FALSE)
Consequently, the following pooled OLS model estimation gives the error:
Error in class(x) <- setdiff(class(x), "pseries") :
adding class "factor" to an invalid object In addition: Warning message: In model.response(mf, "numeric") : using type = "numeric" with a factor response will be ignored
xnam <- paste("x", 3:65, sep="")
Formula <- formula(paste("y ~ ", paste(xnam, collapse=" + ")))
fit=plm(Formula, data=dflm2,model="pooling")
How can I make my pooled OLS estimation procedure work?