spml Error in if (!balanced) stop("Estimation method unavailable for unbalanced panels") : missing value where TRUE/FALSE necessary

Hello,

I am trying to run a spatial panel data regression with a csv file I created. I have made sure all columns are numeric and factors (except for the id). I have removed duplicated couples and made sure the data is balanced. However, when I do the regression I get the following error: Error in if (!balanced) stop("Estimation method unavailable for unbalanced panels") : missing value where TRUE/FALSE necessary

eureg <- readOGR(file.choose()) #Choose shp
SPECIALI <- read.csv(file.choose(), header = TRUE, sep = ",")
SPECIALI <- mutate_at(SPECIALI, vars(SPEC2007:AIR2017), as.factor)
SPECIALI <- SPECIALI %>% convert(num(SPEC2007:AIR2017))
DATA <- merge(eureg, SPECIALI, by.x = 'NUTS_ID',by.y='GEO',duplicateGeoms=TRUE)

n.4near = knearneigh(coordinates(DATA),k=20,longlat=FALSE)
n.4near.nb = knn2nb(n.4near)
plot(n.4near.nb, coordinates(DATA))

unga = nb2listw(n.4near.nb)

LONGO = reshape(as.data.frame(DATA),direction = "long", sep = "", v.names=c("SPEC","GDP","RAIL","MOTOR","MARI","KAP","AIR"),times = c(2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017), timevar="year",varying = c("SPEC2007", "SPEC2008", "SPEC2009", "SPEC2010", "SPEC2011", "SPEC2012","SPEC2013","SPEC2014","SPEC2015", "SPEC2016", "SPEC2017", "GDP2007","GDP2008", "GDP2009","GDP2010","GDP2011","GDP2012", "GDP2013", "GDP2014", "GDP2015","GDP2016", "GDP2017", "RAIL2007", "RAIL2008","RAIL2009", "RAIL2010", "RAIL2011", "RAIL2012","RAIL2013", "RAIL2014", "RAIL2015", "RAIL2016","RAIL2017", "MOTOR2007", "MOTOR2008", "MOTOR2009","MOTOR2010", "MOTOR2011", "MOTOR2012", "MOTOR2013","MOTOR2014","MOTOR2015","MOTOR2016","MOTOR2017","MARI2007","MARI2008","MARI2009","MARI2010","MARI2011","MARI2012","MARI2013","MARI2014","MARI2015","MARI2016","MARI2017","KAP2007","KAP2008","KAP2009","KAP2010","KAP2011","KAP2012","KAP2013","KAP2014","KAP2015","KAP2016","KAP2017","AIR2007","AIR2008","AIR2009","AIR2010","AIR2011","AIR2012","AIR2013","AIR2014","AIR2015","AIR2016","AIR2017"))
LONGO <- mutate_at(LONGO, vars(SPEC:AIR), as.factor)
LONGO$UNIQUE_ID <- paste(LONGO$NUTS_ID,LONGO$year) # concatenate to make unique ID
LONGO$duplicate = duplicated(LONGO$UNIQUE_ID) # generate the duplicate variable
subset(LONGO, duplicate=="TRUE")
 [1] NUTS_ID    LEVL_CODE  CNTR_CODE  NAME_LATN  NUTS_NAME  MOUNT_TYPE URBN_TYPE 
 [8] COAST_TYPE FID        year       SPEC       GDP        RAIL       MOTOR     
[15] MARI       KAP        AIR        id         UNIQUE_ID  duplicate 
<0 rows> (or 0-length row.names)
LONGO2= subset(LONGO, select = -c(LEVL_CODE,CNTR_CODE,NAME_LATN,NUTS_NAME,MOUNT_TYPE,URBN_TYPE,COAST_TYPE,FID) )
LONGO2$country_id <- as.numeric(factor(LONGO2$NUTS_ID)) # numeric country ID
LONGO2_balanced <- make.pbalanced(LONGO2, 
                               balance.type = c("fill"), 
                               index = c("country_id","year"))
is.pbalanced(LONGO2)
[1] TRUE

fm <- SPEC~GDP+AIR
MyRegression <- spml(formula = fm, data = LONGO2_balanced, index=NULL,
                     listw = unga, model = "within", effect = "twoways", lag = TRUE, spatial.error = "b")
Error in if (!balanced) stop("Estimation method unavailable for unbalanced panels") : 
  missing value wheree TRUE/FALSE needed

heads
I have no idea why this error happens nor how to solve it.
I hope someone can help me.
Thank you

The error cannot be reproduced without data. The documentation has only one mention of unbalanced panels, in connection with a different function than called here. The spml function code itself does not have an error return for this condition, so it must arise from some function that it calls. Two suggestions:

  1. Read the original paper
    citEntry(entry = "Article",
    title = "{splm}: Spatial Panel Data Models in {R}",
    author = personList(as.person("Giovanni Millo"),
    as.person("Gianfranco Piras")),
    journal = "Journal of Statistical Software",
    year = "2012",
    volume = "47",
    number = "1",
    pages = "1--38",
    url = "http://www.jstatsoft.org/v47/i01/",

textVersion =
paste("Giovanni Millo, Gianfranco Piras (2012).",
"splm: Spatial Panel Data Models in R.",
"Journal of Statistical Software, 47(1), 1-38.",
"URL http://www.jstatsoft.org/v47/i01/.")
)
2. Appeal to the maintainer Giovanni Millo at the email address given on the first page of the manual.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.