Dear Stalist,

I would like to as for help with stata code.

I would like to calculate a variable Market Potential of city x = sum ( density of city x / the distance between city x and another city say y) excluding the own location.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str42(unit_id2 city) double distance float density
"Redditch"                                   "Aberdeen"  538.9488301858304 186
"Tunbridge Wells"                            "Aberdeen"  687.1605708352208 186
"Basingstoke and Deane"                      "Aberdeen"  653.9312277748618 186
"Gravesham"                                  "Aberdeen"  656.3550968688601 186
"Wrexham"                                    "Aberdeen"    460.74995670796 186
"Newcastle upon Tyne"                        "Aberdeen"  243.5834903023147 186
"Cheltenham"                                 "Aberdeen"  584.4354234700095 186
"Corby"                                      "Aberdeen"  526.2946468063585 186
"Hartlepool"                                 "Aberdeen"  279.1608771987371 186
"Northampton"                                "Aberdeen"  579.4982283753968 186
"Derry & Strabane Local Government District" "Aberdeen"   404.181237326689 186
"Lincoln"                                    "Aberdeen"  447.3404506738833 186
"Crawley"                                    "Aberdeen"  683.7506509640012 186
"Great Yarmouth"                             "Aberdeen"   562.752295191962 186
"Ashford"                                    "Aberdeen"  695.6282666326395 186
"Luton"                                      "Aberdeen"  596.6251547844905 186
"East Staffordshire"                         "Aberdeen"  480.2147037885837 186
"Halton"                                     "Aberdeen"  603.9172622278094 186
"Bath and North East Somerset"               "Aberdeen"  648.8184349179473 186
"Glasgow"                                    "Aberdeen"  195.2692320933963 186
"Darlington"                                 "Aberdeen" 294.29806180182084 186
"Dacorum"                                    "Aberdeen"  610.3353004167517 186
"Gloucester"                                 "Aberdeen"  588.4245143774907 186
"Stoke-on-Trent"                             "Aberdeen"  461.6957090248311 186
"Nuneaton and Bedworth"                      "Aberdeen"  565.2930223777662 186
"Hastings"                                   "Aberdeen"  722.0688218275432 186
"Wirral"                                     "Aberdeen"  425.0609598073945 186
"York"                                       "Aberdeen" 360.75142337901974 186
"Mansfield"                                  "Aberdeen" 449.21592884405317 186
"Bristol"                                    "Aberdeen"  634.7439243094524 186
"Maidstone"                                  "Aberdeen"  676.1942724007241 186
"Portsmouth"                                 "Aberdeen"  707.6103673826763 186
"Blackburn with Darwen"                      "Aberdeen"   379.464917052019 186
"Derby"                                      "Aberdeen"  472.2485483817221 186
"Bracknell Forest"                           "Aberdeen"  644.1962109880027 186
"Burnley"                                    "Aberdeen" 374.23418588211246 186
"Cannock Chase"                              "Aberdeen"   493.361637053212 186
"Worthing"                                   "Aberdeen"  713.6855838548622 186
"Thanet"                                     "Aberdeen"  682.1411053497534 186
"Kingston upon Hull"                         "Aberdeen" 392.74147919044026 186
"Carlisle"                                   "Aberdeen" 256.69913984067006 186
"Ipswich"                                    "Aberdeen"   604.244822077334 186
"Sheffield"                                  "Aberdeen"  421.4191534500604 186
"Doncaster"                                  "Aberdeen"  408.3947467003535 186
"Coventry"                                   "Aberdeen"  529.2638100189234 186
"London"                                     "Aberdeen"  640.8760347183809 186
"Middlesbrough"                              "Aberdeen" 291.75205840222293 186
"Swindon"                                    "Aberdeen"   622.998265948475 186
"Leeds"                                      "Aberdeen"  374.4274682583155 186
"Woking"                                     "Aberdeen"   656.873050055704 186
"Nottingham"                                 "Aberdeen" 470.79965378391677 186
"Bedford"                                    "Aberdeen"  567.5848017634672 186
"Plymouth"                                   "Aberdeen"  765.8835860553229 186
"Blackpool"                                  "Aberdeen" 375.71555014964963 186
"Colchester"                                 "Aberdeen"  615.8087553455063 186
"Brighton and Hove"                          "Aberdeen"  715.7635692720925 186
"Worcester"                                  "Aberdeen"  551.7602550287742 186
"Sunderland"                                 "Aberdeen" 253.61324803039628 186
"Warrington"                                 "Aberdeen"  419.7759572857106 186
"Wycombe"                                    "Aberdeen"  619.0974387220948 186
"Dundee City"                                "Aberdeen"  93.43684246036214 186
"North East Lincolnshire"                    "Aberdeen" 418.76613873287334 186
"Edinburgh"                                  "Aberdeen" 149.24293393240575 186
"Southampton"                                "Aberdeen"  696.0046021816779 186
"Preston"                                    "Aberdeen" 378.98319260324905 186
"Telford and Wrekin"                         "Aberdeen" 491.42893118950155 186
"Cardiff"                                    "Aberdeen"  634.8350926123351 186
"Swansea"                                    "Aberdeen"  626.9227637062459 186
"Leicester"                                  "Aberdeen" 506.07685833382226 186
"Aberdeen"                                   "Aberdeen"                  0 186
"Norwich"                                    "Aberdeen"  547.9345721838114 186
"Liverpool"                                  "Aberdeen"  420.3885976940918 186
"Chesterfield"                               "Aberdeen"   437.906359716411 186
"Peterborough"                               "Aberdeen"  523.5327454156856 186
"Eastbourne"                                 "Aberdeen"  727.2347842257957 186
"Slough"                                     "Aberdeen"   635.195561632506 186
"Torbay"                                     "Aberdeen"  750.2604951130426 186
"Stevenage"                                  "Aberdeen"  596.6691108406063 186
"Exeter"                                     "Aberdeen"  721.9997010962056 186
"Cheshire West and Chester"                  "Aberdeen"  438.1173525786495 186
"West Midlands urban area"                   "Aberdeen"  507.9287175208408 186
"Milton Keynes"                              "Aberdeen"  575.2016514202114 186
"Waveney"                                    "Aberdeen"   580.884234511616 186
"Bournemouth"                                "Aberdeen"   761.542077879677 186
"Oxford"                                     "Aberdeen"  603.2679917027987 186
"Manchester"                                 "Aberdeen" 398.32196313816775 186
"Medway"                                     "Aberdeen"  661.9987589620909 186
"Kettering"                                  "Aberdeen"  536.3477557530864 186
"Rushmoor"                                   "Aberdeen"  660.0437839412406 186
"Cambridge"                                  "Aberdeen"  568.5794152808597 186
"Newport"                                    "Aberdeen"  622.2660390426063 186
"Guildford"                                  "Aberdeen"  680.6774935950415 186
"Falkirk"                                    "Aberdeen" 164.66950039261408 186
"Belfast"                                    "Aberdeen" 371.92034406766203 186
"Reading"                                    "Aberdeen"  638.0844043076983 186
"Belfast"                                    "Ashford"   597.4012348401163 581
"Guildford"                                  "Ashford"  23.516499989777113 581
"Warrington"                                 "Ashford"  344.15910957734565 581
"Portsmouth"                                 "Ashford"  142.55379542671852 581
"Torbay"                                     "Ashford"   319.3471264720729 581
end


Thanks,

Bridget