**创建空间权重矩阵介绍*设置默认路径cdC:\Users\xiubo\Desktop\F182013.v4\F101994\sheng**创建新文件*shp2dta:readsashape(.shp)anddbase(.dbf)filefromdiskandconvertsthemintoStatadatasets.*shp2dta:读取CHN_adm1文件*CHN_adm1:为已有的地图文件*database(chinaprovince):表示创建一个名称为“chinaprovince”的dBase数据集*database(filename):SpecifiesfilenameofnewdBasedataset*coordinates(coord):创建一个名称为“coord”的坐标系数据集*coordinates(filename):Specifiesfilenameofnewcoordinatesdataset*gencentroids(stub):Createscentroidvariables*genid(newvarname):Createsuniqueidvariablefordatabase.dtashp2dtausingCHN_adm1,database(chinaprovince)coordinates(coord)genid(id)gencentroids(c)**绘制2016年中國GDP分布圖*spmap:Visualizationofspatialdata*clnumber(#):numberofclasses*id(idvar):basemappolygonidentifier(识别符,声明变量名,一般以字母或下划线开头,包含数字、字母、下划线)*_2016GDP:变量*coord:之前创建的坐标系数据集spmap_2016GDPusingcoord,id(id)clnumber(5)*更改变量名renamex_clongituderenamey_clatitude**生成距离矩阵*spmat:用于定义与管理空间权重矩阵*Spatial-weightingmatricesarestoredinspatial-weightingmatrixobjects(spmatobjects).*spmatobjectscontainadditionalinformationaboutthedatausedinconstructingspatial-weightingmatrices.*spmatobjectsareusedinfittingspatialmodels;seespreg(ifinstalled)andspivreg(ifinstalled).*idistance:(产生距离矩阵)createanspmatobjectcontaininganinverse-distancematrixW*或contiguity:createanspmatobjectcontainingacontiguitymatrixW*idistance_jingdu:命名名称为“idistance_jingdu”的距離矩陣*longitude:使用经度*latitude:使用纬度*id(id):使用id*dfunction(function[,miles]):(设置计算距离方法)specifythedistancefunction.*functionmaybeoneofeuclidean(default),dhaversine,rhaversine,ortheMinkowskidistanceoforderp,wherepisanintegergreaterthanorequalto1.*normalize(row):(行标准化)specifiesoneofthethreeavailablenormalizationtechniques:row,minmax,andspectral.*Inarow-normalizedmatrix,eachelementinrowiisdividedbythesumofrowi'selements.*Inaminmax-normalizedmatrix,eachelementisdividedbytheminimumofthelargestrowsumandcolumnsumofthematrix.*Inaspectral-normalizedmatrix,eachelementisdividedbythemodulusofthelargesteigenvalueofthematrix.spmatidistanceidistance_jingdulongitudelatitude,id(id)dfunction(euclidean)normalize(row)**保存stata可读文件idistance_jingdu.spmatspmatsaveidistance_jingduusingidistance_jingdu.spmat**将刚刚保存的idistance_jingdu.spmat文件转化为txt文件spmatexportidistance_jingduusingidistance_jingdu.txt**生成相邻矩阵spmatcontiguitycontiguity_jingduusingcoord,id(id)normalize(row)spmatsavecontiguity_jingduusingcontiguity_jingdu.spmatspmatexportcontiguity_jingduusingcontiguity_jingdu.txt**计算Moran’sI*安装spatwmat*spatwmat:用于定义空间权重矩阵*spatwmat:importsorgeneratesthespatialweightsmatricesrequiredbyspatgsa,spatlsa,spatdiag,andspatreg.*Asanoption,spatwmatalsogeneratestheeigenvaluesmatrixrequiredbyspatreg.*name(W):读取空间权重矩阵W*name(W):使用生成的空间权重矩阵W*xcoord:x坐标*ycoord:y坐标*band(08):宽窗介绍*band(numlist)isrequiredifoptionusingfilenameisnotspecified.*Itspecifiesthelowerandupperboundsofthedistancebandwithinwhichlocationpairsmustbeconsideredneighbors(i.e.,spatiallycontiguous)*and,therefore,assignedanonzerospatialweight.*binary:requeststhatabinaryweightsmatrixbegenerated.Tothisaim,allnonzerospatialweightsaresetto1.spatwmat,name(W)xcoord(longitude)ycoord(latitude)band(08)*安装绘制Moran’sI工具:splagvar*splagvar---Generatesspatiallylaggedvariables,constructstheMoranscatterplot,*andcalculatesglobalMoran'sIstatistics.*_2016GDP:使用变量_2016GDP*wname(W):使用空间权重矩阵W*indicatethenameofthespatialweightsmatrixtobeused*wfrom(Stata):indicatesourceofthespatialweightsmatrix*wfrom(Stata|Mata)indicateswhetherthespatialweightsmatrixisaStatamatrixloadedinmemoryoraMatafilelocatedintheworkingdirectory.*IfthespatialweightsmatrixhadbeencreatedusingspwmatrixitshouldexistasaStatamatrixorasaMatafile.*moran(_2016GDP):计算变量_2016GDP的Moran'sI值*plot(_2016GDP):构建变量_2016GDPMoran散点图splagvar_2016GDP,wname(W)wfrom(Stata)moran(_2016GDP)plot(_2016GDP)**使用距离矩阵计算空间计量模型*设置默认路径cdD:\软件学习软件资料\stata\stata指导书籍命令\陈强高级计量经济学及stata应用(第二版)全部数据*使用product.dta数据集(陈强的高级计量经济学及其stata应用P594)*将数据集product.dta存入当前工作路径useproduct.dta,clear*创建新变量,对原有部分变量取对数genlngsp=log(gsp)genlnpcap=log(pcap)genlnpc=log(pc)genlnemp=log(emp)*将空间权重矩阵usaww.spat存入当前工作路径spmatuseusawwusingusaww.spmat*使用聚类稳健的标准误估计随机效应的SDM模型xsmlelngsplnpcaplnpclnempunemp,wmat(usaww)model(sdm)robustnolog*使用选择项durbin(lnemp),不选择不显著的变量,使用聚类稳健的标准误估计随机效应的SDM模型xsmlelngsplnpcaplnpclnempunemp,wmat(usaww)model(sdm)durbin(lnemp)robustnolognoeffects*使用选择项durbin(lnemp),不选择不显著的变量,使用聚类稳健的标准误估计固定效应的SDM模型xsmlelngsplnpcaplnpclnempunemp,wmat(usaww)model(sdm)durbin(lnemp)robustnolognoeffectsfe*存储随机效应和固定效应结果quixsmlelngsplnpcaplnpclnempunemp,wmat(usaww)model(sdm)durbin(lnemp)r2nolognoeffectsreeststorequixsmlelngsplnpcaplnpclnempunemp,wmat(usaww)model(sdm)durbin(lnemp)r2nolognoeffectsfeeststofe*esttab:将保存的结果汇总到一张表格中*b(fmt):specifyformatforpointestimates*beta[(fmt)]:displaybetacoefficientsinsteadofpointest's*se[(fmt)]:displaystandarderrorsinsteadoftstatistics*star(*0.1**0.05***0.01):标记不同显著性水平对应的P值*r2|ar2|pr2[(fmt)]:display(adjusted,pseudo)R-squared*p[(fmt)]:displayp-valuesinsteadoftstatistics*label:makeuseofvariablelabels*title(string):specifyatitleforthetableesttabfere,bser2star(*0.1**0.05***0.01)*hausman检验