Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Error: Can't join on '.rows' x '.rows' because of incompatible types (list / list)" using censReg

Tags:

r

I'm trying to run a tobit regression in r using the censReg package. I have panel data with a number of firms over several years. I set the data up using pdata.frame but when I try to run the regression this error message pops up:

Error: Can't join on '.rows' x '.rows' because of incompatible types (list / list)

What do I need to do to solve this issue?

testPanelData <- pdata.frame(testSample, index = c("gvkey", "fyear"))
estResult <- censReg(REP ~ Cash + Size + Leverage, data = testPanelData)
#Error: Can't join on '.rows' x '.rows' because of incompatible types (list / list)
like image 924
Michael Avatar asked May 10 '19 10:05

Michael


1 Answers

Is your data grouped using dplyr's group_by()? If yes you will get this error when running a plm::plm() model. To fix it, append ungroup() to your dplyr command, e.g.:

library(plm)
library(dplyr)

data(mtcars)

d_grp <- mtcars %>% group_by(cyl)

pd <- pdata.frame(d_grp, index = c("cyl"))
plm(mpg ~ hp, data = pd) # Generates the error:
# Error: Can't join on '.rows' x '.rows' because of incompatible types (list / list)

# To fix:
d_grp2 <- d_grp %>% ungroup()
pd2 <- pdata.frame(d_grp2, index = c("cyl"))
plm(mpg ~ hp, data = pd2) # No error


like image 191
potterzot Avatar answered Oct 31 '22 08:10

potterzot