[R-sig-Geo] Spatial Panel Models Problem (Splm package)
Roger Bivand
Roger@Biv@nd @ending from nhh@no
Sat May 5 12:35:42 CEST 2018
On Sat, 5 May 2018, felipe tavares wrote:
> Good evening.
>
> I am trying to estimate a spatial panel data model through splm package.
>
> I am facing the error: Error in lag.listw(listw, u, zero.policy =
> zero.policy) :
> object lengths differ
>
> However, my W matrix is NxN, my y vector is NTx1 and my X matrix is NTxK.
>
> My code is:
> poly <- readOGR(dsn ="C:/Users/fstavares/OneDrive/Resource Policy Paper",
> layer = "RJ")
> RJ <- poly2nb(poly)
> W <- nb2listw(RJ, zero.policy = TRUE, style = "W", glist = NULL)
> SEM <- spml(gdp ~ oivrev, listw = W, model="within", spatial.error="b",
> lag=F, data=panel)
>
Are the first two columns of panel as required (from ?spml):
data: an object of class ‘data.frame’ or ‘pdata.frame’. A data
frame containing the variables in the model. When the object
is a ‘data.frame’, the first two columns shall contain the
indexes, unless otherwise specified. See ‘index’
From ?index
Panel data are stored in a ‘"pdata.frame"’ which has an ‘"index"’
attribute. Fitted models in ‘"plm"’ have a ‘"model"’ element which
is also a ‘"pdata.frame"’ and therefore also has an ‘"index"’
attribute. Finally, each series, once extracted from a
‘"pdata.frame"’, becomes of class ‘"pseries"’, which also has this
‘"index"’ attribute. ‘"index"’ methods are available for all
these objects. The argument ‘"which"’ indicates which index
should be extracted. If ‘which = NULL’, all indexes are extracted.
‘"which"’ can also be a vector of length 1, 2, or 3 (3 only if the
pdata frame was constructed with an additional group index)
containing either characters (the names of the individual variable
and/or of the time variable and/or the group variable or ‘"id"’
and ‘"time"’) and ‘"group"’ or integers (1 for the individual
index, 2 for the time index, and 3 for the group index (the latter
only if the pdata frame was constructed with such).)
and:
> str(Produc)
'data.frame': 816 obs. of 11 variables:
$ state : Factor w/ 48 levels "ALABAMA","ARIZONA",..: 1 1 1 1 1 1 1 1 1 1
...
$ year : int 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 ...
$ region: Factor w/ 9 levels "1","2","3","4",..: 6 6 6 6 6 6 6 6 6 6 ...
$ pcap : num 15033 15502 15972 16406 16763 ...
$ hwy : num 7326 7526 7765 7908 8026 ...
$ water : num 1656 1721 1765 1742 1735 ...
$ util : num 6051 6255 6442 6756 7002 ...
$ pc : num 35794 37300 38670 40084 42057 ...
$ gsp : int 28418 29375 31303 33430 33749 33604 35764 37463 39964
40979 ...
$ emp : num 1010 1022 1072 1136 1170 ...
$ unemp : num 4.7 5.2 4.7 3.9 5.5 7.7 6.8 7.4 6.3 7.1 ...
with the individual column first varying slowly, and the time column
second varying within the first column values. Since you do not provide a
reproducible example (not your data and code, an example using built-in
data), it is hard to know.
Hope this clarifies,
Roger
>
> Does anyone have faced this problem?
>
> I can send database and code, if it somebody can help me.
>
>
>
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
More information about the R-sig-Geo
mailing list