spatreg过程需要一个空间权矩阵加上一个与此矩阵相关的特征值向量;这两者都可以由Pisani的spatwmat计算(如果您的数据允许的话)。spatreg可以估计空间滞后和空间误差模型。基本的命令是:
spatreg depvar indepvars, weights(w-matrix) eigenval(e-vector) model(lag)
或者
spatreg depvar indepvars, weights(w-matrix) eigenval(e-vector) model(error)
另外还有一个命令为spregsem,spregsem:最大似然估计空间误差截面回归模型
spregsem估计了MLE空间误差截面回归模型。
spregsem可以估计以下模型:1-干扰项的异方差回归模型。2-扰动项下的非正态回归模型。spregsem估计了tobit的连续和截断因变量模型。
spregsem处理连续或截断的因变量数据。如果depvar缺少值或下限,那么在这种情况下spregsem将适合利用tobit模型建立了空间横截面模型,从而解决了多种数据中存在的缺值问题。否则,在本例中对于连续数据,采用正态估计。
spregsem可以生成:-二进制/标准化权重矩阵。逆/逆平方标准化权重矩阵。二进制/标准化/逆特征值变量。
由于是一个外部命令,因此需要先安装下载。
语法格式为:
spregsem depvar indepvars [weight] , wmfile(weight_file) [ lmspac lmhet lmnorm diag tests stand inv inv2 dist(norm|exp|weib) mfx(lin, log) predict(new_var) resid(new_var) iter(#) tech(name) ll(real 0) tobit coll zero tolog nolog level(#) vce(vcetype) maximize other maximization options ]
选项含义为:
depvar表示被解释变量
indepvars 表示解释变量
wmfile(weight_file) 表示导入权重矩阵
inv使用逆标准化权重矩阵(1/W)
inv2 使用反平方标准化权重矩阵(1/W^2)
zero将缺失值的观测值转换为0
coll 保持共线变量;默认移除共线变量
nolog不显示迭代次数
robust表示Huber-White标准误差
level,表示置信区间水平;默认是95%水平
4下述数据,data包含美国俄亥俄州哥伦布市49个社区的社区编号id、犯罪率crime、房价hoval与家庭收入income的数据,WM权重矩阵包含这49个社区基于相邻关系的空间权重矩阵
代码为:
. use data.dta. spregsem crime hoval income, wmfile(WM)==============================================================================*** Binary (0/1) Weight Matrix: 49x49 (Non Normalized)==============================================================================initial: log likelihood = -187.42512rescale: log likelihood = -187.42512rescale eq: log likelihood = -187.42512Iteration 0: log likelihood = -187.42512 Iteration 1: log likelihood = -182.93155 Iteration 2: log likelihood = -182.41948 Iteration 3: log likelihood = -182.4163 Iteration 4: log likelihood = -182.4163 ==============================================================================* MLE Spatial Error Normal Model (SEM)============================================================================== crime = hoval + income------------------------------------------------------------------------------ Sample Size = 49 Wald Test = 15.1345 | P-Value > Chi2(2) = 0.0005 F-Test = 7.5673 | P-Value > F(2 , 47) = 0.0014 (Buse 1973) R2 = 0.2476 | Raw Moments R2 = 0.8632 (Buse 1973) R2 Adj = 0.2316 | Raw Moments R2 Adj = 0.8603 Root MSE (Sigma) = 14.6675 | Log Likelihood Function = -182.4163------------------------------------------------------------------------------- R2h= 0.5514 R2h Adj= 0.5419 F-Test = 28.27 P-Value > F(2 , 47) 0.0000- R2v= 0.4082 R2v Adj= 0.3956 F-Test = 15.86 P-Value > F(2 , 47) 0.0000------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval]-------------+----------------------------------------------------------------crime | hoval | -.2614938 .0916798 -2.85 0.004 -.4411829 -.0818046 income | -1.301729 .3236859 -4.02 0.000 -1.936142 -.667316 _cons | 54.92599 6.053747 9.07 0.000 43.06086 66.79111-------------+---------------------------------------------------------------- /Lambda | .035006 .0111665 3.13 0.002 .01312 .056892 /Sigma | 9.981965 1.008532 9.90 0.000 8.005279 11.95865------------------------------------------------------------------------------ LR Test SEM vs. OLS (Lambda=0): 9.8276 P-Value > Chi2(1) 0.0017 Acceptable Range for Lambda: -0.3229 < Lambda < 0.1693------------------------------------------------------------------------------. est-------------------------------------------------------------------------------------------------------------------------active results-------------------------------------------------------------------------------------------------------------------------SEM1n Number of obs = 49 LR chi2(2) = 9.92Log likelihood = -182.4163 Prob > chi2 = 0.0070------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval]-------------+----------------------------------------------------------------crime | hoval | -.2614938 .0916798 -2.85 0.004 -.4411829 -.0818046 income | -1.301729 .3236859 -4.02 0.000 -1.936142 -.667316 _cons | 54.92599 6.053747 9.07 0.000 43.06086 66.79111-------------+----------------------------------------------------------------Lambda | _cons | .035006 .0111665 3.13 0.002 .01312 .056892-------------+---------------------------------------------------------------- /Sigma | 9.981965 1.008532 9.90 0.000 8.005279 11.95865------------------------------------------------------------------------------. est store spregsem
下面使用spatreg命令进行相关操作,结果为:
代码为:
. spatwmat using WM.dta,name(W) eigenval(E)The following matrices have been created:1. Imported binary weights matrix W Dimension: 49x492. Eigenvalues matrix E Dimension: 49x1. *空间误差模型. spatreg crime hoval income, weights(W) eigenval(E) model(error)initial: log likelihood = -187.42512rescale: log likelihood = -187.42512rescale eq: log likelihood = -187.42512Iteration 0: log likelihood = -187.42512 Iteration 1: log likelihood = -182.82117 Iteration 2: log likelihood = -182.27247 Iteration 3: log likelihood = -182.26824 Iteration 4: log likelihood = -182.26823 Weights matrix Name: W Type: Imported (binary) Row-standardized: NoSpatial error model Number of obs = 49 Variance ratio = 0.402 Squared corr. = 0.551Log likelihood = -182.26823 Sigma = 9.98------------------------------------------------------------------------------ crime | Coef. Std. Err. z P>|z| [95% Conf. Interval]-------------+----------------------------------------------------------------crime | hoval | -.2605768 .0917459 -2.84 0.005 -.4403954 -.0807582 income | -1.289794 .3255491 -3.96 0.000 -1.927858 -.6517291 _cons | 54.45472 6.149929 8.85 0.000 42.40108 66.50836-------------+---------------------------------------------------------------- lambda | .0361054 .0114345 3.16 0.002 .0136943 .0585165------------------------------------------------------------------------------Wald test of lambda=0: chi2(1) = 9.970 (0.002)Likelihood ratio test of lambda=0: chi2(1) = 10.218 (0.001)Lagrange multiplier test of lambda=0: chi2(1) = 6.804 (0.009)Acceptable range for lambda: -1.536 < lambda < 1.000. est store sem. end of do-file
对上述结果进行对比,代码结果为: