用STATA做空间计量.docx

上传人:b****3 文档编号:11539327 上传时间:2023-06-01 格式:DOCX 页数:10 大小:40.17KB
下载 相关 举报
用STATA做空间计量.docx_第1页
第1页 / 共10页
用STATA做空间计量.docx_第2页
第2页 / 共10页
用STATA做空间计量.docx_第3页
第3页 / 共10页
用STATA做空间计量.docx_第4页
第4页 / 共10页
用STATA做空间计量.docx_第5页
第5页 / 共10页
用STATA做空间计量.docx_第6页
第6页 / 共10页
用STATA做空间计量.docx_第7页
第7页 / 共10页
用STATA做空间计量.docx_第8页
第8页 / 共10页
用STATA做空间计量.docx_第9页
第9页 / 共10页
用STATA做空间计量.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

用STATA做空间计量.docx

《用STATA做空间计量.docx》由会员分享,可在线阅读,更多相关《用STATA做空间计量.docx(10页珍藏版)》请在冰点文库上搜索。

用STATA做空间计量.docx

用STATA做空间计量

用STATA做空间计量

HowcanIcalculateMoran'sIinStata?

Note:

Thecommandsshowninthispageareuser-writtenStatacommandsthatmustbedownloaded.Toinstallthepackageofspatialanalysistools,typefinditspatgsainthecommandwindow.

Moran'sIisameasureofspatialautocorrelation--howrelatedthevaluesofavariablearebasedonthelocationswheretheyweremeasured.Usingasetofuser-writtenStatacommands,wecancalculateMoran'sIinStata.WewillbeusingthespatwmatcommandtogenerateamatrixofweightsbasedonthelocationsinourdataandthespatgsacommandtocalculateMoran'sIorotherspatialautocorrelationmeasures.

Let'slookatanexample.Ourdataset,ozone,containsozonemeasurementsfromthirty-twolocationsintheLosAngelesareaaggregatedoveronemonth.Thedatasetincludesthestationnumber(station),thelatitudeandlongitudeofthestation(latandlon),andtheaverageofthehighesteighthourdailyaverages(av8top).Thisdata,andotherspatialdatasets,canbedownloadedfromtheUniversityofIllinois'sSpatialAnalysisLab.Wecanlookatasummaryofourlocationvariablestoseetherangeoflocationsunderconsideration.

usehttp:

//www.ats.ucla.edu/stat/stata/faq/ozone.dta,clear

summarizelatlon

Variable|ObsMeanStd.Dev.MinMax

-------------+--------------------------------------------------------

lat|3234.0146.222816833.627534.69012

lon|32-117.7078.5683853-118.5347-116.2339

Basedontheminimumandmaximumvaluesofthesevariables,wecancalculatethegreatestEuclideandistancewemightmeasurebetweentwopointsinourdataset.

displaysqrt((34.69012-33.6275)^2+(-116.2339--118.5347)^2)

2.5343326

Knowingthismaximumdistancebetweentwopointsinourdata,wecangenerateamatrixbasedonthedistancesbetweenpoints.Inthespatwmatcommand,wenametheweightsmatrixtobegenerated,indicatewhichofourvariablesarethex-andy-coordinatevariables,andprovidearangeofdistancevaluesthatareofinterestinthebandoption.Allofthedistancesareofinterestinthisexample,sowecreateabandwithanupperboundgreaterthanourlargestpossibledistance.Ifwedidnotcareaboutdistancesgreaterthan2,wecouldindicatethisinthebandoption.

spatwmat,name(ozoneweights)xcoord(lon)ycoord(lat)band(03)

Thefollowingmatrixhasbeencreated:

1.Inversedistanceweightsmatrixozoneweights

Dimension:

32x32

Distanceband:

0

Frictionparameter:

1

Minimumdistance:

0.1

1stquartiledistance:

0.4

Mediandistance:

0.6

3rdquartiledistance:

1.0

Maximumdistance:

2.4

Largestminimumdistance:

0.50

Smallestmaximumdistance:

1.23

Asdescribedintheoutput,thecommandabovegeneratedamatrixwith32rowsand32columnsbecauseourdataincludes32locations.Eachoff-diagonalentry[i,j]inthematrixisequalto1/(distancebetweenpointiandpointj).Thus,thematrixentriesforpairsofpointsthatareclosetogetherarehigherthanforpairsofpointsthatarefarapart.Ifyouwishtolookatthematrix,youcandisplayitwiththematrixlistcommand.Withourmatrixofweights,wecannowcalculateMoran'sI.

spatgsaav8top,weights(ozoneweights)moran

Measuresofglobalspatialautocorrelation

 

Weightsmatrix

--------------------------------------------------------------

Name:

ozoneweights

Type:

Distance-based(inversedistance)

Distanceband:

0.0

Row-standardized:

No

--------------------------------------------------------------

Moran'sI

--------------------------------------------------------------

Variables|IE(I)sd(I)zp-value*

--------------------+-----------------------------------------

av8top|0.248-0.0320.0367.6790.000

--------------------------------------------------------------

*1-tailtest

Basedontheseresults,wecanrejectthenullhypothesisthatthereiszerospatialautocorrelationpresentinthevariableav8topatalpha=.05.

Variations

BinaryMatrix:

Ifthereexistssomethresholddistancedsuchthatpairswithdistanceslessthandareneighborsandpairswithdistancesgreaterthandarenot,youcancreateabinaryneighborsmatrixwiththespatwmatcommand(indicatingbinandsettingbandtohaveanupperboundofd)andusethisweightsmatrixforcalculatingMoran'sI.Wecoulddothisford=.75:

