利用STATA创建空间权重矩阵及空间杜宾模型计算命令

合集下载

将空间权重矩阵扩大的stata代码

将空间权重矩阵扩大的stata代码

标题:将空间权重矩阵扩大的stata代码一、介绍空间权重矩阵是空间统计分析的重要工具,用来衡量地理空间单位之间的空间连接关系。

在进行空间计量分析时,常常需要对空间权重矩阵进行扩大,以满足实际研究需求。

本文将介绍如何使用stata代码来扩大空间权重矩阵。

二、准备工作在使用stata代码进行空间权重矩阵扩大之前,首先需要准备好相关的数据和软件环境。

确保已经安装好stata软件,并且具有要分析的空间权重矩阵数据。

三、导入数据在stata中,需要使用"import delimited"命令来导入空间权重矩阵数据。

假设要导入的数据文件名为"spatial_weights.csv",则可以使用以下命令导入数据:```import delimited "spatial_weights.csv", clear```四、扩大空间权重矩阵使用stata代码来扩大空间权重矩阵的方法比较简单,只需要使用"gen"命令来生成新的空间权重矩阵即可。

假设要将原始的空间权重矩阵扩大10倍,可以使用以下命令:```gen new_weight = old_weight * 10```这里的"old_weight"是原始的空间权重矩阵数据,"new_weight"是经过扩大后的新空间权重矩阵数据。

根据实际需求,可以将10修改为其他倍数。

五、保存数据扩大空间权重矩阵后,需要将结果保存到新的数据文件中。

可以使用"export delimited"命令来保存数据,例如:```export delimited "new_spatial_weights.csv", replace```这样就将扩大后的空间权重矩阵数据保存到了新的文件"new_spatial_weights.csv"中。

【计量】空间杜宾模型代码

【计量】空间杜宾模型代码

空间杜宾模型stata代码clear allcd "F:\stata14\ado\mydo\agglo"**调入权重矩阵use Wqiantaoinver.dta, clearkeep s*save "W2.dta" ,replace**矩阵转换为stata应用格式spatwmat using W2, name(W)standardizematrix list W***调入数据use data11.21.dta, clear*对数生成gen lnii=ln(ii)gen lnp=ln(p)gen lna=ln(a)gen lnt=ln(t)gen lnc=ln(c)*设定面板数据格式xtset id year**变量描述性统计local x " ii c p a t" //5个变量tabstat `x', s(mean sd min p25 p50 p75 max) ///format(%6.4f) c(s)*****(2)estimation****SDM estimation(个体固定ind)//Spatial Durbin model (SDM)xsmle lnii lnc lnp lna lnt, wmat(W) model(sdm) fe type(ind) nsim(500) nolog effectsest store M_sptial //不要加入c三次方lna_2,使用第三产业,加入c_lng交乘项estat ic //AIC BIC test//Spatial Durbin model (时间固定time)xsmle lnii lnc lnp lna lnt, wmat(W) model(sdm) fe type(time) nsim(500) nolog effects est store M_timeestat ic//Spatial Durbin model(双固定,both)xsmle lnii lnc lnp lna lnt , wmat(W) model(sdm) fe type(both) nsim(500) nolog effects est store M_bothestat ic**结果汇总列表显示local m "M_sptial M_time M_both"esttab `m', mtitle(`m') nogap s(r2 ll aic bic N ) ///star(* 0.1 ** 0.05 *** 0.01) b(%6.3f)esttab M_sptial M_time M_both using pane0000.rtf //输出结果rtf excel doc****hausman testxsmle lnii lnc lnp lna lnt , wmat(W) model(sdm) fe type(both) nsim(500) nolog estimates store sdm_fexsmle lnii lnc lnp lna lnt , wmat(W) model(sdm) re type(both) nsim(500) nolog estimates store sdm_rehausman sdm_fe sdm_re。

stata构建反距离空间矩阵标准化的命令

stata构建反距离空间矩阵标准化的命令

