*! version 0.99 27aug2012

*! version 1 20oct2012

*! version 1.0.3 21jan2012

*! version 1.0.4 18jun2013

*! version 1.0.5 21jun2016

*! version 1.0.6 27jun2016

*! version 1.0.7 7sep2016

*! version 1.1 12sep2016

help xsmlealso see: xsmle_postestimation

Title

xsmle -- Spatial Panel Data Models

Syntax

Spatial Autoregressive (SAR) model

xsmle depvar [indepvars] [if] [in] [weight]
, wmat(name) model(sar) [SAR_options]

Spatial Durbin (SDM) model

xsmle depvar [indepvars] [if] [in] [weight]
, wmat(name) model(sdm) [SDM_options]

Spatial Autocorrelation (SAC) model

xsmle depvar [indepvars] [if] [in] [weight]
, wmat(name) emat(name) model(sac) [SAC_options]

Spatial Error (SEM) model

xsmle depvar [indepvars] [if] [in] [weight]
, emat(name) model(sem) [SEM_options]

Generalized Spatial Panel Random Effects (GSPRE) model

xsmle depvar [indepvars] [if] [in] [weight]
, wmat(name) model(gspre) [emat(name) GSPRE_options]

SAR_options

Model
wmat(name) specify the weight matrix for the spatial-autoregressive term

re use the random effects estimator; the default

fe use the fixed effects estimator

type(type_options[, leeyu]) specify fixed-effects type

SE/Robust
vce(vcetype) may be oim, opg, robust, cluster clustvar, dkraay #

robust synonym for vce(cluster panelvar)

cluster(clustvar) synonym for vce(cluster clustvar)

Other
dlag(dlag) includes time lagged dependent variable, space-time lagged dependent variable or both in the model

noconstant suppress the constant term in the model. Only for re estimator

effects computes direct, indirect and total effects and adds them to e(b)

