I have a dataset with individuals with their geocoordinates and supermarket branches with geocoordinates. I need to calculate distance between the house of each individual to all the supermarket branches operating on the year of birth of that individual.
I know the format of geodist and geonear but I don't know how to loop it for each individuals year of birth to each supermarket's branch year.
For example:
clear
set obs 10
gen lat1 = 37 + (41 - 37) * uniform()
gen lon1 = -109 + (109 - 102) * uniform()
gen yrbirth= round(1950 + (12-5) * uniform())
save "individual.dta", replace
clear
set obs 15
gen lat2 = 37 + (41 - 37) * uniform()
gen lon2 = -109 + (109 - 102) * uniform()
gen stryr= round(1950 + (12-5) * uniform())
save "store.dta", replace
merge 1:1 _n using "individual.dta", nogen
Now, in this example, individual 1 with year of birth 1952 does not have any supermarket branch operating in that year so I want the distance to be (.). For the individual with year of birth 1955, I want to calculate the distance to the 7 supermarket branches operating in 1955. I want to do it for all individuals and then keep for each individual the nearest two supermarket branches.
I would appreciate if someone can help me.
Related Posts with Looping with Geodist
Eurobarometer and only look at varibles in one countryHi! I have an assignment where I would like to use Eurobarometer. What I want to do is to only look…
ARDL ECM bounds testHi, I have selected optimal lags for an ARDL with two variables, plus impulse dummies (time series)…
Summary table (specifically standard deviation) for ANOVA commandI am trying to get a summary table for my anova command (like the subcommand tabulate does when you …
Forestplot using the metan commandHi, How can I create a forestplot using the metan command, in which the x range will be from 0.4 to…
generating new variableHello members, Please i want to generate a new variable "marital status" to have categories "1. Mari…
Subscribe to:
Post Comments (Atom)
0 Response to Looping with Geodist
Post a Comment