stata构建反距离空间矩阵标准化的命令Stata构建反距离空间矩阵标准化的命令在空间分析领域中,反距离权重矩阵是一种常用的技术,用于衡量地理上的相互影响。

而在Stata软件中,通过使用特定的命令,我们可以轻松地构建反距离空间矩阵标准化。

本文将介绍Stata中可用的命令并展示其使用方法,以便读者能够充分理解和应用这一功能。

1. 空间权重构建空间权重矩阵是反距离权重矩阵构建的基础。

通过衡量地点之间的空间距离,我们可以构建空间权重矩阵,并用于后续的分析和建模。

在Stata中,常用的命令是‘spwmatrix’,简洁且易于使用。

该命令允许我们通过考虑特定的几何关系和距离度量标准,构建空间权重矩阵。

我们可以使用欧氏距离作为度量标准,设置一个特定的阈值来限制权重的计算。

2. 反距离权重矩阵的构建一旦空间权重矩阵构建完成,我们可以根据此矩阵构建反距离权重矩阵。

反距离权重矩阵主要用于考虑地点之间的相互影响程度。

在Stata 中,我们可以使用‘spdweight’命令来完成这一任务。

该命令可以直接根据空间权重矩阵计算反距离权重矩阵。

我们可以选择不同类型的标准化方法,如列标准化或对称标准化,以便适应特定的需求。

3. 空间矩阵标准化标准化是空间矩阵分析的重要环节,它可以帮助我们更好地理解数据的特征和局部空间依赖性。

在Stata中,我们可以使用‘stdnb’命令对反距离空间矩阵进行标准化。

该命令提供了不同的标准化方法,如罗宾逊标准化、触发点标准化和边界溢出标准化。

这样,我们可以根据特定的需求选择最适合的标准化方法。

通过以上步骤,我们可以在Stata中轻松地构建反距离空间矩阵标准化。

这种空间矩阵的分析方法对于研究空间相关性、聚类和空间回归等问题非常有用。

熟练掌握和应用这些命令,可以帮助我们更好地理解地理现象并进行深入的空间数据分析。

个人观点和理解:反距离空间矩阵标准化是一种非常有用的方法,可以帮助我们更好地理解地理现象背后的空间关系。

stata调用空间矩阵

stata调用空间矩阵

stata调用空间矩阵Stata 中使用空间权重矩阵空间权重矩阵在空间计量经济学分析中至关重要,它用于表示地理实体之间的空间关系。

Stata 提供了多种方法来构建和导入空间权重矩阵。

构建空间权重矩阵使用 spweight 命令:spweight 命令可用于基于空间距离、空间邻接或其他自定义标准生成空间权重矩阵。

语法为:```stataspweight matrixname wtype options```其中,matrixname 指定矩阵名称,wtype 指定权重类型,options 指定生成矩阵的附加选项。

例如,要基于欧氏距离生成空间权重矩阵,可使用以下命令:```stataspweight mymatrix euclidean```从文件导入空间权重矩阵Stata 也支持从文件导入空间权重矩阵。

支持多种文件格式,包括文本文件、dbf 文件和 shapefile。

要从文本文件导入矩阵,可使用以下命令:```stataimport delimited mymatrix.wgt filename.txt```确保该文件包含以逗号分隔的权重值。

空间权重矩阵的类型Stata 中有几种不同类型的空间权重矩阵:二元权重矩阵:表示两个地理实体是否相邻或在指定距离内。

连续权重矩阵:表示两个地理实体之间的距离或其他空间度量。

对称权重矩阵:其中两个地理实体之间的权重相等。

非对称权重矩阵:其中两个地理实体之间的权重不等。

权重标准化在进行空间分析之前,通常需要对空间权重矩阵进行标准化。

标准化涉及将权重除以它们的行和或列总和,以确保矩阵中所有行的总和为 1。

Stata 提供了以下命令进行标准化:rowstandardize:对行进行标准化colstandardize:对列进行标准化空间分析一旦构建或导入空间权重矩阵,就可以将其用于各种空间分析,例如:空间自相关:测量地理实体中数据的空间集中或分散程度。