vceeffects(vcee_type[, nsim(#)]) sets how the standard errors for the direct, indirect and total effects are computed

constraints(constraints) apply specified linear constraints

from(init_specs) specify initial values for the coefficients

hausman performs the Hausman test. Allowed only for static models

Reporting
level(#) set confidence level; default is level(95)

postscore save observation-by-observation scores in the estimation results list

posthessian save the Hessian corresponding to the full set of coefficients in the estimation results list

display_options control
spacing and display of omitted variables and base and empty cells

Maximization
maximize_options control the maximization process; seldom used

SDM_options

Model
wmat(name) specify the weight matrix for the spatial-autoregressive term

dmat(name) specify the weight matrix for the spatially lagged regressors; default is to use the wmat() matrix

durbin(varlist) specify the regressors that have to be spatially lagged; default is to lag all independent variables in varlist

re use the random effects estimator; the default

fe use the fixed effects estimator

type(type_options[, leeyu]) specify fixed-effects type

SE/Robust
vce(vcetype) may be oim, opg, robust, cluster clustvar, dkraay #

robust synonym for vce(cluster panelvar)

cluster(clustvar) synonym for vce(cluster clustvar)

Other
dlag(dlag) includes time lagged dependent variable, space-time lagged dependent variable or both in the model

noconstant suppress the constant term in the model. Only for re estimator

effects computes direct, indirect and total effects and adds them to e(b)

vceeffects(vcee_type[, nsim(#)]) sets how the standard errors for the direct, indirect and total effects are computed

constraints(constraints) apply specified linear constraints

from(init_specs) specify initial values for the coefficients

hausman performs the Hausman test. Allowed only for static models

Reporting
level(#) set confidence level; default is level(95)

postscore save observation-by-observation scores in the estimation results list

posthessian save the Hessian corresponding to the full set of coefficients in the estimation results list

display_options control spacing and display of omitted variables and base and empty cells

Maximization
maximize_options control the maximization process; seldom used

SAC_options

Model
wmat(name) specify the weight matrix for the spatial-autoregressive term

emat(name) specify the weight matrix used in the spatial error term; default is to use the wmat() matrix

fe use the fixed effects estimator

type(type_options[, leeyu]) specify fixed-effects type

SE/Robust
vce(vcetype) may be oim, opg, robust, cluster clustvar, dkraay #

robust synonym for vce(cluster panelvar)

cluster(clustvar) synonym for vce(cluster clustvar)

Other
effects computes direct, indirect and total effects and adds them to e(b)

vceeffects(vcee_type[, nsim(#)]) sets how the standard errors for the direct, indirect and total effects are computed

constraints(constraints) apply specified linear constraints

from(init_specs) specify initial values for the coefficients

Reporting
level(#) set confidence level; default is level(95)

postscore save observation-by-observation scores in the estimation results list

posthessian save the Hessian corresponding to the full set of coefficients in the estimation results list

display_options control
spacing and display of omitted variables and base and empty cells

Maximization
maximize_options control the maximization process; seldom used

SEM_options

Model
emat(name) specify the weight matrix used in the spatial error term

re use the random effects estimator; the default

fe use the fixed effects estimator

type(type_options[, leeyu]) specify fixed-effects type

SE/Robust
vce(vcetype) may be oim, opg, robust, cluster clustvar, dkraay #

robust synonym for vce(cluster panelvar)

cluster(clustvar) synonym for vce(cluster clustvar)

Other
noconstant suppress the constant term in the model. Only for re estimator

constraints(constraints) apply specified linear constraints

from(init_specs) specify initial values for the coefficients

hausman performs the Hausman test

Reporting
level(#) set confidence level; default is level(95)

postscore save observation-by-observation scores in the estimation results list

posthessian save the Hessian corresponding to the full set of coefficients in the estimation results list

display_options control
spacing and display of omitted variables and base and empty cells

Maximization
maximize_options control the maximization process; seldom used

GSPRE_options

Model
wmat(name) specify the weight matrix used for the spatial random effect component. Either/both wmat() or emat() is/are required according to error(#)

emat(name) specify the weight matrix used for the spatial error component. Either/both wmat() or emat() is/are required

re use the random effects estimator; the default

error(#) define the spatial random effect error structure

SE/Robust
vce(vcetype) may be oim, opg, robust, cluster clustvar, dkraay #

robust synonym for vce(cluster panelvar)

cluster(clustvar) synonym for vce(cluster clustvar)

Other
noconstant suppress the constant term in the model

constraints(constraints) apply specified linear constraints

from(init_specs) specify initial values for the coefficients

Reporting
level(#) set confidence level; default is level(95)

postscore save observation-by-observation scores in the estimation results list

posthessian save the Hessian corresponding to the full set of coefficients in the estimation results list

display_options control
spacing and display of omitted variables and base and empty cells

Maximization
maximize_options control the maximization process; seldom used

Type options

ind for individual fixed effects

time for time fixed effect

both for both time and individual fixed effects

leeyu transforms the data according to Lee & Yu (JoE, 2010)

Error options

error(1) for phi != lambda != 0 - the default

error(2) for phi != 0, lambda == 0

error(3) for phi == 0, lambda != 0, (equivalent to the SEM model)

error(4) for phi == lambda

vce effects type

dm for Delta Method standard errors

sim [,nsim(#)] for Monte Carlo standard errors (the default), using # replications (Lesage and Pace, 2009)

none for no standard errors

dlag options

dlag(1) includes time lagged dependent variable in the model (tau*y_it-1)

dlag(2) includes space-time lagged dependent variable in the model (psi*W*y_it-1)

dlag(3) includes both time lagged and space-time lagged dependent variable in the model (tau*y_it-1 + psi*W*y_it-1))

A panel and a time variable must be specified. Use xtset.

indepvars may contain factor variables; see fvvarlist.

aweights and iweights are allowed; see weight.

Weights must be constant within panel.

Multiple imputation is allowed; see mi.

Description

xsmle fits fixed or random effects spatial models for balanced panel data. See the mi prefix command in order to use xsmle in the unbalanced case. Consider the following general specification for the spatial panel data model:

y_it = tau*y_it-1 + psi*W*y_it-1 + rho*W*y_it + beta*X_it + D*Z_it*theta + a_i + gamma_t + v_it
v_it = lambda*E*v_it + u_it

where u_it is a normally distributed error term, W is the spatial matrix for the autoregressive component, D the spatial matrix for the spatially lagged independent variables, E the spatial matrix for the idiosyncratic error component.
a_i is the individual fixed or random effect and gamma_t is the time effect.
xsmle fits the following nested models:

i) the SAR model with lagged dependent variable (theta=lambda=psi=0)

y_it = tau*y_it-1 + rho*W*y_it + beta*X_it + a_i + gamma_t + u_it

ii) the SAR model with time and space lagged dependent variable (theta=lambda=tau=0)

y_it = psi*W*y_it-1 + rho*W*y_it + beta*X_it + a_i + gamma_t + u_it

iii) the full dynamic SAR model (theta=lambda=0)

y_it = tau*y_it-1 + psi*W*y_it-1 + rho*W*y_it + beta*X_it + a_i + gamma_t + u_it

iv) the classical SAR model (theta=lambda=psi=tau=0)

y_it = rho*W*y_it + beta*X_it + a_i + gamma_t + u_it

v) the SDM model with lagged dependent variable (lambda=psi=0)

y_it = tau*y_it-1 + rho*W*y_it + beta*X_it + D*Z_it*theta + a_i + gamma_t + u_it

vi) the SDM model with time and space lagged dependent variable (lambda=tau=0)

y_it = tau*y_it-1 + rho*W*y_it + beta*X_it + D*Z_it*theta + a_i + gamma_t + u_it

vii) the full dynamic SDM model (lambda=0)

y_it = tau*y_it-1 + psi*W*y_it-1 + rho*W*y_it + beta*X_it + D*Z_it*theta + a_i + gamma_t + u_it

viii) the classical SDM model (lambda=tau=psi=0)

y_it = rho*W*y_it + beta*X_it + D*Z_it*theta + a_i + gamma_t + u_it

xsmle allows to use a different weighting matrix for the spatially lagged dependent variable (W) and the spatially lagged regressors (D) together with a different sets of explanatory (X_it) and spatially lagged regressors (Z_it).
The default is to use W=D and X_it=Z_it.

ix) the SAC model (theta=tau=psi=0)

y_it = rho*W*y_it + beta*X_it + a_i + gamma_t + v_it
v_it = lambda*E*v_it + u_it

for which xsmle allows to use a different weighting matrix for the spatially lagged dependent variable (W) and the error term (E).

x) the SEM model (rho=theta=tau=psi=0)

y_it = beta*X_it + a_i + gamma_t + v_it
v_it = lambda*E*v_it + u_it

xi) the GSPRE model (rho=theta=tau=psi=0)

y_it = beta*X_it + a_i + v_it
a_i = phi*W*a_i + mu_i
v_it = lambda*E*v_it + u_it

where also the random effects have a spatial autoregressive form.

Options for the Spatial Autoregressive (SAR) model

Model

wmat(name) specifies the weight matrix for the spatial-autoregressive term. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

re use the random effects estimator; the default.

fe use the fixed effects estimator.

type(type_options[, leeyu]) specifies fixed-effects type. May be ind for individual fixed effects effects, time for time fixed effects or both for time and individual fixed effects.
Suboption leeyu transforms the data according to Lee & Yu (JoE, 2010).

Other

dlag(dlag) includes time lagged dependent variable, space-time lagged dependent variable or both in the model.

level(#) sets confidence interval level; default is level(95).

noconstant suppresses the constant term in the model. Only for re estimator.

effects computes direct, indirect and total effects and adds them to e(b).

vceeffects(vcee_type[, nsim(#)]) sets how the standard errors for the direct, indirect and total effects are computed. May be dm for Delta Method standard errors, sim[,nsim(#)] for Monte Carlo standard errors, where nsim(#) sets the number of simulations for the Lesage and Pace (2009) procedure, or none for no standard errors.

hausman performs the robust Hausman test, automatically detecting the alternative estimator. The test is computed estimating the variance covariance matrix of the difference between fe and re estimators as in White (1982). Allowed only for static models.

Options for the Spatial Durbin (SDM) model

Model

wmat(name) specifies the weight matrix for the spatial-autoregressive term. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

dmat(name) specifies the weight matrix for the spatially lagged regressors; default is to use the matrix specified in wmat(). name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

durbin(varlist) specifies the regressors that have to be spatially lagged; default is to lag all independent variables in varlist.

re use the random effects estimator; the default.

fe use the fixed effects estimator.

type(type_options[, leeyu]) specifies fixed-effects type. May be ind for individual fixed effects, time for time fixed effects or both for time and individual fixed effects.
Suboption leeyu transforms the data according to Lee & Yu (JoE, 2010).

Other

dlag(dlag) includes time lagged dependent variable, space-time lagged dependent variable or both in the model.

level(#) sets confidence interval level; default is level(95).

noconstant suppresses the constant term in the model. Only for re estimator.

effects computes direct, indirect and total effects and adds them to e(b).

vceeffects(vcee_type[, nsim(#)]) sets how the standard errors for the direct, indirect and total effects are computed. May be dm for Delta Method standard errors, sim[,nsim(#)] for Monte Carlo standard errors, where nsim(#) sets the number of simulations for the Lesage and Pace (2009) procedure, or none for no standard errors.

constraints(constraints) apply specified linear constraints.

hausman performs the robust Hausman test, automatically detecting the alternative estimator. The test is computed estimating the variance covariance matrix of the difference between fe and re estimators as in White (1982). Allowed only for static models.

Options for the Spatial Autocorrelation (SAC) model

Model

wmat(name) specifies the weight matrix for the spatial-autoregressive term. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

emat(name) specifies the weight matrix for the spatial-error term. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

type(type_options[, leeyu]) specifies fixed-effects type. May be ind for individual fixed effects, time for time fixed effects or both for time and individual fixed effects.
Suboption leeyu transforms the data according to Lee & Yu (JoE, 2010).

Other

level(#) sets confidence interval level; default is level(95).

effects computes direct, indirect and total effects and adds them to e(b).

vceeffects(vcee_type[, nsim(#)]) sets how the standard errors for the direct, indirect and total effects are computed. May be dm for Delta Method standard errors, sim[,nsim(#)] for Monte Carlo standard errors, where nsim(#) sets the number of simulations for the Lesage and Pace (2009) procedure, or none for no standard errors.

constraints(constraints) apply specified linear constraints.

Options for the Spatial Error (SEM) model

Model

emat(name) specifies the weight matrix for the spatial-error term. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

re use the random effects estimator; the default.

fe use the fixed effects estimator.

type(type_options[, leeyu])} specifies fixed-effects type. May be ind for individual fixed effects, time for time fixed effects or both for time and individual fixed effects.
Suboption leeyu transforms the data according to Lee & Yu (JoE, 2010).

Other

level(#) sets confidence interval level; default is level(95).

noconstant suppresses the constant term in the model. Only for re estimator.

constraints(constraints) apply specified linear constraints.

hausman performs the robust Hausman test, automatically detecting the alternative estimator. The test is computed estimating the variance covariance matrix of the difference between fe and re estimators as in White (1982).

Options for the Generalized Spatial Panel Random Effects (GSPRE) model

Model

wmat(name) specifies the weight matrix for the spatial random-effects. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

emat(name) specifies the weight matrix for the spatial-error term. name can be a Stata matrix or a spmat object. This matrix can be standardized or not.

error(#) defines the random effect error structure. Error specification with # = 1..4 for combinations of the coefficients: rho1 for the random effect spatial error component the spatial panel error component and rho2 for the spatial error component

Other

level(#) sets confidence interval level; default is level(95).

noconstant suppresses the constant term in the model. Only for re estimator.

constraints(constraints) apply specified linear constraints.

Options or options' arguments common to all models

Starting values

from() specifies initial values for the coefficients.
You can specify the initial values in one of three ways: by specifying the name of a
vector containing the initial values (e.g., from(b0), where b0 is a
properly labeled vector); by specifying coefficient names with the values
(e.g., from(age=2.1 /sigma=7.4)); or by specifying a list of values
(e.g., from(2.1 7.4, copy)). Poor values in from() may lead to convergence
problems.

skip specifies that any parameters found in the specified initialization
vector that are not also found in the model be ignored. The default action is
to issue an error message.

copy specifies that the list of values or the initialization
vector be copied into the initial-value vector by position rather than
by name.

Maximization

maximize_options: difficult, technique(algorithm_spec),
iterate(#), [no]log, from(init_specs), tolerance(#),
ltolerance(#), nrtolerance(#),
nonrtolerance; see [R] maximize. These
options are seldom used.

Display

display_options:
vsquish,
baselevels,
allbaselevels;
see [R] estimation options.

Variance estimation

This entry describes the arguments of vce() option. vce() specifies how to estimate the
variance-covariance matrix (VCE) corresponding to the parameter estimates.
The standard errors reported in the table of parameter estimates are the
square root of the variances (diagonal elements) of the VCE.

vcetype description

Likelihood based

oim observed information matrix (OIM). see vcetype

opg outer product of the gradient (OPG) vectors

Sandwich estimators

robust synonym for clustered sandwich estimator where clustvar is panelvar

cluster clustvar clustered sandwich estimator

dkraay # Driscoll-Kraay robust estimator. # is the maximum lag used in the calculation

Remarks

This version of xsmle does not allow the use of multiple weight matrices in wmat() or emat() (or dmat()). This means that the weight matrix is forced to be the same
for each cross-section and xsmle will automatically replicate it for all time periods. Notice that the maximum dimension of a single Stata matrix depends on Stata's flavor: 40 x 40 (Small) 800 x 800 (IC) and 11,000 x 11,000 (SE or MP).
In order to overcome this limitation, bigger matrices have to be specified as spmat objects.

When variance-covariance matrix is not positive definite and vceeffects(sim) has been specified, direct, indirect and total effects standard errors are computed using a modified positive definite matrix as in Rebonato and Jackel (2000).

We would like to thank Giovanni Millo and Gianfranco Piras for creating and sharing the spatial weights matrix used in all xsmle examples.

Examples

SAR model

use http://www.econometrics.it/stata/data/xsmle/product.dta, clear

spmat use usaww using http://www.econometrics.it/stata/data/xsmle/usaww.spmat

gen lngsp = log(gsp)

gen lnpcap = log(pcap)

gen lnpc = log(pc)

gen lnemp = log(emp)

xsmle lngsp lnpcap lnpc lnemp unemp, wmat(usaww)

SDM model with selected spatially lagged regressors and direct+indirect effect

xsmle lngsp lnpcap lnpc lnemp, re model(sdm) wmat(usaww) durbin(lnpcap lnpc)

SAC model

xsmle lngsp lnpcap lnpc lnemp, fe model(sac) wmat(usaww) emat(usaww)

SEM model

xsmle lngsp lnpcap lnpc lnemp, re model(sem) emat(usaww)

GSPRE model

xsmle lngsp lnpcap lnpc lnemp, model(gspre) error(1) wmat(usaww) emat(usaww)

References

Lee L.-f., de Jong, R. and Yu J., 2008.
Quasi-maximum likelihood estimators for spatial dynamic panel data with fixed effects when both n and T are large
Journal of Econometrics, 146, pp. 118-134.

Lee L.-f., Yu J., 2010.
Estimation of spatial autoregressive panel data models with fixed effects.
Journal of Econometrics, 154, pp. 165-185.

Elhorst P., 2010.
Spatial Panel Data Models.
Handbook of applied spatial analysis. Edited by Fisher, M.M., Getis, A..

Cameron A. C., Gelbach J. B. and Miller D. L., 2011.
Robust Inference With Multiway Clustering.
Journal of Business & Economic Statistics, 29(2) pp. 238-249.

Saved results

xsmle saves the following in e():

Scalars

e(N) number of observations

e(t_max) number of periods

e(N_g) number of groups

e(N_clust) number of clusters

e(ll) log likelihood

e(converged) 1 if the model converged, 0 otherwise

e(ic) number of iterations

e(df_m) model degrees of freedom

e(k_exp) number of ancillary parameters

e(df_r) model residual degrees of freedom

e(a_avg) mean of fixed-effects

e(sigma_a) standard deviation of random-effects

e(sigma_e) standard deviation of idiosyncratic errors

e(rank) rank of the variance-covariance matrix

e(k_eq) number of equations

e(r2_w) R-squared within model

e(r2) R-squared overall model

e(r2_b) R-squared between model

e(hau_chi2_df) Hausman test degrees of freedom

e(hau_chi2_p) Hausman test degrees p-value

e(hau_chi2) Hausman test statistic

Macros

e(title) title in estimation output

e(cmd) xsmle

e(transf_type) type of data transformation

e(vce) vcetype specified in vce()

e(dlag) time-lagged dependent variable

e(dlag_type) type of dynamic model

e(ivar) variable denoting groups

e(tvar) variable denoting time

e(type) type of fixed effects

e(effects) fixed or random effects

e(model) estimated spatial model

e(predict) program used to implement predict

e(properties) b V

e(depvar) name of dependent variable

e(rhsvar) names of independent variables

e(drhsvar) names of spatially lagged independent variables

e(nocons) equal to 1 if intercept is not included in the model

e(w_spmat_obj) equal to 1 if wmat() matrix is a spmat object

e(e_spmat_obj) equal to 1 if emat() matrix is a spmat object

e(d_spmat_obj) equal to 1 if dmat() matrix is a spmat object

e(wmatrix) name of the spatial weighting matrix wmat()

e(ematrix) name of the spatial weighting matrix emat()

e(dmatrix) name of the spatial weighting matrix dmat()

e(marginsok) predictions allowed by margins

e(covariates) names of independent variables

e(technique) maximization technique

e(crittype) optimization criterion

e(user) name of likelihood-evaluator program

e(ml_method) type of ml method

e(wtype) weight type

e(wexp) weight expression

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of the estimators

e(gradient) gradient vector

e(score) score matrix

e(hessian) hessian matrix

e(ilog) iteration log vector

Functions

e(sample) marks estimation sample

Authors

Federico Belotti

Centre for Economic and International Studies, University of Rome Tor Vergata

Rome, Italy

federico.belotti@uniroma2.it

Gordon Hughes

University of Edinburgh

Edinburgh, UK

g.a.hughes@ed.ac.uk

Andrea Piano Mortari

Centre for Economic and International Studies, University of Rome Tor Vergata

Rome, Italy

andrea.piano.mortari@uniroma2.it

Also see

Online: xsmle_postestimation, spreg, spivreg,
spmat, shp2dta, mif2dta (if installed)