Hello, i would like to run spatial autoregressive lag model using lagsarlm.
I generate this data and try to run the regression:
library(splm)
# tady si nageneruji nejaka random data
set.seed(123)
id <- rep(1:10, each = 10)
time <- rep(1:10, times = 10)
income <- rnorm(1000, mean = 50, sd = 10)
crime <- rnorm(1000, mean = 10, sd = 2)
data <- data.frame(id, time, income, crime)
# create matrix
mat <- matrix(sample(c(0,1), 10*10, replace=TRUE), nrow=10, ncol=10)
mat[lower.tri(mat)] <- t(mat)[lower.tri(mat)]
diag(mat) <- 0
w <- mat2listw(mat, style="B")
# to panel data structure
pdata <- pdata.frame(data, index=c("id", "time"), row.names = FALSE)
# THIS WORKS
# fe_model <- plm(crime ~ income, data=pdata, index=c("id", "time"), model="within")
# Create SPML model object
spml_model <- spml(crime ~ income, data = pdata, listw = w, lag = TRUE, model = "random", index=c("id", "time"))
# I got error Error in w %*% y : non-conformable arguments
# Print model summary
summary(spml_model)
But I got an error Error in w %*% y : non-conformable arguments
. What do I do wrong please?