Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Calculating and storing distances


From   evan roberts <eroberts@hist.umn.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: Calculating and storing distances
Date   Wed, 30 Aug 2006 17:53:00 -0500

The previous code I submitted works fine for a limited number of observations. If there are more than 80 locations it will not work whereas the following will:
foreach var in id lat lon {
gen `var'2=.
}

save main, replace

qui desc
local max=r(N)

forvalues k=1(1)`max' {

use main, clear
replace id2=id[`k']
foreach var in lat lon {
replace `var'2=.
replace `var'2=`var' if id==id2
sort id2 `var'2
replace `var'2 = `var'2[1]
}

save tmp`k', replace

}

forvalues k=1(1)`max' {
use main, clear
append using tmp`k'
save main, replace
erase tmp`k'.dta
}

drop if id2==.

Evan Roberts

------------
Evan Roberts
Minnesota Population Center and Department of History
University of Minnesota
<eroberts@pop.umn.edu>
www.pop.umn.edu/~eroberts
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index