[R-sig-Geo] Error in "lag.listw(listw, xt, ...) : object lengths differ" to estimate panel SLX model

asmiro Abeje Fikadu @@m|ro2013 @end|ng |rom gm@||@com
Thu Jun 13 11:05:09 CEST 2019


Dear Members,

I am trying to estimate spatial lagged explanatory (SLX) model with R.
I did the following codes.
teffdata <- read_dta("pdata.dta.dta")  # Loaded the dataset
coordinates(teffdata) <- ~Latitude + Longitude
mycoords <- coordinates(teffdata)
dis_rd <- rdist.earth(mycoords, miles = FALSE)
# relabel rows/columns
temp <- teffdata$id
str(temp)
row.names(dis_rd) <- temp
colnames(dis_rd) <- temp
#Create neighbor list based on inverse distance
for(i in 1:dim(dis_rd)[1]) {dis_rd[i,i] = 0} # renders exactly zero all
diagonal elements, where dim is "dimension"
dis_rd[dis_rd > 160] <- 0                   # all distances > 80km are set
to zero ==> Why I choose 20 miles??
dis_rd <- ifelse(dis_rd!=0, 1/dis_rd, dis_rd) # calculating the inverse
distances
# Create the spatial weights based on inverse distance
nbl <- mat2listw(dis_rd, style="W")  # create a (normalized) listw object
or number of neighbors list
# Then, I converted the data.frame into pdata.frame
pd  <- pdata.frame(as.data.frame(teffdata), index = c("ID","year"))
# then,
# Creating specific pdata.frame spatial vectors, for instance:
speduc  <- pd$Educ
spage <- pd$Age
spext  <- pd$Ext
spcredit < pd$Credit # could not create this variable, look the label of it
spfert <- pd$FertilUsage
spswC <- pd$SWC
spsow <- pd$SowingMethod
spdmkt <- pd$dist_market
sprain <- pd$MRainfall
sphhsize <- pd$HHSIZE
spslope <- pd$Slope
spfertil <- pd$SoilFertilStatus
spgender <- pd$Gender
spseedtype <- pd$SeedType
spaez <- pd$AEZ
sptlu <- pd$TLU

# Specifying a formula for these models:
model <- ineff_translog_time ~ Educ + Age + Ext + Credit + FertilUsage +
SWC + SowingMethod +
  dist_market + MRainfall + HHSIZE + Slope + SoilFertilStatus + Gender +
SeedType + AEZ + TLU +
  slag(speduc, listw = nbl) + slag(spage, listw = nbl) + slag(spext, listw
= nbl) +
  slag(spfert, listw = nbl) + slag(spswC, listw = nbl) + slag(spsow, listw
= nbl) +
  slag(spdmkt, listw = nbl) + slag(sprain, listw = nbl) + slag(spfertil,
listw = nbl) +
  slag(spseedtype)

# Applying plm and splm functions on the original data (data.table
data.frame object):
regslx<-plm(model,data= as.data.frame(pd),listw = nbl,index=c("ID","year"),
            model="within", effect="twoways",spatial.error="none",lag=F)
summary(regslx)
# Finally, I got an error Error in "lag.listw(listw, xt, ...) : object
lengths differ"
Note: number of observations = 858
          number of time periods = 2
          I applied inverse distance based spatial weight matrix

So, could you please somone help me where I am getting wrong?




*Kind Regards,*
*Asmiro Abeje Fikadu*
*MSc student in Uni-Bonn, Germany*
*Address: Hainstrasse 52 /Zi. 229*
*                   P.O.BOX:  53121, Bonn*
*                   Cell phone: 015214173450*

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list