空间回归:考虑空间相关性的回归分析。

【计量】空间杜宾模型代码

【计量】空间杜宾模型代码

空间杜宾模型stata代码clear allcd "F:\stata14\ado\mydo\agglo"**调入权重矩阵use Wqiantaoinver.dta, clearkeep s*save "W2.dta" ,replace**矩阵转换为stata应用格式spatwmat using W2, name(W)standardizematrix list W***调入数据use data11.21.dta, clear*对数生成gen lnii=ln(ii)gen lnp=ln(p)gen lna=ln(a)gen lnt=ln(t)gen lnc=ln(c)*设定面板数据格式xtset id year**变量描述性统计local x " ii c p a t" //5个变量tabstat `x', s(mean sd min p25 p50 p75 max) ///format(%6.4f) c(s)*****(2)estimation****SDM estimation(个体固定ind)//Spatial Durbin model (SDM)xsmle lnii lnc lnp lna lnt, wmat(W) model(sdm) fe type(ind) nsim(500) nolog effectsest store M_sptial //不要加入c三次方lna_2,使用第三产业,加入c_lng交乘项estat ic //AIC BIC test//Spatial Durbin model (时间固定time)xsmle lnii lnc lnp lna lnt, wmat(W) model(sdm) fe type(time) nsim(500) nolog effects est store M_timeestat ic//Spatial Durbin model(双固定,both)xsmle lnii lnc lnp lna lnt , wmat(W) model(sdm) fe type(both) nsim(500) nolog effects est store M_bothestat ic**结果汇总列表显示local m "M_sptial M_time M_both"esttab `m', mtitle(`m') nogap s(r2 ll aic bic N ) ///star(* 0.1 ** 0.05 *** 0.01) b(%6.3f)esttab M_sptial M_time M_both using pane0000.rtf //输出结果rtf excel doc****hausman testxsmle lnii lnc lnp lna lnt , wmat(W) model(sdm) fe type(both) nsim(500) nolog estimates store sdm_fexsmle lnii lnc lnp lna lnt , wmat(W) model(sdm) re type(both) nsim(500) nolog estimates store sdm_rehausman sdm_fe sdm_re。

利用STATA创建空间权重矩阵及空间杜宾模型计算命令

利用STATA创建空间权重矩阵及空间杜宾模型计算命令

