**[SP] spxtregress** -- Spatial autoregressive models for panel data

__Syntax__

Fixed-effects maximum likelihood

**spxtregress** *depvar* [*indepvars*] [*if*] [*in*]**,** **fe** [*fe_options*]

Random-effects maximum likelihood

**spxtregress** *depvar* [*indepvars*] [*if*] [*in*]**,** **re** [*re_options*]

*fe_options* Description
-------------------------------------------------------------------------
Model
* **fe** use fixed-effects estimator
__dvarl__**ag(***spmatname***)** spatially lagged dependent variable
__err__**orlag(***spmatname***)** spatially lagged errors
__ivarl__**ag(***spmatname* **:** *varlist***)** spatially lagged independent variables;
repeatable
**force** allow estimation when estimation sample
is a subset of the sample used to
create the spatial weighting matrix
__grid__**search(***#***)** resolution of the initial-value search
grid; seldom used

Reporting
__l__**evel(***#***)** set confidence level; default is
**level(95)**
*display_options* control columns and column formats, row
spacing, line width, display of omitted
variables and base and empty cells, and
factor-variable labeling

Maximization
*maximize_options* control the maximization process; seldom
used

__coefl__**egend** display legend instead of statistics
-------------------------------------------------------------------------

*re_options* Description
-------------------------------------------------------------------------
Model
* **re** use random-effects estimator
__dvarl__**ag(***spmatname***)** spatially lagged dependent variable
__err__**orlag(***spmatname***)** spatially lagged errors
__ivarl__**ag(***spmatname* **:** *varlist***)** spatially lagged independent variables;
repeatable
__sarpan__**el** alternative formulation of the estimator
in which the panel effects follow the
same spatial process as the errors
__nocons__**tant** suppress constant term
**force** allow estimation when estimation sample
is a subset of the sample used to
create the spatial weighting matrix

Reporting
__l__**evel(***#***)** set confidence level; default is
**level(95)**
*display_options* control columns and column formats, row
spacing, line width, display of omitted
variables and base and empty cells, and
factor-variable labeling

Maximization
*maximize_options* control the maximization process; seldom
used

__coefl__**egend** display legend instead of statistics
-------------------------------------------------------------------------

* You must specify either **fe** or **re**.
*indepvars* and *varlist* specified in **ivarlag()** may contain factor
variables; see fvvarlist.
**coeflegend** does not appear in the dialog box.
See **[SP] spxtregress postestimation** for features available after
estimation.

__Menu__

**Statistics > Spatial autoregressive models**

__Description__

**spxtregress** fits spatial autoregressive (SAR) models, also known as
simultaneous autoregressive models, for panel data. The commands
**spxtregress, fe** and **spxtregress, re** are extensions of **xtreg, fe** and
**xtreg, re** for spatial data; see **[XT] xtreg**.

If you have not read **[SP] intro 1** - **[SP] intro 8**, you should do so before
using **spxtregress**.

To use **spxtregress**, your data must be Sp data and **xtset**. See **[SP] intro**
**3** for instructions on how to prepare your data.

To specify spatial lags, you will need to have one or more spatial
weighting matrices. See **[SP] intro 2** and **[SP] spmatrix** for an
explanation of the types of weighting matrices and how to create them.

__Options for spxtregress, fe__

+-------+
----+ Model +------------------------------------------------------------

**fe** requests the fixed-effects regression estimator.

**dvarlag(***spmatname***)** specifies a spatial weighting matrix that defines a
spatial lag of the dependent variable. Only one **dvarlag()** option may
be specified. By default, no spatial lags of the dependent variable
are included.

**errorlag(***spmatname***)** specifies a spatial weighting matrix that defines a
spatially lagged error. Only one **errorlag()** option may be specified.
By default, no spatially lagged errors are included.

**ivarlag(***spmatname* **:** *varlist***)** specifies a spatial weighting matrix and a
list of independent variables that define spatial lags of the
variables. This option is repeatable to allow spatial lags created
from different matrices. By default, no spatial lags of the
independent variables are included.

**force** requests that estimation be done when the estimation sample is a
proper subset of the sample used to create the spatial weighting
matrices. The default is to refuse to fit the model. Weighting
matrices potentially connect all the spatial units. When the
estimation sample is a subset of this space, the spatial connections
differ and spillover effects can be altered. In addition, the
normalization of the weighting matrix differs from what it would have
been had the matrix been normalized over the estimation sample. The
better alternative to **force** is first to understand the spatial space
of the estimation sample and, if it is sensible, then create new
weighting matrices for it. See **[SP] spmatrix** and *Missing values,*
*dropped observations, and the W matrix* in **[SP] intro 2**.

**gridsearch(***#***)** specifies the resolution of the initial-value search grid.
The default is **gridsearch(0.1)**. You may specify any number between
0.001 and 0.1 inclusive.

+-----------+
----+ Reporting +--------------------------------------------------------

**level(***#***)**; see **[R] estimation options**.

*display_options*: **noci**, __nopv__**alues**, __noomit__**ted**, **vsquish**, __noempty__**cells**,
__base__**levels**, __allbase__**levels**, __nofvlab__**el**, **fvwrap(***#***)**, **fvwrapon(***style***)**,
**cformat(***%fmt***)**, **pformat(%***fmt***)**, **sformat(%***fmt***)**, and **nolstretch**; see **[R]**
**estimation options**.

+--------------+
----+ Maximization +-----------------------------------------------------

*maximize_options*: __dif__**ficult**, __tech__**nique(***algorithm_spec***)**, __iter__**ate(***#***)**,
[__no__]__lo__**g**, __tr__**ace**, __grad__**ient**, **showstep**, __hess__**ian**, __showtol__**erance**,
__tol__**erance(***#***)**, __ltol__**erance(***#***)**, __nrtol__**erance(***#***)**, and __nonrtol__**erance**; see
**[R] maximize**.

The following option is available with **spxtregress, fe** but is not shown
in the dialog box:

**coeflegend**; see **[R] estimation options**.

__Options for spxtregress, re__

+-------+
----+ Model +------------------------------------------------------------

**re** requests the generalized least-squares random-effects estimator.

**dvarlag(***spmatname***)** specifies a spatial weighting matrix that defines a
spatial lag of the dependent variable. Only one **dvarlag()** option may
be specified. By default, no spatial lags of the dependent variable
are included.

**errorlag(***spmatname***)** specifies a spatial weighting matrix that defines a
spatially lagged error. Only one **errorlag()** option may be specified.
By default, no spatially lagged errors are included.

**ivarlag(***spmatname* **:** *varlist***)** specifies a spatial weighting matrix and a
list of independent variables that define spatial lags of the
variables. This option is repeatable to allow spatial lags created
from different matrices. By default, no spatial lags of the
independent variables are included.

**sarpanel** requests an alternative formulation of the estimator in which
the panel effects follow the same spatial process as the errors. By
default, the panel effects are included in the estimation equation as
an additive term, just as they are in the standard nonspatial
random-effects model. When **sarpanel** and **errorlag(***spmatname***)** are
specified, the panel effects also have a spatial autoregressive form
based on *spmatname*. If **errorlag()** is not specified with **sarpanel**, the
estimator is identical to the estimator when **sarpanel** is not
specified. The **sarpanel** estimator was originally developed by
Kapoor, Kelejian, and Prucha (2007); see *Methods and formulas*.

**noconstant**; see **[R] estimation options**.

**force** requests that estimation be done when the estimation sample is a
proper subset of the sample used to create the spatial weighting
matrices. The default is to refuse to fit the model. This is the
same **force** option described for use with **spxtregress, fe**.

+-----------+
----+ Reporting +--------------------------------------------------------

**level(***#***)**; see **[R] estimation options**.

*display_options*: **noci**, __nopv__**alues**, __noomit__**ted**, **vsquish**, __noempty__**cells**,
__base__**levels**, __allbase__**levels**, __nofvlab__**el**, **fvwrap(***#***)**, **fvwrapon(***style***)**,
**cformat(***%fmt***)**, **pformat(%***fmt***)**, **sformat(%***fmt***)**, and **nolstretch**; see **[R]**
**estimation options**.

+--------------+
----+ Maximization +-----------------------------------------------------

*maximize_options*: __dif__**ficult**, __tech__**nique(***algorithm_spec***)**, __iter__**ate(***#***)**,
[__no__]__lo__**g**, __tr__**ace**, __grad__**ient**, **showstep**, __hess__**ian**, __showtol__**erance**,
__tol__**erance(***#***)**, __ltol__**erance(***#***)**, __nrtol__**erance(***#***)**, and __nonrtol__**erance**; see
**[R] maximize**.

The following option is available with **spxtregress, re** but is not shown
in the dialog box:

**coeflegend**; see **[R] estimation options**.

__Examples__

Setup
**. copy http://www.stata-press.com/data/r15/homicide_1960_1990.dta .**
**. copy http://www.stata-press.com/data/r15/homicide_1960_1990_shp.dta**
**.**
**. use homicide_1960_1990**
**. xtset _ID year**
**. spset**

Create a contiguity weighting matrix with the default spectral
normalization
**. spmatrix create contiguity W if year == 1990**

Fit a spatial autoregressive random-effects model
**. spxtregress hrate ln_population ln_pdensity gini i.year,** **re**
**dvarlag(W)**

Create an inverse-distance weighting matrix with the default spectral
normalization
**. spmatrix create idistance M if year == 1990**

Same as above but use the alternative formulation of the estimator
**. spxtregress hrate ln_population ln_pdensity gini i.year,** **re**
**sarpanel dvarlag(M) errorlag(M)**

Fit a spatial autoregressive fixed-effects model
**. spxtregress hrate ln_population ln_pdensity gini i.year,** **fe**
**dvarlag(M) errorlag(M)**

__Stored results__

**spxtregress, fe** and **spxtregress, re** store the following in **e()**:

Scalars
**e(N)** number of observations
**e(N_g)** number of groups (panels)
**e(g)** group size
**e(k)** number of parameters
**e(df_m)** model degrees of freedom
**e(df_c)** degrees of freedom for test of spatial terms
**e(ll)** log likelihood
**e(iterations)** number of maximum log-likelihood estimation
iterations
**e(rank)** rank of **e(V)**
**e(r2_p)** pseudo-R-squared
**e(chi2)** chi-squared
**e(chi2_c)** chi-squared for test of spatial terms
**e(p)** p-value for model test
**e(p_c)** p-value for test of spatial terms
**e(converged)** **1** if converged, **0** otherwise

Macros
**e(cmd)** **spxtregress**
**e(cmdline)** command as typed
**e(depvar)** name of dependent variable
**e(indeps)** names of independent variables
**e(idvar)** name of ID variable
**e(model)** **fe**, **re**, or **re sarpanel**
**e(title)** title in estimation output
**e(constant)** **hasconstant** or **noconstant** (**re** only)
**e(dlmat)** name of spatial weighting matrix applied to *depvar*
**e(elmat)** name of spatial weighting matrix applied to errors
**e(chi2type)** **Wald**; type of model chi-squared test
**e(vce)** **oim**
**e(ml_method)** type of **ml** method
**e(technique)** maximization technique
**e(properties)** **b V**
**e(estat_cmd)** program used to implement **estat**
**e(predict)** program used to implement **predict**
**e(marginsok)** predictions allowed by **margins**
**e(asbalanced)** factor variables **fvset** as **asbalanced**
**e(asobserved)** factor variables **fvset** as **asobserved**

Matrices
**e(b)** coefficient vector
**e(ilog)** iteration log (up to 20 iterations)
**e(gradient)** gradient vector
**e(Hessian)** Hessian matrix
**e(V)** variance-covariance matrix of the estimators

Functions
**e(sample)** marks estimation sample

__Reference__

Kapoor, M., H. H. Kelejian, and I. R. Prucha. 2007. Panel data models
with spatially correlated error components. *Journal of Econometrics*
140: 97-130.