**[SP] spivregress** -- Spatial autoregressive models with endogenous covariates

__Syntax__

**spivregress** *depvar* [*varlist*_1] **(***varlist*_2 **=** *varlist*_iv**)** [*if*] [*in*] [**,**
*options*]

*varlist*_1 is the list of included exogenous regressors.

*varlist*_2 is the list of endogenous regressors.

*varlist*_iv is the list of excluded exogenous regressors used with
*varlist*_1 as instruments for *varlist*_2.

*options* Description
-------------------------------------------------------------------------
Model
__dvarl__**ag(***spmatname***)** spatially lagged dependent variable;
repeatable
__err__**orlag(***spmatname***)** spatially lagged errors; repeatable
__ivarl__**ag(***spmatname* **:** *varlist***)** spatially lagged exogenous variables from
*varlist*_1; 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
-------------------------------------------------------------------------

*varlist*_1, *varlist*_2, *varlist*_iv, and *varlist* specified in **ivarlag()** may
contain factor variables; see fvvarlist.
**coeflegend** does not appear in the dialog box.
See **[SP] spivregress postestimation** for features available after
estimation.

__Menu__

**Statistics > Spatial autoregressive models**

__Description__

**spivregress** is the equivalent of **ivregress** for spatial data. **spivregress**
fits spatial autoregressive (SAR) models, also known as simultaneous
autoregressive models, where the models may contain additional endogenous
variables as well as exogenous variables. These models can be used to
account for possible dependence between the outcome variable and the
unobserved errors.

For models without endogenous regressors, see **[SP] spregress**.

If you have not read **[SP] intro 1** - **[SP] intro 8**, you should do so before
using **spivregress**. Your data must be Sp data to use **spivregress**. 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__

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

**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 exogenous variables that define spatial lags of the
variables. The variables in *varlist* must be a subset of the
exogenous variables in *varlist*_1. This option is repeatable to allow
spatial lags created from different matrices. By default, no spatial
lags of the exogenous 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 **spivregress** but is not shown in
the dialog box:

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

__Examples__

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

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

Fit a generalized spatial two-stage least-squares regression
**. spivregress dui nondui vehicles i.dry (police = elect),** **dvarlag(W)**
**errorlag(W)**

Same as above but add a spatial lag of the covariate **dry**
**. spivregress dui nondui vehicles i.dry (police = elect),** **dvarlag(W)**
**errorlag(W) ivarlag(W: i.dry)**

__Stored results__

**spivregress** 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 comparison test
**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 comparison test
**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)** **spivregress**
**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