利用STATA创建空间权重矩阵及空间杜宾模型计算命令** 创建空间权重矩阵介绍*设置默认路径cd C:\Users\xiubo\Desktop\F182013.v4\F101994\sheng**创建新文件*shp2dta:reads a shape (.shp) and dbase (.dbf) file from disk and converts them into Stata datasets.*shp2dta:读取CHN_adm1文件*CHN_adm1:为已有的地图文件*database (chinaprovince):表示创建一个名称为“chinaprovince”的dBase数据集*database(filename):Specifies filename of new dBase dataset*coordinates(coord):创建一个名称为“coord”的坐标系数据集*coordinates(filename):Specifies filename of new coordinates dataset*gencentroids(stub):Creates centroid variables*genid(newvarname):Creates unique id variable for database.dtashp2dta using CHN_adm1,database (chinaprovince) coordinates(coord) genid(id) gencentroids(c)**绘制2016年中國GDP分布圖*spmap:Visualization of spatial data*clnumber(#):number of classes*id(idvar):base map polygon identifier(识别符,声明变量名,一般以字母或下划线开头,包含数字、字母、下划线)*_2016GDP:变量*coord:之前创建的坐标系数据集spmap _2016GDP using coord, id(id) clnumber(5)*更改变量名rename x_c longituderename y_c latitude*spmat:用于定义与管理空间权重矩阵*Spatial-weighting matrices are stored in spatial-weighting matrix objects (spmat objects).*spmat objects contain additional information about the data used in constructing spatial-weighting matrices.*spmat objects are used in fitting spatial models; see spreg (if installed) and spivreg (if installed).*idistance:(产生距离矩阵)create an spmat object containing an inverse-distance matrix W*或contiguity:create an spmat object containing a contiguity matrix W*idistance_jingdu:命名名称为“idistance_jingdu”的距離矩陣*longitude:使用经度*latitude:使用纬度*id(id):使用id*dfunction(function[, miles]):(设置计算距离方法)specify the distance function.*function may be one of euclidean (default), dhaversine, rhaversine, or the Minkowski distance of order p, where p is an integer greater than or equal to 1.*normalize(row):(行标准化)specifies one of the three available normalization techniques: row, minmax, and spectral.*In a row-normalized matrix, each element in row i is divided by the sum of row i's elements.*In a minmax-normalized matrix, each element is divided by the minimum of the largest row sum and column sum of thematrix.*In a spectral-normalized matrix, each element is divided by the modulus of the largest eigenvalue of the matrix.spmat idistance idistance_jingdu longitude latitude, id(id) dfunction(euclidean) normalize(row)**保存stata可读文件idistance_jingdu.spmatspmat save idistance_jingdu using idistance_jingdu.spmat**将刚刚保存的idistance_jingdu.spmat文件转化为txt文件spmat export idistance_jingdu using idistance_jingdu.txtspmat contiguity contiguity_jingdu using coord, id(id) normalize(row)spmat save contiguity_jingdu using contiguity_jingdu.spmat spmat export contiguity_jingdu using contiguity_jingdu.txt **计算Moran’s I*安装spatwmat*spatwmat:用于定义空间权重矩阵*spatwmat:imports or generates the spatial weights matrices required by spatgsa, spatlsa, spatdiag, and spatreg.*As an option, spatwmat also generates the eigenvalues matrix required by spatreg.*name(W):读取空间权重矩阵W*name(W):使用生成的空间权重矩阵W*xcoord:x坐标*ycoord:y坐标*band(0 8):宽窗介绍*band(numlist) is required if option using filename is not specified.*It specifies the lower and upper bounds of the distance band within which location pairs must be considered "neighbors"(i.e., spatially contiguous)*and, therefore, assigned a nonzero spatial weight.*binary:requests that a binary weights matrix be generated. To this aim, all nonzero spatial weights are set to 1.spatwmat, name(W) xcoord(longitude) ycoord(latitude) band(0 8)*安装绘制Moran’s I工具:splagvar*splagvar --- Generates spatially lagged variables, constructs the Moran scatter plot,*and calculates global Moran's I statistics.*_2016GDP:使用变量_2016GDP*wname(W):使用空间权重矩阵W*indicate the name of the spatial weights matrix to be used *wfrom(Stata):indicate source of the spatial weights matrix *wfrom(Stata | Mata) indicates whether the spatial weights matrix is a Stata matrix loaded in memory or a Mata file located in the working directory.*If the spatial weights matrix had been created using spwmatrix it should exist as a Stata matrix or as a Mata file.*moran(_2016GDP):计算变量_2016GDP的Moran's I值*plot(_2016GDP):构建变量_2016GDPMoran散点图splagvar _2016GDP, wname(W) wfrom(Stata) moran(_2016GDP) plot(_2016GDP)**使用距离矩阵计算空间计量模型*设置默认路径cd D:\软件学习软件资料\stata\stata指导书籍命令\陈强高级计量经济学及stata应用(第二版)全部数据*使用product.dta数据集(陈强的高级计量经济学及其stata应用P594)*将数据集product.dta存入当前工作路径use product.dta , clear*创建新变量,对原有部分变量取对数gen lngsp=log(gsp)gen lnpcap=log(pcap)gen lnpc=log(pc)gen lnemp=log(emp)*将空间权重矩阵usaww.spat存入当前工作路径spmat use usaww using usaww.spmat*使用聚类稳健的标准误估计随机效应的SDM模型xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm)robust nolog*使用选择项durbin(lnemp),不选择不显著的变量,使用聚类稳健的标准误估计随机效应的SDM模型xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) robust nolog noeffects*使用选择项durbin(lnemp),不选择不显著的变量,使用聚类稳健的标准误估计固定效应的SDM模型xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) robust nolog noeffects fe *存储随机效应和固定效应结果qui xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) r2 nolog noeffects reest sto requi xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) r2 nolog noeffects feest sto fe*esttab:将保存的结果汇总到一张表格中*b(fmt):specify format for point estimates*beta[(fmt)]:display beta coefficients instead of point est's*se[(fmt)]:display standard errors instead of t statistics*star( * 0.1 ** 0.05 *** 0.01):标记不同显著性水平对应的P值*r2|ar2|pr2[(fmt)]:display (adjusted, pseudo) R-squared*p[(fmt)]:display p-values instead of t statistics*label:make use of variable labels*title(string):specify a title for the tableesttab fe re , b se r2 star( * 0.1 ** 0.05 *** 0.01)*hausman检验*进行hausman检验前,回归中没有使用稳健标准误(没用“r”), *是因为传统的豪斯曼检验建立在同方差的前提下*constant:include estimated intercepts in comparison; default is to exclude*df(#):use # degrees of freedom*sigmamore:base both (co)variance matrices on disturbance variance estimate from efficient estimator*sigmaless:base both (co)variance matrices on disturbance variance estimate from consistent estimatorhausman fe re**有时我们还会得到负的chi2值,即chi2<0,表明模型不能满足Hausman检验的渐近假设。

空间相邻权重矩阵stata命令

空间相邻权重矩阵stata命令

空间相邻权重矩阵stata命令
在Stata中,要创建空间相邻权重矩阵,你可以使用`spmat`命令。

空间相邻权重矩阵通常用于空间数据分析,它表示了地理空间上的邻近关系。

以下是一个简单的示例来说明如何使用`spmat`命令创建空间相邻权重矩阵:
首先,假设你有一个地理空间数据集,其中包含了每个地区的经纬度信息。

你可以使用这些信息来构建空间相邻权重矩阵。

stata.
导入数据。

import delimited "yourfile.csv", clear.
创建经纬度变量。

gen lonlat = "("+string(longitude) + " " +
string(latitude)+")"
生成空间相邻权重矩阵。

spmat create W, from(lonlat) id(your_id_variable) replace.
在这个例子中,你需要将"yourfile.csv"替换为你的数据文件名,"longitude"和"latitude"替换为你数据集中的经度和纬度变量名,"your_id_variable"替换为你的地区标识变量名。

这段代码将创建一个空间相邻权重矩阵并将其命名为"W"。

当然,这只是一个简单的示例。

在实际应用中,你可能需要根据你的数据集和分析目的进行调整和扩展。

希望这个回答能够帮助到你。

空间计量模型stata代码

空间计量模型stata代码

空间计量模型stata代码本文将介绍如何使用Stata软件进行空间计量模型分析,并提供相应的代码示例。

空间计量模型是一种考虑空间依赖关系的统计模型,常用于研究城市、区域发展、环境污染等问题。

以下是具体的步骤和代码:1. 加载数据首先使用命令“use”加载数据文件。

假设我们的数据文件名为“data.dta”,则代码如下:use 'data.dta', clear2. 空间权重矩阵的构建空间权重矩阵是空间计量模型的重要组成部分,用于描述地理空间上的邻近关系。

常见的权重矩阵类型包括邻接矩阵、距离矩阵、K近邻法等。

这里以邻接矩阵为例,假设我们的邻接矩阵文件名为“w.gal”,则代码如下:spmat wspset w, clearspset w using 'w.gal', idvar(id) coordvar(x y) 其中,“spmat”命令用于创建一个新的空间权重矩阵对象,“spset”命令用于设置权重矩阵对象的属性。

3. 空间计量模型的估计以空间自回归模型为例,假设我们的因变量为“y”,自变量为“x1”、“x2”,则模型的代码如下:spreg y x1 x2, wmatrix(w) robust其中,“spreg”命令用于进行空间自回归模型的估计,“wmatrix”选项用于指定权重矩阵对象,“robust”选项用于进行异方差性处理。

4. 结果输出和解释最后,使用“estimates”命令输出模型的估计结果,并进行解释。

例如,下面的代码将输出估计结果的标准误、t值和p值:estimates store model1estimates table model1, b(se) t(p) star(0.1 0.05 0.01) 其中,“estimates store”命令用于将估计结果存储到模型对象中,“estimates table”命令用于输出估计结果的表格形式。

解释结果时,需要注意权重矩阵的特征值和特征向量,以及空间自相关性的类型和程度。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

** 创建空间权重矩阵介绍*设置默认路径cd C:\Users\xiubo\Desktop\F182013.v4\F101994\sheng**创建新文件*shp2dta:reads a shape (.shp) and dbase (.dbf) file from disk and converts them into Stata datasets.*shp2dta:读取CHN_adm1文件*CHN_adm1:为已有的地图文件*database (chinaprovince):表示创建一个名称为“chinaprovince”的dBase数据集*database(filename):Specifies filename of new dBase dataset*coordinates(coord):创建一个名称为“coord”的坐标系数据集*coordinates(filename):Specifies filename of new coordinates dataset*gencentroids(stub):Creates centroid variables*genid(newvarname):Creates unique id variable for database.dtashp2dta using CHN_adm1,database (chinaprovince) coordinates(coord) genid(id) gencentroids(c)**绘制2016年中國GDP分布圖*spmap:Visualization of spatial data*clnumber(#):number of classes*id(idvar):base map polygon identifier(识别符,声明变量名,一般以字母或下划线开头,包含数字、字母、下划线)*_2016GDP:变量*coord:之前创建的坐标系数据集spmap _2016GDP using coord, id(id) clnumber(5)*更改变量名rename x_c longituderename y_c latitude**生成距离矩阵*spmat:用于定义与管理空间权重矩阵*Spatial-weighting matrices are stored in spatial-weighting matrix objects (spmat objects).*spmat objects contain additional information about the data used in constructing spatial-weighting matrices.*spmat objects are used in fitting spatial models; see spreg (if installed) and spivreg (if installed).*idistance:(产生距离矩阵)create an spmat object containing an inverse-distance matrix W*或contiguity:create an spmat object containing a contiguity matrix W*idistance_jingdu:命名名称为“idistance_jingdu”的距離矩陣*longitude:使用经度*latitude:使用纬度*id(id):使用id*dfunction(function[, miles]):(设置计算距离方法)specify the distance function.*function may be one of euclidean (default), dhaversine, rhaversine, or the Minkowski distance of order p, where p is an integer greater than or equal to 1.*normalize(row):(行标准化)specifies one of the three available normalization techniques: row, minmax, and spectral.*In a row-normalized matrix, each element in row i is divided by the sum of row i's elements.*In a minmax-normalized matrix, each element is divided by the minimum of the largest row sum and column sum of the matrix.*In a spectral-normalized matrix, each element is divided by the modulus of the largest eigenvalue of the matrix.spmat idistance idistance_jingdu longitude latitude, id(id) dfunction(euclidean) normalize(row)**保存stata可读文件idistance_jingdu.spmatspmat save idistance_jingdu using idistance_jingdu.spmat**将刚刚保存的idistance_jingdu.spmat文件转化为txt文件spmat export idistance_jingdu using idistance_jingdu.txt**生成相邻矩阵spmat contiguity contiguity_jingdu using coord, id(id) normalize(row)spmat save contiguity_jingdu using contiguity_jingdu.spmatspmat export contiguity_jingdu using contiguity_jingdu.txt**计算Moran’s I*安装spatwmat*spatwmat:用于定义空间权重矩阵*spatwmat:imports or generates the spatial weights matrices required by spatgsa, spatlsa, spatdiag, and spatreg.*As an option, spatwmat also generates the eigenvalues matrix required by spatreg.*name(W):读取空间权重矩阵W*name(W):使用生成的空间权重矩阵W*xcoord:x坐标*ycoord:y坐标*band(0 8):宽窗介绍*band(numlist) is required if option using filename is not specified.*It specifies the lower and upper bounds of the distance band within which location pairs must be considered "neighbors" (i.e., spatially contiguous)*and, therefore, assigned a nonzero spatial weight.*binary:requests that a binary weights matrix be generated. To this aim, all nonzero spatial weights are set to 1.spatwmat, name(W) xcoord(longitude) ycoord(latitude) band(0 8)*安装绘制Moran’s I工具:splagvar*splagvar --- Generates spatially lagged variables, constructs the Moran scatter plot,*and calculates global Moran's I statistics.*_2016GDP:使用变量_2016GDP*wname(W):使用空间权重矩阵W*indicate the name of the spatial weights matrix to be used*wfrom(Stata):indicate source of the spatial weights matrix*wfrom(Stata | Mata) indicates whether the spatial weights matrix is a Stata matrix loaded in memory or a Mata file located in the working directory.*If the spatial weights matrix had been created using spwmatrix it should exist as a Stata matrix or as a Mata file.*moran(_2016GDP):计算变量_2016GDP的Moran's I值*plot(_2016GDP):构建变量_2016GDPMoran散点图splagvar _2016GDP, wname(W) wfrom(Stata) moran(_2016GDP) plot(_2016GDP)**使用距离矩阵计算空间计量模型*设置默认路径cd D:\软件学习软件资料\stata\stata指导书籍命令\陈强高级计量经济学及stata应用(第二版)全部数据*使用product.dta数据集(陈强的高级计量经济学及其stata应用P594)*将数据集product.dta存入当前工作路径use product.dta , clear*创建新变量,对原有部分变量取对数gen lngsp=log(gsp)gen lnpcap=log(pcap)gen lnpc=log(pc)gen lnemp=log(emp)*将空间权重矩阵usaww.spat存入当前工作路径spmat use usaww using usaww.spmat*使用聚类稳健的标准误估计随机效应的SDM模型xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm)robust nolog*使用选择项durbin(lnemp),不选择不显著的变量,使用聚类稳健的标准误估计随机效应的SDM模型xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) robust nolog noeffects*使用选择项durbin(lnemp),不选择不显著的变量,使用聚类稳健的标准误估计固定效应的SDM模型xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) robust nolog noeffects fe*存储随机效应和固定效应结果qui xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) r2 nolog noeffects reest sto requi xsmle lngsp lnpcap lnpc lnemp unemp,wmat(usaww) model(sdm) durbin(lnemp) r2 nolog noeffects feest sto fe*esttab:将保存的结果汇总到一张表格中*b(fmt):specify format for point estimates*beta[(fmt)]:display beta coefficients instead of point est's*se[(fmt)]:display standard errors instead of t statistics*star( * 0.1 ** 0.05 *** 0.01):标记不同显著性水平对应的P值*r2|ar2|pr2[(fmt)]:display (adjusted, pseudo) R-squared*p[(fmt)]:display p-values instead of t statistics*label:make use of variable labels*title(string):specify a title for the tableesttab fe re , b se r2 star( * 0.1 ** 0.05 *** 0.01)*hausman检验*进行hausman检验前,回归中没有使用稳健标准误(没用“r”),*是因为传统的豪斯曼检验建立在同方差的前提下*constant:include estimated intercepts in comparison; default is to exclude*df(#):use # degrees of freedom*sigmamore:base both (co)variance matrices on disturbance variance estimate from efficient estimator*sigmaless:base both (co)variance matrices on disturbance variance estimate from consistent estimatorhausman fe re**有时我们还会得到负的chi2值,即chi2<0,表明模型不能满足Hausman检验的渐近假设。

相关文档
最新文档