用STATA做空間計量_第1頁
用STATA做空間計量_第2頁
用STATA做空間計量_第3頁
用STATA做空間計量_第4頁
用STATA做空間計量_第5頁
已閱讀5頁,還剩10頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、用STATA故空間計量How can I calculate Morans 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.Morans I is a measure of spatial autocorrelation-how related the

2、 values of a variable are based on the locations where they were measured. Using a set of user-written Stata commands, we can calculate Morans 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 Mor

3、ans I or other spatial autocorrelation measures.Lets 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 ofthe station (lat and l

4、on), and the average of the highest eight hour daily averages (av8top). This data, and other spatial datasets, can be downloaded from the University of Illinoiss Spatial Analysis Lab. We can look at a summary of our location variables to see the range of locations under consideration.use http:/www.a

5、/stat/stata/faq/ozone.dta, clearsummarize lat lonVariable | Obs Mean Std. Dev.Min Max+lat |3234.0146 .2228168 33.6275 34.69012lon |32-117.7078 .5683853 -118.5347 -116.2339Based on the minimum and maximum values of these variables, we can calculate the greatest Euclidean distance we might

6、measure between two points in our dataset.display sqrt(34.69012 - 33.6275)2 + (-116.2339 - -118.5347)2)2.5343326Knowing 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 gene

7、rated, 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 distancesa re of interest in this example, so we create a band with an upper bound greater than our largest possible distance. If w

8、e 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: 32x32Distance band: 0 d = 3Friction parameter: 1Mini

9、mum distance: 0.11st quartile distance: 0.4Median distance: 0.63rd quartile distance: 1.0Maximum distance: 2.4Largest minimum distance: 0.50Smallest maximum distance: 1.23As described in the output, the command above generated a matrix with 32 rows and 32 columns because our data includes 32 locatio

10、ns. Each off-diagonal entry i, j in the matrix is equal to1/(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

11、command. With our matrix of weights, we can now calculate Morans I.spatgsa av8top, weights(ozoneweights) moranMeasures of global spatial autocorrelationWeights matrixName: ozoneweightsType: Distance-based (inverse distance) Distance band: 0.0 d = 3.0 Row-standardized: NoMorans IVariables | I E(I) sd

12、(I) z p-value*+av8top | 0.248 -0.032 0.036 7.679 0.000 *1-tail testBased on these results, we can reject the null hypothesis that there is zero spatial autocorrelation present in the variable av8top at alpha = .05.VariationsBinary Matrix: If there exists some threshold distance d such that pairs wit

13、h 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 anupper bound of d) and use this weights matrix for calculating Morans I. We could do this for d = .75:sp

14、atwmat, name(ozoneweights) xcoord(lon) ycoord(lat) band(0 .75) binThe following matrix has been created:1. Distance-based binary weights matrix ozoneweightsDimension: 32x32Distance band: 0 d = .75Friction parameter: 1Minimum distance: 0.11st quartile distance: 0.4Median distance: 0.63rd quartile dis

15、tance: 1.0Maximum distance: 2.4Largest minimum distance: 0.50Smallest maximum distance: 1.23spatgsa av8top, weights(ozoneweights) moranMeasures of global spatial autocorrelationWeights matrixName: ozoneweightsType: Distance-based (binary) Distance band: 0.0 d = 0.75 Row-standardized: NoMorans IVaria

16、bles | I E(I) sd(I) z p-value*+av8top | 0.188 -0.032 0.0336.762 0.000*1-tail testIn 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 m

17、atrix: If you have calculated a weights matrix according to some other metric than those available in spatwmat and wish to use it in calculating Morans 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 altw

18、eights.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 spatia

19、l 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 commandT.o install this, type findit variog in your command window.The variog command allows you to calculate and graph a variogram for r

20、egularly spaced one-dimensional data.T he 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 variableZ vary as the distances between the points at whicZh i s mea

21、sured increase.Lets look at an example. Our dataset contains ozone measurements from thirty-two locations in the Los Angeles area aggregated over one monthT.h edataset includes the station number (station), the latitude and longitude of the station (lat and lon), and the average of the highest eight

22、 hour daily averages (av8top). This data, and other spatial datasets, can be downloaded from the GeoDa Center for Geospatial Analysis and Computatio.nuse /stat/stata/faq/ozone, clear clist in 1/5stationav8toplatlon1.607.22580634.13583-117.92362.695.89919434.17611-118.31533.724.

23、05288533.82361-118.18754.747.18145234.19944-118.53475.756.07661334.06694-117.7514For the sake of an example, lets imagine that instead of specific latitude and longitude locations, the stations are evenly spaced along a single latitudIfe w. e assume the observations are in the order in which the sta

24、tions 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.B y default, a plot of the semi-variogram will be generated.variog av8top, list| Lag|Semi-variance# of pairs | 12.32850631 | 22.61508630 | 32.62986229

25、| 42.98358428 | 5|3.41502627 | 62.92300726 | 74.10443725 | 83.37850324 | 93.53152823 | 10|4.4928122 | 115.2296521 | 126.65785720 | 136.546219 | 146.12622118 | 15|6.55698317 | 166.45151916 |Next, lets generate a variogram using the latitude and longitude of the stations. For this, we will use the var

26、iog2 command. W hile 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. Lets look at a summary of our coordinates to get a sense of the distances existing in our data.summarize lat lonVariable |ObsM

27、eanStd. Dev.MinMax+lat |3234.0146.222816833.627534.69012lon |32-117.7078.5683853 -118.5347 -116.2339Based 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.5343326As 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 a variance that we

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論