I intend to make a Moran scaterplot in Stata. However, I am facing trouble to create the matrix of spatial weights. The code used was:
clear all
import excel "C:\Users\daves\OneDrive\Pessoal\Acadêmico\Mestrad o\Dissertação - Execução\Análises\Desigualdade - Regressão com PIB Municipal\Base de dados.xlsx", sheet("Planilha1") firstrow
//converge to str7
tostring Codigo, replace
//ename to CD_MUN
rename Codigo CD_MUN
//change work directory
cd "C:\Users\daves\OneDrive\Pessoal\Acadêmico\Mestrad o\Dissertação - Execução\Análises\MT_Municipios_2022"
//use shapefile
spshape2dta MT_Municipios_2022, replace
//merge
merge m:m CD_MUN using "C:\Users\daves\OneDrive\Pessoal\Acadêmico\Mestrad o\Dissertação - Execução\Análises\MT_Municipios_2022\MT_Municipios _2022.dta"
//single year
drop if Year < 2010
The data, after merging and dropping observations, is presented bellow:
When I run the code bellow:
//Weight matrix
spmatrix create contiguity W
//Scaterplot Moran
spatlsa Income40poorer, weights(W)
A message of error ocurr:Matrix W does not exist
How can I generate the code to achieve the matrix?
clear all
import excel "C:\Users\daves\OneDrive\Pessoal\Acadêmico\Mestrad o\Dissertação - Execução\Análises\Desigualdade - Regressão com PIB Municipal\Base de dados.xlsx", sheet("Planilha1") firstrow
//converge to str7
tostring Codigo, replace
//ename to CD_MUN
rename Codigo CD_MUN
//change work directory
cd "C:\Users\daves\OneDrive\Pessoal\Acadêmico\Mestrad o\Dissertação - Execução\Análises\MT_Municipios_2022"
//use shapefile
spshape2dta MT_Municipios_2022, replace
//merge
merge m:m CD_MUN using "C:\Users\daves\OneDrive\Pessoal\Acadêmico\Mestrad o\Dissertação - Execução\Análises\MT_Municipios_2022\MT_Municipios _2022.dta"
//single year
drop if Year < 2010
The data, after merging and dropping observations, is presented bellow:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str7 CD_MUN str33 Município double(Lat Long Income40poorer) int _ID double(_CX _CY) "5100102" "Acorizal" -15.199491 -56.3701493 10.94 1 -56.31803576052537 -15.177269347572569 "5100201" "Água Boa" -14.0572665 -52.1615971 13.56 2 -52.50025307405131 -13.977564266606636 "5100250" "Alta Floresta" -9.886111 -56.087222 13.51 3 -56.3677085015132 -10.055804544827458 "5100300" "Alto Araguaia" -17.3139183 -53.2157003 13.45 4 -53.46699680769031 -17.449504075864365 "5100359" "Alto Boa Vista" -11.6739 -51.3878 6.58 5 -51.75022344389769 -11.811502343869748 "5100409" "Alto Garças" -16.947562 -53.5299889 14.05 6 -53.580939157514216 -16.8882416242314 "5100508" "Alto Paraguai" -14.5054055 -56.4840012 12.02 7 -56.66124171186436 -14.75979737533704 "5100607" "Alto Taquari" -17.8340709 -53.2844274 14.43 8 -53.29657364265147 -17.827206230304515 "5100805" "Apiacás" -9.543889 -57.448889 13.55 9 -57.82599821155492 -8.758635833004735 "5101001" "Araguaiana" -15.716667 -51.85 14.65 10 -51.80670519627334 -15.130288195114774 "5101209" "Araguainha" -16.8593724 -53.0343861 16.66 11 -53.12127538252165 -16.750515378368284 "5101258" "Araputanga" -15.4645725 -58.3482517 12.57 12 -58.45910265825619 -15.25301626908964 "5101308" "Arenápolis" -14.4617866 -56.8436658 14.12 13 -56.85934161098203 -14.507091018513233 "5101407" "Aripuanã" -10.172113 -59.454925 9.29 14 -59.85630768985148 -10.179663940790038 "5101605" "Barão de Melgaço" -16.2789 -55.9578 11.65 15 -56.02952144464605 -16.810379188441335 "5101704" "Barra do Bugres" -15.0643133 -57.1789938 11.37 16 -57.559572190838466 -15.067759883087641 "5101803" "Barra do Garças" -15.89 -52.256667 10.47 17 -52.44274439676174 -15.363055206520071 "5101852" "Bom Jesus do Araguaia" -12.1723666 -51.504648 12.89 18 -51.73947800015276 -12.217808976551934 "5101902" "Brasnorte" -12.155 -57.9789 10.71 19 -57.9988367440737 -12.423103820486345 "5102504" "Cáceres" -16.183333 -57.666667 11.18 20 -57.83360803824163 -16.537401689925552 "5102603" "Campinápolis" -14.5158 -52.895 3.49 21 -53.128380900788216 -14.374608041591198 "5102637" "Campo Novo do Parecis" -13.6521806 -57.8986482 14.8 22 -57.93095334755364 -13.68829960669082 "5102678" "Campo Verde" -15.5498535 -55.1729923 12.72 23 -54.958086029644896 -15.344785322092953 "5102686" "Campos de Júlio" -13.7186383 -59.2598693 9.75 24 -59.1930544053875 -13.579846016688718 "5102694" "Canabrava do Norte" -11.0539 -51.8308 10.64 25 -51.82363386870563 -11.201583086620245 "5102702" "Canarana" -13.5415868 -52.2763472 11.1 26 -52.398915405797034 -13.329839414126925 "5102793" "Carlinda" -9.9709503 -55.8274321 11.52 27 -55.83415924215409 -10.10638308543036 "5102850" "Castanheira" -11.132778 -58.602778 10.56 28 -58.602797236353304 -10.940726038839813 "5103007" "Chapada dos Guimarães" -15.460833 -55.75 10.44 29 -55.55214645024638 -15.12100901357706 "5103056" "Cláudia" -11.515 -54.8908 10.66 30 -55.04769829710479 -11.44815466636803 "5103106" "Cocalinho" -14.3969 -50.9958 13.18 31 -51.148446233171384 -13.86982300618364 "5103205" "Colíder" -10.8045299 -55.4560027 11.35 32 -55.46858408111061 -10.630984871126461 "5103254" "Colniza" -9.54389 -57.44889 6.67 33 -60.30419381146491 -9.292440664844445 "5103304" "Comodoro" -13.65 -59.783333 10.28 34 -59.75136486495116 -13.19366522302567 "5103353" "Confresa" -10.6439 -51.5689 8.29 35 -51.69857253382331 -10.404166625127791 "5103361" "Conquista D'Oeste" -14.5578 -59.5719 12.32 36 -59.33223622057129 -14.634682022705455 "5103379" "Cotriguaçu" -9.85778 -58.4139 6.39 37 -58.67515455546982 -9.537854004730054 "5103403" "Cuiabá" -15.5951004 -56.0922649 9.51 38 -55.81823178948488 -15.592792334833925 "5103437" "Curvelândia" -15.6 -57.9219 13.42 39 -57.87644937159904 -15.617112751350701 "5103452" "Denise" -14.74 -57.053889 15.89 40 -56.96161614004239 -14.730076095138605 "5103502" "Diamantino" -14.4083277 -56.4469562 13.21 41 -56.804568699175086 -14.095738292053072 "5103601" "Dom Aquino" -15.8094662 -54.9211653 11.62 42 -54.776527994316034 -15.656315394145844 "5103700" "Feliz Natal" -12.3858 -54.92 13.91 43 -54.18480386007494 -11.932901236688751 "5103809" "Figueirópolis D'Oeste" -15.445 -58.74 15.11 44 -58.70257463350431 -15.527386368577965 "5103858" "Gaúcha do Norte" -13.1781626 -53.2573598 3.69 45 -53.45617697189669 -12.995961583346347 "5103908" "General Carneiro" -15.7116589 -52.7550968 7.85 46 -53.34280146316657 -15.520137717056143 "5103957" "Glória D'Oeste" -15.7678 -58.3558 13.75 47 -58.32529256834483 -15.839196549509095 "5104104" "Guarantã do Norte" -9.9504872 -54.9086065 12.9 48 -54.62110531757516 -9.776268561549207 "5104203" "Guiratinga" -16.3460831 -53.7639538 12.98 49 -53.59007555376754 -16.38474677539504 "5104500" "Indiavaí" -15.4962225 -58.5772805 14 50 -58.597591976519496 -15.335201906134524 "5104526" "Ipiranga do Norte" -12.2382263 -56.1519237 13.72 51 -56.058659209735715 -12.017026205902928 "5104542" "Itanhangá" -22.9935711 -43.3030875 12.45 52 -56.75487811207127 -12.1403921830551 "5104559" "Itaúba" -11.061944 -55.275833 10.72 53 -55.589811272387806 -11.110991787676367 "5104609" "Itiquira" -17.2077149 -54.1484433 13.89 54 -54.59732059468429 -17.333887811898993 "5104807" "Jaciara" -15.9681811 -54.9650947 12.02 55 -55.191949318682695 -15.975734998443773 "5104906" "Jangada" -15.235833 -56.488889 6.93 56 -56.572739937216205 -15.337843480699332 "5105002" "Jauru" -15.3403041 -58.8680861 10.04 57 -58.86566571816707 -15.30479478445535 "5105101" "Juara" -11.255 -57.52 12.95 58 -57.61840292139564 -11.023732242887027 "5105150" "Juína" -11.4181597 -58.7606808 10.16 59 -59.32449524903365 -11.532094690729512 "5105176" "Juruena" -12.847227 -58.926895 14.28 60 -58.624825608458615 -10.397452403025552 "5105200" "Juscimeira" -16.0508 -54.8839 15.03 61 -54.90422490559096 -16.182878614878533 "5105234" "Lambari D'Oeste" -15.3228 -58.0039 14.23 62 -57.77917941232637 -15.377071910877069 "5105259" "Lucas do Rio Verde" -13.0650649 -55.9197032 14.49 63 -56.16745525463448 -13.03726268780817 "5105309" "Luciára" -10.75 -50.5667 15.36 64 -50.945799462612754 -11.014675149775984 "5105507" "Vila Bela da Santíssima Trindade" -15.0064254 -59.9509173 8.36 65 -59.99083159458444 -15.190622406435162 "5105580" "Marcelândia" -11.0779159 -54.5249384 11.16 66 -54.05341565755499 -10.88626411688603 "5105606" "Matupá" -10.1703001 -54.9301852 9.87 67 -54.35687471880219 -10.013975782245053 "5105622" "Mirassol d'Oeste" -15.6738138 -58.1028107 11.26 68 -58.054959408060164 -15.654156205746865 "5105903" "Nobres" -14.733333 -56.333333 13.45 69 -55.81247900880092 -14.376970632428002 "5106000" "Nortelândia" -14.455 -56.8028 13.91 70 -56.72249293552059 -14.347737218305834 "5106109" "Nossa Senhora do Livramento" -15.758333 -56.345556 11.82 71 -56.484039826651085 -15.839004810794503 "5106158" "Nova Bandeirantes" -9.81389 -57.8619 6.65 72 -58.076941272229966 -9.76844110652515 "5106174" "Nova Nazaré" -13.9898149 -51.7999477 7.6 73 -51.88994973042275 -14.156237629110615 "5106182" "Nova Lacerda" -14.4745301 -59.5853047 9.92 74 -59.77145731681706 -14.299833489461097 "5106190" "Nova Santa Helena" -10.82 -53.3508 9.19 75 -54.90666915892022 -10.918919875679421 "5106208" "Nova Brasilândia" -14.9569 -54.9658 6.93 76 -55.050812904581484 -14.784476976479716 "5106216" "Nova Canaã do Norte" -10.5578 -55.9528 10.43 77 -56.04172790476304 -10.700279070473451 "5106224" "Nova Mutum" -13.8224921 -56.0820242 12.94 78 -56.106054264445994 -13.62959906963144 "5106232" "Nova Olímpia" -14.796944 -57.287778 11.01 79 -57.42145129387154 -14.804433282139199 "5106240" "Nova Ubiratã" -12.9908 -55.255 11.83 80 -54.75951988518504 -12.9964263801945 "5106257" "Nova Xavantina" -27.083333 -52.333333 11.67 81 -52.406817653258365 -14.596957840422526 "5106265" "Novo Mundo" -9.95 -55.197778 11.41 82 -55.403680784796954 -9.752155069295247 "5106273" "Novo Horizonte do Norte" -11.4128 -57.3519 10.67 83 -57.30351868839538 -11.383601539861393 "5106281" "Novo São Joaquim" -14.9058 -53.0178 13.67 84 -53.25848056637146 -15.078102405600308 "5106299" "Paranaíta" -9.6669618 -56.4765937 11.45 85 -56.68258880238319 -9.593574365676968 "5106307" "Paranatinga" -14.4270271 -54.0484815 10.95 86 -54.10899016439388 -13.677654086919363 "5106315" "Novo Santo Antônio" -5.2879036 -41.9347567 12.03 87 -50.88794647729436 -12.313386364338797 "5106372" "Pedra Preta" -16.622778 -54.473889 14.83 88 -54.2492077635204 -16.795172590944194 "5106422" "Peixoto de Azevedo" -10.22306 -54.97972 6.71 89 -53.59394723960452 -10.149515070847944 "5106455" "Planalto da Serra" -14.6611435 -54.7742498 13.57 90 -54.67396753584173 -14.58878237013204 "5106505" "Poconé" 16.267 -56.633 11.25 91 -56.944702804473565 -16.782844143165036 "5106653" "Pontal do Araguaia" -15.9339 -52.3169 14.05 92 -52.72139944246705 -15.931955953502433 "5106703" "Ponte Branca" -16.45 -52.666667 13.98 93 -52.93657485182785 -16.6589499810553 "5106752" "Pontes e Lacerda" -15.2347084 -59.3314294 12.79 94 -59.45774229708416 -15.516822641980657 "5106778" "Porto Alegre do Norte" -10.8839261 -51.6438106 10.69 95 -51.71357869457031 -10.826170934798789 "5106802" "Porto dos Gaúchos" -11.512103 -57.358192 13.33 96 -56.74569835674646 -11.734958209352534 "5106828" "Porto Esperidião" -15.85 -58.466667 9.7 97 -58.98236115628332 -15.956674126288624 "5106851" "Porto Estrela" -15.3315179 -57.2071067 9.36 98 -57.21550456449232 -15.521176377296204 "5107008" "Poxoréo" -15.8691790439575 -56.0941622007565 11.86 99 -54.1860187680725 -15.851006113067427 "5107040" "Primavera do Leste" -15.5570739 -54.2991272 13.27 100 -54.21995435480085 -15.096682749044543 end
When I run the code bellow:
//Weight matrix
spmatrix create contiguity W
//Scaterplot Moran
spatlsa Income40poorer, weights(W)
A message of error ocurr:Matrix W does not exist
How can I generate the code to achieve the matrix?