Silvia
Silvia

Reputation: 41

How to include a spatial lag of an explanatory variable in a panel spatial model?

I am doing a spatial durbin model with spml function (splm package), I have included as regressors a polynom (grade 2) and obviosly I need to include its spatial lag too. Unfortunately the function slag and lag.listw don't work with a poly function, giving me the errors :

no applicable method for 'slag' applied to an object of class "c('poly', 'matrix')"

and

Error in lag.listw(dist.listw, poly(GDP.PCAP, 2)) : object lengths differ

Insert the two variables manually is excluded since the model does not work for singularity problems.

If someone can help me I would really appreciate.

Thanks Silvia

Upvotes: 4

Views: 838

Answers (1)

desval
desval

Reputation: 2435

You can indeed include spatially lagged explanatory variables using slag. However, you need to make sure that your data is of class pdata.frame.

A reproducible example:

library(plm)
library(spatialreg)
library(splm)

# load data
data(Produc, package = "plm")
data(usaww, package = "splm")

d <- pdata.frame(Produc, index = c("state","year"), drop.index = FALSE)

# create a spatial explanatory variable
d$unemp_l <- slag(d$unemp, usaww)

# run model
m <- splm::spml(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp + unemp_l,
                  data = d, listw = mat2listw(usaww) , model="within")
summary(m)
Spatial panel fixed effects error model


Call:
splm::spml(formula = log(gsp) ~ log(pcap) + log(pc) + log(emp) + 
    unemp + unemp_l, data = d, listw = mat2listw(usaww), model = "within")

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.1211492 -0.0234013 -0.0040218  0.0167919  0.1787587 

Spatial error parameter:
    Estimate Std. Error t-value  Pr(>|t|)    
rho 0.542254   0.033772  16.056 < 2.2e-16 ***

Coefficients:
            Estimate Std. Error t-value Pr(>|t|)    
log(pcap)  0.0090575  0.0251036  0.3608  0.71824    
log(pc)    0.2152367  0.0234077  9.1951  < 2e-16 ***
log(emp)   0.7833003  0.0277672 28.2096  < 2e-16 ***
unemp     -0.0014795  0.0011443 -1.2930  0.19603    
unemp_l   -0.0031210  0.0015790 -1.9766  0.04808 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

You can verify that the spatial explanatory is correct. For instance:

a <- usaww["ALABAMA",]
a <- a[a!=0]
a
    FLORIDA     GEORGIA MISSISSIPPI    TENNESSE 
       0.25        0.25        0.25        0.25 
mean(d[d$year=="1970" & d$state %in% names(a) , "unemp"])
[1] 4.525

d[d$state=="ALABAMA" & d$year=="1970", "unemp_l"]
ALABAMA-1970 
   4.525 

Upvotes: 2

Related Questions