用STATA做空间计量_第1页
用STATA做空间计量_第2页
用STATA做空间计量_第3页
用STATA做空间计量_第4页
用STATA做空间计量_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

How can I calculate Moran s I in Stata Note The commands shown in this page are user written Stata commands that must be downloaded To install the package of spatial analysis tools type findit spatgsa in the command window Moran s I is a measure of spatial autocorrelation how related the values of a variable are based on the locations where they were measured Using a set of user written Stata commands we can calculate Moran s I in Stata We will be using the spatwmat command to generate a matrix of weights based on the locations in our data and the spatgsa command to calculate Moran s I or other spatial autocorrelation measures Let s look at an example Our dataset ozone contains ozone measurements from thirty two locations in the Los Angeles area aggregated over one month The dataset includes the station number station the latitude and longitude of the station lat and lon and the average of the highest eight hour daily averages av8top This data and other spatial datasets can be downloaded from the University of Illinois s Spatial Analysis Lab We can look at a summary of our location variables to see the range of locations under consideration use http www ats ucla edu stat stata faq ozone dta clear summarize lat lon Variable Obs Mean Std Dev Min Max lat 32 34 0146 2228168 33 6275 34 69012 lon 32 117 7078 5683853 118 5347 116 2339 Based on the minimum and maximum values of these variables we can calculate the greatest Euclidean distance we might measure between two points in our dataset display sqrt 34 69012 33 6275 2 116 2339 118 5347 2 2 5343326 Knowing this maximum distance between two points in our data we can generate a matrix based on the distances between points In the spatwmat command we name the weights matrix to be generated indicate which of our variables are the x and y coordinate variables and provide a range of distance values that are of interest in the band option All of the distances are of interest in this example so we create a band with an upper bound greater than our largest possible distance If we did not care about distances greater than 2 we could indicate this in the band option spatwmat name ozoneweights xcoord lon ycoord lat band 0 3 The following matrix has been created 1 Inverse distance weights matrix ozoneweights Dimension 32x32 Distance band 0 d 3 Friction parameter 1 Minimum distance 0 1 1st quartile distance 0 4 Median distance 0 6 3rd quartile distance 1 0 Maximum distance 2 4 Largest minimum distance 0 50 Smallest maximum distance 1 23 As described in the output the command above generated a matrix with 32 rows and 32 columns because our data includes 32 locations Each off diagonal entry i j in the matrix is equal to 1 distance between point i and point j Thus the matrix entries for pairs of points that are close together are higher than for pairs of points that are far apart If you wish to look at the matrix you can display it with the matrix list command With our matrix of weights we can now calculate Moran s I spatgsa av8top weights ozoneweights moran Measures of global spatial autocorrelation Weights matrix Name ozoneweights Type Distance based inverse distance Distance band 0 0 d 3 0 Row standardized No Moran s I Variables I E I sd I z p value av8top 0 248 0 032 0 036 7 679 0 000 1 tail test Based on these results we can reject the null hypothesis that there is zero spatial autocorrelation present in the variable av8top at alpha 05 Variations Binary Matrix If there exists some threshold distance d such that pairs with distances less than d are neighbors and pairs with distances greater than d are not you can create a binary neighbors matrix with the spatwmat command indicating bin and setting band to have an upper bound of d and use this weights matrix for calculating Moran s I We could do this for d 75 spatwmat name ozoneweights xcoord lon ycoord lat band 0 75 bin The following matrix has been created 1 Distance based binary weights matrix ozoneweights Dimension 32x32 Distance band 0 d 75 Friction parameter 1 Minimum distance 0 1 1st quartile distance 0 4 Median distance 0 6 3rd quartile distance 1 0 Maximum distance 2 4 Largest minimum distance 0 50 Smallest maximum distance 1 23 spatgsa av8top weights ozoneweights moran Measures of global spatial autocorrelation Weights matrix Name ozoneweights Type Distance based binary Distance band 0 0 d 0 75 Row standardized No Moran s I Variables I E I sd I z p value av8top 0 188 0 032 0 033 6 762 0 000 1 tail test In this example the binary formulation of distance yields a similar result We can reject the null hypothesis that there is zero spatial autocorrelation present in the variable av8top at alpha 05 Using an existing matrix If you have calculated a weights matrix according to some other metric than those available in spatwmat and wish to use it in calculating Moran s I spatwmat allows you to read in a Stata dataset of the required dimensions and format it as a distance matrix that can be used by spatgsa If altweights dta is a dataset with 32 columns and 32 rows it could be converted to a weighted matrix aweights to be used in spatgsa analyzing av8top spatwmat using C altweights dta name aweights How do I generate a variogram for spatial data in Stata When analyzing geospatial data describing the spatial pattern of a measured variable is of great importance User written Stata commands allow you to explore such patterns This page will use the variog and variog2 command To install this type findit variog in your command window The variog command allows you to calculate and graph a variogram for regularly spaced one dimensional data The variog2 command allows you to calculate and graph a variogram for two dimensional data without constraints on spacing In both cases the variogram illustrates how differences in a measured variable Z vary as the distances between the points at which Z is measured increase Let s look at an example Our dataset contains ozone measurements from thirty two locations in the Los Angeles area aggregated over one month The dataset includes the station number station the latitude and longitude of the station lat and lon and the average of the highest eight hour daily averages av8top This data and other spatial datasets can be downloaded from the GeoDa Center for Geospatial Analysis and Computation use http www ats ucla edu stat stata faq ozone clear clist in 1 5 station av8top lat lon 1 60 7 225806 34 13583 117 9236 2 69 5 899194 34 17611 118 3153 3 72 4 052885 33 82361 118 1875 4 74 7 181452 34 19944 118 5347 5 75 6 076613 34 06694 117 7514 For the sake of an example let s imagine that instead of specific latitude and longitude locations the stations are evenly spaced along a single latitude If we assume the observations are in the order in which the stations appear we can use the variog command In the command we indicate the measured outcome and we will opt for the calculated values to be listed By default a plot of the semi variogram will be generated variog av8top list Lag Semi variance of pairs 1 2 328506 31 2 2 615086 30 3 2 629862 29 4 2 983584 28 5 3 415026 27 6 2 923007 26 7 4 104437 25 8 3 378503 24 9 3 531528 23 10 4 49281 22 11 5 22965 21 12 6 657857 20 13 6 5462 19 14 6 126221 18 15 6 556983 17 16 6 451519 16 Next let s generate a variogram using the latitude and longitude of the stations For this we will use the variog2 command While the lag distance in variog was assumed to be the distance between each evenly spaced observation variog2 requires the user to specify the lag distance Let s look at a summary of our coordinates to get a sense of the distances existing in our data summarize lat lon Variable Obs Mean Std Dev Min Max lat 32 34 0146 2228168 33 6275 34 69012 lon 32 117 7078 5683853 118 5347 116 2339 Based on this we can calculate the maximum possible distance we might see in our data dis sqrt 33 6275 34 69012 2 118 5347 116 2339 2 2 5343326 As a starting point we can choose a lag distance of 1 and we can examine distances up to 12 lags apart We want to choose a lag distance that yields enough pairs in each lag to generate

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论