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
Estimate GARCH-DCC with asymmetriesHas anyone had experience estimating GARCH-DCC models with asymmetries (GJR for example)? Can this b…
bysort queryHello, I am trying to use bys to generate sequential and total number of Lines of treatments by pati…
Multiple time-failure analysis, event-specific coeffcients?Dear all, I am using stcox along with a stratification variable to estimate the hazard functions fo…
How to create control group against fraud firms?Dear all, I want to create a control sample of non-fraud firms against firms that committed fraud. I…
ElasticitiesHello, I would like to estimate the exports elasticity and the imports elasticity of some countries…
Subscribe to:
Post Comments (Atom)
0 Response to Looping with Geodist
Post a Comment