Learn R Programming

splm (version 1.6-5)

spgm: GM estimation of spatial panel data models

Description

GM estimation of panel data models with spatially correlated errors components of the form:

$$ y_N(t) = \lambda W y + X_N(t) \beta + u_N(t) $$

$$ u_N(t) = \rho W_N u_N(t) + \epsilon(t)$$

$$ \epsilon_N = (e_T \otimes I_N ) \mu_N + \nu_N $$

where \( \rho\), and the variance components \(\sigma^2_\mu\) and \(\sigma^2_\nu\) are estimated by GM, and the model coefficients by a Feasible GLS estimator. The model can also include additional (other than the spatial lag) endogenous variables.

Usage

spgm(formula, data=list(), index=NULL, listw = NULL, listw2 = NULL, Durbin = FALSE,
         model = c("within", "random"), lag = FALSE, spatial.error = TRUE,
         moments = c("initial", "weights", "fullweights"), endog = NULL, 
         instruments = NULL, lag.instruments = FALSE, verbose = FALSE, 
         method = c("w2sls", "b2sls", "g2sls", "ec2sls"), control = list(), 
         optim.method = "nlminb",  pars = NULL)

Value

An object of class "splm".

coefficients

GLS coefficients estimate of the model parameters

vcov

the variance covariance matrix of the estimated coefficients

residuals

the GLS residuals

fitted.values

difference between response variable and residuals

sigma2

GLS residuals variance

type

'a description of the model estimated'

rho

a vector including the spatial parameter and the variance components (see Details)

model

the matrix of the data used

call

the call used to create the object

Arguments

formula

a description of the model to be fit. The details of model specification are given for lm

data

an object of class data.frame or pdata.frame. An optional data frame containing the variables in the model. When the obect is a data.frame, the first two columns may contain the indexes. See index

index

if not NULL (default), a character vector to identify the indexes among the columns of the data.frame

listw

an object of class listw, matrix, or Matrix

.

listw2

an object of class listw, matrix, or Matrix. Only if both lag and spatial.error are both TRUE

Durbin

default FALSE. If TRUE all the regressors are also spatially lagged. If it is a formula (Durbin = ~ xi + x2), only the variables specified in the formula are lagged.

model

One of "within" or "random". The assumption made on the individual effects

lag

if TRUE a spatial lag of the dependent variable is added to the regression equation

spatial.error

a logic vector. If TRUE the spatial autoregressive error term is added to the model and an estimate for \(\rho\) is produced

moments

"initial" (default) defines the set of GM estimator to be used. Alternatives are "weights" and "fullweights" (See Details)

endog

additional endogenous variables. Default NULL. If not NULL should be specified as a formula with no dependent variable (endog = ~ x1 + x2). Note the ~ before the expression.

instruments

external instruments. Default NULL. If not NULL should be specified as a formula with no dependent variable (instruments = ~ x1 + x2). Note the ~ before the expression.

lag.instruments

should the external instruments be spatially lagged?

verbose

default fALSE, If TRUE reports function values during optimization

method

One of "w2sls", "b2sls", "g2sls", "ec2sls". (See Details)

control

a list of control parameters for the optimization

optim.method

default set to "nlminb". or optionally a method passed to optim to use an alternative optimizer.

pars

initial values of the parameter rho and sigmav. The default for rho is to start from a regression of the spatially lagged residuals on the residuals (depending on the model). for sigmav the starting value is the variance of the residuals (again this depends on the model).

Author

Gianfranco Piras

Details

The function is a very general interface to estimate various nested specifications of the general model including additional endogenous variables described above. When both spatial.error and lag are FALSE the model reduces to a panel data model with an additional endogeneous variable. The function then uses ivsplm to perform the Instrumental Variables and two-stage least squares for panel data model. method = "w2sls" corresponds to the fixed effects estimator, method = "b2sls" to the between effects model, method = "g2sls" to the GLS random effects model, and method = "ec2sls" to the Baltagi's EC2SLS.

