**[SP] spregress** -- Spatial autoregressive models

__Syntax__

Generalized spatial two-stage least squares

**spregress** *depvar* [*indepvars*] [*if*] [*in*]**,** **gs2sls** [*gs2sls_options*]

Maximum likelihood

**spregress** *depvar* [*indepvars*] [*if*] [*in*]**,** **ml** [*ml_options*]

*gs2sls_options* Description
-------------------------------------------------------------------------
Model
* **gs2sls** use generalized spatial two-stage
least-squares estimator
__dvarl__**ag(***spmatname***)** spatially lagged dependent variable;
repeatable
__err__**orlag(***spmatname***)** spatially lagged errors; repeatable
__ivarl__**ag(***spmatname* **:** *varlist***)** spatially lagged independent variables;
repeatable
__nocons__**tant** suppress constant term
__het__**eroskedastic** treat errors as heteroskedastic
**force** allow estimation when estimation sample
is a subset of the sample used to
create the spatial weighting matrix
**impower(***#***)** order of instrumental-variable
approximation

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

Optimization
*optimization_options* control the optimization process; seldom
used

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

*ml_options* Description
-------------------------------------------------------------------------
Model
* **ml** use maximum likelihood estimator
__dvarl__**ag(***spmatname***)** spatially lagged dependent variable; not
repeatable
__err__**orlag(***spmatname***)** spatially lagged errors; not repeatable
__ivarl__**ag(***spmatname* **:** *varlist***)** spatially lagged independent variables;
repeatable
__nocons__**tant** suppress constant term
__const__**raints(***constraints***)** apply specified linear constraints
**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

SE/Robust
**vce(***vcetype***)** *vcetype* may be **oim** or __r__**obust**

Reporting
__l__**evel(***#***)** set confidence level; default is
**level(95)**
__nocnsr__**eport** do not display constraints
*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 **gs2sls** or **ml**.
*indepvars* and *varlist* specified in **ivarlag()** may contain factor
variables; see fvvarlist.
**coeflegend** does not appear in the dialog box.
See **[SP] spregress postestimation** for features available after
estimation.

__Menu__

**Statistics > Spatial autoregressive models**

__Description__

**spregress** is the equivalent of **regress** for spatial data. **spregress** fits
spatial autoregressive (SAR) models, also known as simultaneous
autoregressive models. If you have not read **[SP] intro 1** - **[SP] intro 8**,
you should do so before using **spregress**.

To use **spregress**, your data must be Sp data. 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 spregress, gs2sls__

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

**gs2sls** requests that the generalized spatial two-stage least-squares
estimator be used.

**dvarlag(***spmatname***)** specifies a spatial weighting matrix that defines a
spatial lag of the dependent variable. This option is repeatable to
allow higher-order models. By default, no spatial lags of the
dependent variable are included.

**errorlag(***spmatname***)** specifies a spatial weighting matrix that defines a
spatially lagged error. This option is repeatable to allow
higher-order models. 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.

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

**heteroskedastic** specifies that the estimator treat the errors as
heteroskedastic instead of homoskedastic, which is the default; see
*Methods and formulas* in **[SP] spregress**.

**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**.

**impower(***#***)** specifies the order of an instrumental-variable approximation
used in fitting the model. The derivation of the estimator involves
a product of *#* matrices. Increasing *#* may improve the precision of
the estimation and will not cause harm, but will require more
computer time. The default is **impower(2)**. See *Methods and formulas*
for additional details on **impower(***#***)**.

+-----------+
----+ 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**.

+--------------+
----+ Optimization +-----------------------------------------------------

*optimization_options*: __iter__**ate(***#***)**, [__no__]__lo__**g**, __tr__**ace**, __grad__**ient**, **showstep**,
__hess__**ian**, __showtol__**erance**, __tol__**erance(***#***)**, __ltol__**erance(***#***)**, __nrtol__**erance(***#***)**,
and __nonrtol__**erance**; see **[M-5] optimize()**.

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

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

__Options for spregress, ml__

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

**ml** requests that the maximum likelihood estimator be used.

**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.

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

**constraints(***constraints***)**; 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 **spregress, gs2sls**.

**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.

+-----------+
----+ SE/Robust +--------------------------------------------------------

**vce(***vcetype***)** specifies the type of standard error reported, which
includes types that are derived from asymptotic theory (**oim**) and that
are robust to nonnormal independent and identically distributed
(i.i.d.) disturbance (**robust**). See **[R]** *vce_option*.

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

**level(***#***)**, **nocnsreport**; 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 **spregress, ml** but is not shown in
the dialog box:

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

__Examples__

Setup
**. copy http://www.stata-press.com/data/r15/homicide1990.dta .**
**. copy http://www.stata-press.com/data/r15/homicide1990_shp.dta .**
**. use homicide1990**
**. spset**

Create a contiguity weighting matrix with the default spectral
normalization
**. spmatrix create contiguity W**

Fit a generalized spatial two-stage least-squares regression
**. spregress hrate ln_population ln_pdensity gini,** **gs2sls dvarlag(W)**

Same as above but add a spatial autoregressive error term
**. spregress hrate ln_population ln_pdensity gini,** **gs2sls dvarlag(W)**
**errorlag(W)**

Same as above but add terms representing spatial lags of the independent
variables
**. spregress hrate ln_population ln_pdensity gini,** **gs2sls dvarlag(W)**
**errorlag(W)** **ivarlag(W: ln_population ln_pdensity gini)**

__Stored results__

**spregress, gs2sls** stores the following in **e()**:

Scalars
**e(N)** number of observations
**e(k)** number of parameters
**e(df_m)** model degrees of freedom
**e(df_c)** degrees of freedom for test of spatial terms
**e(iterations)** number of generalized method of moments iterations
**e(iterations_2sls)** number of two-stage least-squares 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 generalized method of moments converged, **0**
otherwise
**e(converged_2sls)** **1** if two-stage least-squares converged, **0** otherwise

Macros
**e(cmd)** **spregress**
**e(cmdline)** command as typed
**e(depvar)** name of dependent variable
**e(indeps)** names of independent variables
**e(idvar)** name of ID variable
**e(estimator)** **gs2sls**
**e(title)** title in estimation output
**e(constant)** **hasconstant** or **noconstant**
**e(exogr)** exogenous regressors
**e(dlmat)** names of spatial weighting matrices applied to
*depvar*
**e(elmat)** names of spatial weighting matrices applied to
errors
**e(het)** **heteroskedastic** or **homoskedastic**
**e(chi2type)** **Wald**; type of model chi-squared test
**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(marginsnotok)** predictions disallowed by **margins**
**e(asbalanced)** factor variables **fvset** as **asbalanced**
**e(asobserved)** factor variables **fvset** as **asobserved**

Matrices
**e(b)** coefficient vector
**e(delta_2sls)** two-stage least-squares estimates of coefficients
in spatial lag equation
**e(rho_2sls)** generalized method of moments estimates of
coefficients in spatial error equation
**e(V)** variance-covariance matrix of the estimators

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

**spregress, ml** stores the following in **e()**:

Scalars
**e(N)** number of observations
**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)** **spregress**
**e(cmdline)** command as typed
**e(depvar)** name of dependent variable
**e(indeps)** names of independent variables
**e(idvar)** name of ID variable
**e(estimator)** **ml**
**e(title)** title in estimation output
**e(constant)** **hasconstant** or **noconstant**
**e(dlmat)** name of spatial weighting matrix applied to *depvar*
**e(elmat)** name of spatial weighting matrix applied to errors
**e(chi2type)** {cmd Wald}; type of model chi-squared test
**e(vce)** *vcetype* specified in **vce()**
**e(vcetype)** title used to label Std. Err.
**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(marginsnotok)** predictions disallowed by **margins**
**e(asbalanced)** factor variables **fvset** as **asbalanced**
**e(asobserved)** factor variables **fvset** as **asobserved**

Matrices
**e(b)** coefficient vector
**e(Cns)** constraints matrix
**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