spatwmat,name(ozoneweights)xcoord(lon)ycoord(lat)band(0.75)bin

Thefollowingmatrixhasbeencreated:

1.Distance-basedbinaryweightsmatrixozoneweights

Dimension:

32x32

Distanceband:

0

Frictionparameter:

1

Minimumdistance:

0.1

1stquartiledistance:

0.4

Mediandistance:

0.6

3rdquartiledistance:

1.0

Maximumdistance:

2.4

Largestminimumdistance:

0.50

Smallestmaximumdistance:

1.23

spatgsaav8top,weights(ozoneweights)moran

 

Measuresofglobalspatialautocorrelation

 

Weightsmatrix

--------------------------------------------------------------

Name:

ozoneweights

Type:

Distance-based(binary)

Distanceband:

0.0

Row-standardized:

No

--------------------------------------------------------------

Moran'sI

--------------------------------------------------------------

Variables|IE(I)sd(I)zp-value*

--------------------+-----------------------------------------

av8top|0.188-0.0320.0336.7620.000

--------------------------------------------------------------

*1-tailtest

Inthisexample,thebinaryformulationofdistanceyieldsasimilarresult.Wecanrejectthenullhypothesisthatthereiszerospatialautocorrelationpresentinthevariableav8topatalpha=.05.

Usinganexistingmatrix:

IfyouhavecalculatedaweightsmatrixaccordingtosomeothermetricthanthoseavailableinspatwmatandwishtouseitincalculatingMoran'sI,spatwmatallowsyoutoreadinaStatadatasetoftherequireddimensionsandformatitasadistancematrixthatcanbeusedbyspatgsa.Ifaltweights.dtaisadatasetwith32columnsand32rows,itcouldbeconvertedtoaweightedmatrixaweightstobeusedinspatgsaanalyzingav8top:

spatwmatusing"C:

\altweights.dta",name(aweights)

 

HowdoIgenerateavariogramforspatialdatainStata?

Whenanalyzinggeospatialdata,describingthespatialpatternofameasuredvariableisofgreatimportance. UserwrittenStatacommandsallowyoutoexploresuchpatterns.Thispagewillusethevariogandvariog2command. Toinstallthis,typefinditvarioginyourcommandwindow.  

Thevariogcommandallowsyoutocalculateandgraphavariogramforregularlyspacedone-dimensionaldata. Thevariog2commandallowsyoutocalculateandgraphavariogramfortwo-dimensionaldatawithoutconstraintsonspacing. Inbothcases,thevariogramillustrateshowdifferencesinameasuredvariableZvaryasthedistancesbetweenthepointsatwhichZismeasuredincrease.

Let'slookatanexample. Ourdatasetcontainsozonemeasurementsfromthirty-twolocationsintheLosAngelesareaaggregatedoveronemonth. Thedatasetincludesthestationnumber(station),thelatitudeandlongitudeofthestation(latandlon),andtheaverageofthehighesteighthourdailyaverages(av8top).Thisdata,andotherspatialdatasets,canbedownloadedfromtheGeoDaCenterforGeospatialAnalysisandComputation.

usehttp:

//www.ats.ucla.edu/stat/stata/faq/ozone,clear

clistin1/5

stationav8toplatlon

1.607.22580634.13583-117.9236

2.695.89919434.17611-118.3153

3.724.05288533.82361-118.1875

4.747.18145234.19944-118.5347

5.756.07661334.06694-117.7514

Forthesakeofanexample,let'simaginethatinsteadofspecificlatitudeandlongitudelocations,thestationsareevenlyspacedalongasinglelatitude. Ifweassumetheobservationsareintheorderinwhichthestationsappear,wecanusethevariogcommand. Inthecommand,weindicatethemeasuredoutcomeandwewilloptforthecalculatedvaluestobelisted. Bydefault,aplotofthesemi-variogramwillbegenerated. 

variogav8top,list

+----------------------------------+

|LagSemi-variance#ofpairs|

|----------------------------------|

|12.32850631|

|22.61508630|

|32.62986229|

|42.98358428|

|53.41502627|

|----------------------------------|

|62.92300726|

|74.10443725|

|83.37850324|

|93.53152823|

|104.4928122|

|----------------------------------|

|115.2296521|

|126.65785720|

|136.546219|

|146.12622118|

|156.55698317|

|----------------------------------|

|166.45151916|

+----------------------------------+

Next,let'sgenerateavariogramusingthelatitudeandlongitudeofthestations. Forthis,wewillusethevariog2command. Whilethelagdistanceinvariogwasassumedtobethedistancebetweeneachevenlyspacedobservation,variog2requirestheusertospecifythelagdistance.Let'slookatasummaryofourcoordinatestogetasenseofthedistancesexistinginourdata. 

summarizelatlon

Variable|ObsMeanStd.Dev.MinMax

-------------+--------------------------------------------------------

lat|3234.0146.222816833.627534.69012

lon|32-117.7078.5683853-118.5347-116.2339

Basedonthis,wecancalculatethemaximumpossibledistancewemightseeinourdata.

dissqrt((33.6275-34.69012)^2+(-118.5347--116.2339)^2)

2.5343326

Asastartingpoint,wecanchoosealagdistanceof.1andwecanexaminedistancesupto12lagsapart.Wewanttochoosealagdistancethatyieldsenoughpairsineachlagtogenerateavariancethatwetrust.Wemightaimtohaveatleast15pairsineachlag.

variog2av8toplatlon,width(.1)lags(12)list

 

+----------------------------------+

|LagSemi-variance#ofpairs|

|----------------------------------|

|14.7294426|

|21.8984

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2