spdep lagsarlm regression error
It produces the following error. Error: length(listw$neighbours) == n is not TRUE
Do you have NA values in your dataframe 'mex'? The problem may be that using the option 'na.action=na.omit', lagsarlm() subsets the listw object, then the impact() function is waiting for the listw object of the subset. So, you may want to try to subset your W object, just before calling impact(). Also I recommend that you check that your data are in the same order that your listw object:
identical(attr(W, 'region.id'), rownames(sar.mex$X)) identical(attr(W, 'region.id'), names(sar.mex$y))