Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Constructing assignment var for Spatial RDD: For each id in region 1 need shortest distance to an id in region 0


From   Stata Chris <[email protected]>
To   [email protected]
Subject   Re: st: Constructing assignment var for Spatial RDD: For each id in region 1 need shortest distance to an id in region 0
Date   Fri, 27 Nov 2009 22:06:53 -0500

Thanks, that's a very convenient command!!

I just haven't been able to figure out how to restrict it to search
for the each member of group 0 (1) not the closest one of all but the
closest one only from the respective other group, since -nearest-
doesn't seem to allow if conditions.

I tried to always keep just one member of group 0 ("number" <1000)
with all of group 1 ("number" > 1000) before executing -nearest-, as
in the below, but that would seem rather inelegant to say the least...

forvalues number = 1/246 {
    preserve
    keep if number2==number | number2>1000
	drop partner dist
	nearest zkx zky, id(partner) dist(dist)
	replace distance = dist
	save distance, replace
	restore
	drop _merge
	merge id using distance, sort
}



2009/11/27 Roy Wada <[email protected]>:
>> distance to each village in region 0 (1), as
>> d=sqrt[ (y_1-y_0)^2  +  (x_1-x_0)^2  ],
>
> If you are going to use Euclidean distance take a look at -nearest- from ssc.
>
> Roy
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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