When spatial.error is TRUE and lag is FALSE the model is one with spatially autocorrelated error components. If effects is "random", the Kapoor et al. (2007) GM estimator is performed and the residuals in the first step come from an OLS regression. When moments is "initial", the initial estimator is calculated. This first set of GM estimators is based only on a subset of the moments conditions and assigns equal weigths to each of them. When moments is "fullweights", the second set of GM estimators is calculated. This estimator is based on the full set of moments conditions. It also involves the expression for the variance covariance matrix of the sample moments calculated under the assumption of normally distributed innovations. The calculation of the trace terms in the expression of the variance covariance matrix of the sample moments uses codes from the Matrix package. When moments is"weights", the third set of GM estimator is used. This is motivated by computational issues. The procedure is analogous to the second one but uses a simplified expression for the variance covariance matrix of the sample moments. If effects is "fixed", the initial estimator is a within estimator and the moments conditions of Kapoor et al. (2007) are modified accordingly.

Finally, when both spatial.error and lag are TRUE the complete model is estimated (with or without additional endogenous variables). OLS residuals are no longer consistent because of the spatially lagged dependent variable. If effects is "random", two initial estimators are computed: a within two-stage least squares and a between two stage least squares. The two sets of corresponding residuals are used in the spatial generalized moments estimator (GM) where the moments conditions of Kapoor et al. (2007) are again modified accordingly. If effects is "fixed", the initial estimator is a within two stage least squares estimator and the moments conditions of Kapoor et al. (2007) are modified accordingly.

Note that for the random effects models, \(\sigma^2_\mu\) is not reported. \(\sigma^2_1\) is reported instead. However, a value for \(\sigma^2_\mu\) can easily be obtained from: $$\sigma^2_1 = \sigma^2_\nu + T \sigma^2_\mu$$ The function also produces an estimate for \(\theta\) which is a function of the variance components.

References

Kapoor, M., Kelejian, H.H. and Prucha, I.R. (2007) Panel data model with spatially correlated error components, Journal of Econometrics, 140, pages 97--130.

Mutl, J., and Pfaffermayr, M. (2011) The Hausman test in a Cliff and Ord panel model, Econometrics Journal, 14, pages 48--76.

Kelejian, H.H. and Prucha, I.R. (1999) A Generalized Moments Estimator for the Autoregressive Parameter in a Spatial Model, International Economic Review, 40, pages 509--533.

Kelejian, H.H. and Prucha, I.R. (1999) A Generalized Spatial Two Stage Least Square Procedure for Estimating a Spatial Autoregressive Model with Autoregressive Disturbances, Journal of Real Estate Finance and Economics, 17, pages 99--121.

Millo, G., Piras, G. (2012) splm: Spatial Panel Data Models in R. Journal of Statistical Software, 47(1), 1--38. URL http://www.jstatsoft.org/v47/i01/.

Examples

Run this code
library(splm)
library(plm)
data(Produc)
data(usaww)
########SPATIAL LAG MODEL######
#no space no endog: error use plm
if (FALSE) GM_lag_b2sls <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                     lag = FALSE, spatial.error = FALSE, method = "b2sls",
                     listw = usaww)
#no space but endog 
GM_b2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                       lag = FALSE, spatial.error = FALSE, endog = ~ log(pcap),
                       method = "b2sls",
                       instruments = ~log(hwy), listw = usaww)
summary(GM_b2sls_e)
GM_g2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                   lag = FALSE, spatial.error = FALSE, endog = ~ log(pcap),
                   method = "g2sls",
                   instruments = ~log(hwy), listw = usaww)
summary(GM_g2sls_e)
GM_ec2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                   lag = FALSE, spatial.error = FALSE, endog = ~ log(pcap),
                   method = "ec2sls",
                   instruments = ~log(hwy), listw = usaww)
summary(GM_ec2sls_e)
GM_w2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                   lag = FALSE, spatial.error = FALSE, endog = ~ log(pcap),
                   method = "w2sls",
                   instruments = ~log(hwy), listw = usaww)
summary(GM_w2sls_e)
#SPATIAL LAG MODEL 
GM_lag_b2sls <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
           lag = TRUE, spatial.error = FALSE, method = "b2sls",
           listw = usaww)
