Dear Statalisters
I have shapefile containing information about the geographic coordinates of all the districts in Pakistan. I am required to have a variable of the distance between a border district and the rest of all the districts. I am using STATA 15's 'spdistance' command to calculate it. As the syntax for 'spdistance' returns the distance between two district IDs whereas I want to calculate the distance between 93 districts. Is there any way I can do it in a loop? I am writing the codes here as I am not sure how to use 'dataex' with shapefile.
capture drop distance
gen distance=.
local id 20 54 94 95 99 101
spdistance `id' 96 (* where 96 is the id for border district which will remain fixed)
replace distance=r(distance) if distt_id==`id'
however, this code returns an error i.e
94 95 99 101 96 found where nothing expected
r(198);
Related Posts with calculating distance in a loop using 'spdistance' in STATA 15
Graph: display negative sign using en-dash instead of hyphenHi list, Code: webuse auto,clear replace rep78=-1*rep78 if foreign==1 scatter rep78 trunk,ysc(r(-5…
Graph: couldn't get the looking of apostrophe rightHi list, I need to include an apostrophe in my figure. Someone asked me to change the looking of th…
repeating a smoothing function in a time seriesHello I have a series of mortality data for 100 countries. I have (clumsily) coded the following fo…
Command for estimating household consumption aggregateHello Statalist, Here is a preview of my dataset Code: * Example generated by -dataex-. To instal…
Collapsing unique country names and country IDsHello, I am getting strange results when I try to collapse country data and I would like to ask you…
Subscribe to:
Post Comments (Atom)
0 Response to calculating distance in a loop using 'spdistance' in STATA 15
Post a Comment