I want to calculate distance between lat long of between household ids. The code I used is as follows
clear
use "C:\Users\SOM\OneDrive - Indian Institute of Technology Bombay\Desktop\PhD_thesis_data_kanzara\gps\househo ld_gps_location_google_map.dta"
rename (hhid head_name latitude longitude)( hhid1 head_name1 latitude1 longitude1)
cross using "C:\Users\SOM\OneDrive - Indian Institute of Technology Bombay\Desktop\PhD_thesis_data_kanzara\gps\househo ld_gps_location_google_map.dta"
drop if hhid1== hhid
geodist latitude1 longitude1 latitude longitude,gen(distance_vincenty)
geodist latitude1 longitude1 latitude longitude,gen(distance_haversine) sphere
in this case let for ids 1 and 2 we get two pairs (1,2) and (2,1) the distance between these two pairs will be same. i want to keep only one pair say (1,2). can you suggest what should I do.
Data after merging
copy up to and including the previous line ------------------
clear
use "C:\Users\SOM\OneDrive - Indian Institute of Technology Bombay\Desktop\PhD_thesis_data_kanzara\gps\househo ld_gps_location_google_map.dta"
rename (hhid head_name latitude longitude)( hhid1 head_name1 latitude1 longitude1)
cross using "C:\Users\SOM\OneDrive - Indian Institute of Technology Bombay\Desktop\PhD_thesis_data_kanzara\gps\househo ld_gps_location_google_map.dta"
drop if hhid1== hhid
geodist latitude1 longitude1 latitude longitude,gen(distance_vincenty)
geodist latitude1 longitude1 latitude longitude,gen(distance_haversine) sphere
in this case let for ids 1 and 2 we get two pairs (1,2) and (2,1) the distance between these two pairs will be same. i want to keep only one pair say (1,2). can you suggest what should I do.
Data after merging
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int hhid1 double(latitude1 longitude1) int hhid double(latitude longitude distance_vincenty distance_haversine) 1 77.3578571 20.6651418 3 77.3575606 20.6648568 .033826256685093856 .03369096703494456 3 77.3575606 20.6648568 1 77.3578571 20.6651418 .03382625668529262 .03369096703494456 1 77.3578571 20.6651418 4 77.3575485 20.6650475 .034529089640824545 .03439141012761076 4 77.3575485 20.6650475 1 77.3578571 20.6651418 .034529089640778395 .03439141012761076 3 77.3575606 20.6648568 4 77.3575485 20.6650475 .004852904673477477 .0048321225041347855 4 77.3575485 20.6650475 3 77.3575606 20.6648568 .0048529046734201685 .0048321225041347855 1 77.3578571 20.6651418 5 77.3575002 20.6650337 .039931793061539066 .039772572156142605 5 77.3575002 20.6650337 1 77.3578571 20.6651418 .03993179306139327 .039772572156142605 3 77.3575606 20.6648568 5 77.3575002 20.6650337 .008010249239978716 .007977571065833007 5 77.3575002 20.6650337 3 77.3575606 20.6648568 .00801024924006957 .007977571065833007 1 77.3578571 20.6651418 6 77.3574477 20.6649944 .04584715395176294 .04566432021418458 6 77.3574477 20.6649944 1 77.3578571 20.6651418 .04584715395185029 .04566432021418458 4 77.3575485 20.6650475 5 77.3575002 20.6650337 .005402747174080315 .005381205579727998 5 77.3575002 20.6650337 4 77.3575485 20.6650475 .005402747174105186 .005381205579727998 3 77.3575606 20.6648568 6 77.3574477 20.6649944 .01304514893077448 .012992873586428146 6 77.3574477 20.6649944 3 77.3575606 20.6648568 .013045148930648719 .012992873586428146 1 77.3578571 20.6651418 7 77.3573469 20.6649224 .057210565876799964 .056982368228243506 7 77.3573469 20.6649224 1 77.3578571 20.6651418 .057210565876624056 .056982368228243506 4 77.3575485 20.6650475 6 77.3574477 20.6649944 .011327900321212028 .011282700641271669 6 77.3574477 20.6649944 4 77.3575485 20.6650475 .011327900321051779 .011282700641271669 3 77.3575606 20.6648568 7 77.3573469 20.6649224 .023911269645074153 .023815927210059512 7 77.3573469 20.6649224 3 77.3575606 20.6648568 .023911269645198203 .023815927210059512 5 77.3575002 20.6650337 6 77.3574477 20.6649944 .005939288934780543 .005915565599479631 6 77.3574477 20.6649944 5 77.3575002 20.6650337 .005939288934919838 .005915565599479631 1 77.3578571 20.6651418 8 77.3574113 20.6649839 .049918488500280356 .049719421935199154 4 77.3575485 20.6650475 7 77.3573469 20.6649224 .0227133669725922 .022622701529399786 7 77.3573469 20.6649224 4 77.3575485 20.6650475 .02271336697268739 .022622701529399786 8 77.3574113 20.6649839 1 77.3578571 20.6651418 .049918488500233706 .049719421935199154 3 77.3575606 20.6648568 8 77.3574113 20.6649839 .016954876948828607 .016887113566055816 8 77.3574113 20.6649839 3 77.3575606 20.6648568 .01695487694873152 .016887113566055816 5 77.3575002 20.6650337 7 77.3573469 20.6649224 .017329263815016975 .01726005392712035 7 77.3573469 20.6649224 5 77.3575002 20.6650337 .01732926381493958 .01726005392712035 4 77.3575485 20.6650475 8 77.3574113 20.6649839 .015395678452089924 .01533426237481381 8 77.3574113 20.6649839 4 77.3575485 20.6650475 .015395678451985187 .01533426237481381 1 77.3578571 20.6651418 9 77.3572835 20.6648907 .06433009205478166 .06407349013859497 9 77.3572835 20.6648907 1 77.3578571 20.6651418 .0643300920546915 .06407349013859497 6 77.3574477 20.6649944 7 77.3573469 20.6649224 .011390079375972122 .011344592342489466 7 77.3573469 20.6649224 6 77.3574477 20.6649944 .011390079376082803 .011344592342489466 5 77.3575002 20.6650337 8 77.3574113 20.6649839 .009999152843099721 .009959249617845842 8 77.3574113 20.6649839 5 77.3575002 20.6650337 .009999152843036705 .009959249617845842 3 77.3575606 20.6648568 9 77.3572835 20.6648907 .03094651436478564 .030823157659931853 9 77.3572835 20.6648907 3 77.3575606 20.6648568 .030946514364674802 .030823157659931853 4 77.3575485 20.6650475 9 77.3572835 20.6648907 .029831789929681864 .02971272530504808 9 77.3572835 20.6648907 4 77.3575485 20.6650475 .029831789929662112 .02971272530504808 6 77.3574477 20.6649944 8 77.3574113 20.6649839 .004071788971915234 .004055554043316913 8 77.3574113 20.6649839 6 77.3574477 20.6649944 .00407178897168955 .004055554043316913 5 77.3575002 20.6650337 9 77.3572835 20.6648907 .024443558834852434 .024345968792529725 9 77.3572835 20.6648907 5 77.3575002 20.6650337 .024443558834932787 .024345968792529725 7 77.3573469 20.6649224 8 77.3574113 20.6649839 .007345075410399752 .0073156998614609114 8 77.3574113 20.6649839 7 77.3573469 20.6649224 .00734507541054561 .0073156998614609114 6 77.3574477 20.6649944 9 77.3572835 20.6648907 .018505680096308492 .018431806891616102 9 77.3572835 20.6648907 6 77.3574477 20.6649944 .0185056800961626 .018431806891616102 1 77.3578571 20.6651418 11 77.3573635 20.6647909 .05576891137734457 .055546197647863595 11 77.3573635 20.6647909 1 77.3578571 20.6651418 .05576891137737377 .055546197647863595 3 77.3575606 20.6648568 11 77.3573635 20.6647909 .022063102465210382 .021975123384303283 7 77.3573469 20.6649224 9 77.3572835 20.6648907 .0071202544518154925 .007091846820384856 9 77.3572835 20.6648907 7 77.3573469 20.6649224 .0071202544519485 .007091846820384856 11 77.3573635 20.6647909 3 77.3575606 20.6648568 .022063102465375142 .021975123384303283 4 77.3575485 20.6650475 11 77.3573635 20.6647909 .021584689696044896 .02149806963181075 11 77.3573635 20.6647909 4 77.3575485 20.6650475 .02158468969594528 .02149806963181075 1 77.3578571 20.6651418 12 77.3568858 20.6647254 .1089124458721655 .10847802698771365 8 77.3574113 20.6649839 9 77.3572835 20.6648907 .014448298144443164 .014390593386197107 9 77.3572835 20.6648907 8 77.3574113 20.6649839 .014448298144484334 .014390593386197107 12 77.3568858 20.6647254 1 77.3578571 20.6651418 .10891244587238458 .10847802698771365 5 77.3575002 20.6650337 11 77.3573635 20.6647909 .016374459074049937 .016308500923845382 11 77.3573635 20.6647909 5 77.3575002 20.6650337 .01637445907414185 .016308500923845382 3 77.3575606 20.6648568 12 77.3568858 20.6647254 .07540304463008887 .07510245312967531 12 77.3568858 20.6647254 3 77.3575606 20.6648568 .07540304463001914 .07510245312967531 6 77.3574477 20.6649944 11 77.3573635 20.6647909 .010634961698612899 .010591824193995542 11 77.3573635 20.6647909 6 77.3574477 20.6649944 .01063496169871284 .010591824193995542 4 77.3575485 20.6650475 12 77.3568858 20.6647254 .07440149288076585 .07410466969902 12 77.3568858 20.6647254 4 77.3575485 20.6650475 .07440149288085882 .07410466969902 5 77.3575002 20.6650337 12 77.3568858 20.6647254 .06900426840551871 .0687289613014099 12 77.3568858 20.6647254 5 77.3575002 20.6650337 .06900426840539937 .0687289613014099 1 77.3578571 20.6651418 13 77.3569502 20.6645447 .10229272151430825 .10188432436021004 7 77.3573469 20.6649224 11 77.3573635 20.6647909 .0037101770023627383 .003694493653913419 11 77.3573635 20.6647909 7 77.3573469 20.6649224 .003710177002435724 .003694493653913419 13 77.3569502 20.6645447 1 77.3578571 20.6651418 .10229272151411901 .10188432436021004 3 77.3575606 20.6648568 13 77.3569502 20.6645447 .06857066432381853 .06829707692217528 13 77.3569502 20.6645447 3 77.3575606 20.6648568 .06857066432400225 .06829707692217528 6 77.3574477 20.6649944 12 77.3568858 20.6647254 .06307411081319587 .06282248491816965 12 77.3568858 20.6647254 6 77.3574477 20.6649944 .06307411081312252 .06282248491816965 4 77.3575485 20.6650475 13 77.3569502 20.6645447 .0679153744719298 .0676439570261961 8 77.3574113 20.6649839 11 77.3573635 20.6647909 .0071225518837364716 .007093157969535096 11 77.3573635 20.6647909 8 77.3574113 20.6649839 .007122551883650792 .007093157969535096 13 77.3569502 20.6645447 4 77.3575485 20.6650475 .06791537447206526 .0676439570261961 7 77.3573469 20.6649224 12 77.3568858 20.6647254 .051701884852473526 .051495663594055496 12 77.3568858 20.6647254 7 77.3573469 20.6649224 .05170188485244265 .051495663594055496 5 77.3575002 20.6650337 13 77.3569502 20.6645447 .06255446788669154 .06230439925072215 13 77.3569502 20.6645447 5 77.3575002 20.6650337 .0625544678866699 .06230439925072215 1 77.3578571 20.6651418 14 77.3570159 20.6647558 .09438422978121276 .09400772090925508 14 77.3570159 20.6647558 1 77.3578571 20.6651418 .09438422978133376 .09400772090925508 9 77.3572835 20.6648907 11 77.3573635 20.6647909 .0092583315366793 .009221222303066616 11 77.3573635 20.6647909 9 77.3572835 20.6648907 .009258331536926923 .009221222303066616 3 77.3575606 20.6648568 14 77.3570159 20.6647558 .06086034933892053 .06061773477227844 6 77.3574477 20.6649944 13 77.3569502 20.6645447 .05661809493900837 .056391736234691174 13 77.3569502 20.6645447 6 77.3574477 20.6649944 .05661809493909648 .056391736234691174 14 77.3570159 20.6647558 3 77.3575606 20.6648568 .060860349338887156 .06061773477227844 8 77.3574113 20.6649839 12 77.3568858 20.6647254 .05900604506371607 .05877063689395524 12 77.3568858 20.6647254 8 77.3574113 20.6649839 .05900604506358183 .05877063689395524 end
Comment