summary(GM_lag_b2sls)
GM_lag_g2sls <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
           lag = TRUE, spatial.error = FALSE, method = "g2sls",
           listw = usaww)
summary(GM_lag_g2sls)
GM_lag_ec2sls <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
           lag = TRUE, spatial.error = FALSE, method = "ec2sls",
           listw = usaww)
summary(GM_lag_ec2sls)
GM_lag_w2sls <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
           lag = TRUE, spatial.error = FALSE,
           listw = usaww, method = "w2sls")
summary(GM_lag_w2sls)
#endogenous
GM_lag_b2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                  lag = TRUE,
                  spatial.error = FALSE, endog = ~ log(pcap),
                  method = "b2sls",
                  instruments = ~log(hwy), listw = usaww)
summary(GM_lag_b2sls_e)
GM_lag_g2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                       lag = TRUE,
                       spatial.error = FALSE, endog = ~ log(pcap),
                       method = "g2sls",
                       instruments = ~log(hwy), listw = usaww)
summary(GM_lag_g2sls_e)
GM_lag_ec2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                       lag = TRUE,
                       spatial.error = FALSE, endog = ~ log(pcap),
                       method = "ec2sls",
                       instruments = ~log(hwy), listw = usaww)
summary(GM_lag_ec2sls_e)
GM_lag_w2sls_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                       lag = TRUE,
                       spatial.error = FALSE, endog = ~ log(pcap),
                       method = "w2sls",
                       instruments = ~log(hwy), listw = usaww)
summary(GM_lag_w2sls_e)

########SPATIAL ERROR MODEL######
GM_error_within <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                     lag = FALSE, spatial.error = TRUE, model = "within",
                     listw = usaww)
summary(GM_error_within)
GM_error_random <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                        lag = FALSE, spatial.error = TRUE, model = "random",
                        listw = usaww)
summary(GM_error_random)
GM_error_within_fw <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                        lag = FALSE, spatial.error = TRUE, model = "within",
                        listw = usaww, moments = "fullweights")
summary(GM_error_within_fw)
GM_error_random_w <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                        lag = FALSE, spatial.error = TRUE, model = "random",
                        listw = usaww, moments = "fullweights")
summary(GM_error_random_w)
#endogenous
GM_error_within_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                        lag = FALSE,
                        spatial.error = TRUE, endog = ~ log(pcap),
                        model = "within",
                        instruments = ~log(hwy), listw = usaww)
summary(GM_error_within_e)
GM_error_random_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                       lag = FALSE,
                       spatial.error = TRUE, endog = ~ log(pcap),
                       model = "random",
                       instruments = ~log(hwy), listw = usaww)
summary(GM_error_random_e)

########SARAR MODEL######
GM_sarar_within <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                        lag = TRUE, spatial.error = TRUE, model = "within",
                        listw = usaww)
summary(GM_sarar_within)
GM_sarar_random <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                        lag = TRUE, spatial.error = TRUE, model = "random",
                        listw = usaww)
summary(GM_sarar_random)
GM_sarar_within_fw <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                           lag = TRUE, spatial.error = TRUE, model = "within",
                           listw = usaww, moments = "fullweights")
summary(GM_sarar_within_fw)
GM_sarar_random_fw <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                          lag = TRUE, spatial.error = TRUE, model = "random",
                          listw = usaww, moments = "fullweights")
summary(GM_sarar_random_fw)
#endogenous
GM_sarar_within_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                          lag = TRUE,
                          spatial.error = TRUE, endog = ~ log(pcap),
                          model = "within",
                          instruments = ~log(hwy), listw = usaww)
summary(GM_sarar_within_e)
GM_sarar_random_e <- spgm(log(gsp) ~  log(pc) + unemp, data=Produc,
                          lag = TRUE,
                          spatial.error = TRUE, endog = ~ log(pcap),
                          model = "random",
                          instruments = ~log(hwy), listw = usaww)
summary(GM_sarar_random_e)

Run the code above in your browser using DataLab