Dear all (data extract at the end),
I am trying to test for spatial autocorrelation in panel data using the xtmoran command (from ssc install).
I am facing the following problem, with the following code:
I do not understand what caused this error, please could someone let me know where I've gone wrong?
I suspect it might because of the weighting matrix, which is not associated to a shape file in this case. Is this a problem? I manually inputted latitude and longitude and used Robert Picard's
command.
The inverse distance weighting matrix then looks like this (the first row is removed in the above code, but I wonder why it appears):
The rest of the data (an extract of it):
I am trying to test for spatial autocorrelation in panel data using the xtmoran command (from ssc install).
I am facing the following problem, with the following code:
Code:
spset canton, coord(lat lng) coordsys(latlong, kilometers) spmatrix create idistance W if Datum_n==tm(2022m4) , normalize(row) replace spmatrix summarize W spmatrix export W using myfile.csv, replace import delimited "Downloads\myfile.csv", clear delimiter(space) drop if v2==. drop v1 save W, replace use "$data/SPATIAL_CT", clear xtset canton Datum_n, monthly xtmoran cant_month_sum_newpositions, wname(W.dta) ERROR: variable cant_month_sum_newpositions728 not found
I suspect it might because of the weighting matrix, which is not associated to a shape file in this case. Is this a problem? I manually inputted latitude and longitude and used Robert Picard's
Code:
geo2xy
The inverse distance weighting matrix then looks like this (the first row is removed in the above code, but I wonder why it appears):
Code:
clear input byte v1 float(v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21) 20 . . . . . . . . . . . . . . . . . . . . 1 0 .033741657 .03030484 .12817147 .08562172 .05523836 .03843883 .018478306 .03841457 .0262484 .05917112 .09705798 .034991365 .031389296 .02688484 .04822607 .05271863 .03087607 .07970407 .0843224 2 .02411275 0 .2011876 .01914739 .017467113 .015746543 .013430405 .008860125 .07270077 .05050749 .015362188 .02866992 .01246935 .29798737 .024665046 .07084346 .035942703 .01330989 .03742783 .04016205 3 .022734886 .21120374 0 .01842274 .016914003 .015509573 .01336643 .008999494 .06785418 .06338729 .015050041 .02702102 .012417258 .30877945 .026185364 .05501815 .034226473 .013403355 .034017157 .035489395 4 .11857197 .024786765 .022717685 0 .2293703 .06522042 .04351062 .01895996 .02738773 .020184765 .09689056 .05472162 .04150366 .023418346 .021237774 .03290169 .03557517 .03005152 .04580312 .04718633 5 .08392707 .023958456 .022099564 .24303265 0 .06575013 .04679817 .020611595 .025993675 .01969346 .13354287 .04683619 .04741533 .022771975 .0206344 .031139906 .03263503 .030579703 .04055284 .042027 6 .06158894 .02456783 .023050535 .07860585 .07478947 0 .13934332 .03088488 .02851434 .022141643 .10842347 .05385603 .08946498 .023348544 .026437223 .029477676 .03889909 .06480422 .04236245 .03943949 7 .04633558 .02265443 .021477267 .05669555 .0575513 .1506498 0 .04287126 .025891064 .02096824 .08377001 .04249001 .17009193 .021684255 .025338067 .02631301 .03366471 .0829645 .035332017 .033256985 8 .04925651 .033049196 .031977072 .05463213 .0560525 .073838934 .09480326 0 .036432654 .03206876 .066223174 .04781438 .09896535 .032095328 .03834209 .036130037 .04296947 .09058557 .0432367 .04152688 9 .03882307 .10281408 .09140917 .029919846 .02680054 .02584612 .021706983 .01381285 0 .08374035 .023972394 .05464591 .01964082 .08530086 .05059366 .07704156 .09039225 .022346275 .074078284 .067114964 10 .03603124 .09701788 .1159839 .029950865 .027579116 .0272599 .02387778 .016514182 .11374102 0 .02538452 .04557164 .02185678 .09659707 .069489054 .06026143 .06323402 .025288576 .05350425 .05085678 11 .0660215 .023985475 .022383735 .11686014 .1520121 .1085018 .07753894 .027719423 .02646629 .02063328 0 .04624471 .08363428 .022886014 .02266927 .029711787 .033635903 .04115531 .03909741 .0388426 12 .08968846 .03707246 .033283293 .0546605 .04415387 .04463522 .032572247 .01657534 .04996536 .03067776 .03829938 0 .02801797 .03382407 .034324046 .04924373 .10098927 .03102193 .15553167 .09546342 13 .04729979 .02358641 .02237398 .06064487 .06538815 .10846496 .1907382 .05018571 .02627024 .021523267 .10132277 .04098545 0 .022661775 .024992887 .027498275 .032872498 .06402014 .035200875 .03396977 14 .021432357 .28471205 .28103212 .017284384 .015862474 .014298358 .012282548 .008221077 .05762989 .04804807 .01400499 .024992455 .011446795 0 .02246958 .05748762 .030761763 .012178725 .031790815 .034063958 15 .04563466 .05858533 .05924683 .03896778 .035732307 .04024771 .03567931 .024415277 .08497467 .08592656 .03448651 .06304933 .03138379 .0558591 0 .05210727 .09108242 .04231307 .0646004 .0557077 16 .0511027 .10504644 .07771183 .03768682 .03366365 .02801517 .023130666 .014362464 .080778 .04651843 .02821728 .05646868 .021556044 .08921707 .032529164 0 .06017355 .02182539 .08149308 .11050357 17 .0530232 .05058621 .04588632 .03867748 .033486348 .035089675 .028088745 .016212888 .08995786 .04633149 .03032001 .10991875 .02445886 .0453132 .05396958 .05711438 0 .029507225 .1303475 .08171028 18 .0517574 .03122084 .02994906 .05445355 .05229566 .0974298 .11537146 .05696499 .037064794 .03088151 .06183021 .05627479 .07939053 .0298995 .04178665 .034526333 .04917869 0 .04707629 .04264795 19 .06562516 .04312252 .03733423 .04076564 .0340638 .031283047 .02413315 .013354911 .06035133 .032092378 .028851096 .13858093 .021441 .03833568 .031335585 .063321136 .10670649 .02312287 0 .16617905 20 .07512265 .05006837 .04214497 .04544158 .03819779 .031513546 .024579126 .013878925 .05916343 .03300658 .03101421 .0920364 .02238836 .04444621 .02923855 .09290569 .072377376 .02266604 .1798102 0 end
Code:
clear input float(canton Datum_n cant_month_sum_newpositions) double(lat lng Y X _CX _CY) 1 723 129 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 724 301 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 725 73 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 726 425 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 727 319 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 732 403 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 733 412 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 734 454 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 735 418 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 736 433 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 737 382 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 738 349 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 739 348 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 740 340 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 744 305 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 745 316 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 746 253 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 747 225 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 1 749 268 47.4 8.05 133.72444444444446 -89.62326573311933 47.4 8.05 2 723 8 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 724 10 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 725 0 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 726 30 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 727 30 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 732 42 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 733 33 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 734 20 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 735 27 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 736 28 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 737 19 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 738 21 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 739 18 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 740 10 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 744 22 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 745 22 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 746 28 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 747 15 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884 2 749 27 47.385849 9.27884 134.5982862222222 -89.63813046864622 47.385849 9.27884
Comment