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

 From "Martin Weiss" To Subject st: RE: 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 23:56:31 +0100

```<>

On loops you want to look at Nick`s
http://www.stata-journal.com/sjpdf.html?articlenum=pr0005

Your id1 and id0 separation cries out for -separate-

You will find listers reluctant to answer because of the attachment. Look at
the FAQ, they are quite explicit...

HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Stata Chris
Sent: Freitag, 27. November 2009 23:49
To: statalist@hsphsun2.harvard.edu
Subject: st: Constructing assignment var for Spatial RDD: For each id in
region 1 need shortest distance to an id in region 0

Dear Statalisters,

I would like to construct the assignment variable for a Spatial RDD,
i.e. for each village in either of two regions I would like to know
the distance to the border.

Now, while I know the x- and y-coordinate of each village in the
sample, I do not know the exact position of each point on the border;
So my idea was to compute for each village in region 1 (0) the
distance to each village in region 0 (1), as
d=sqrt[ (y_1-y_0)^2  +  (x_1-x_0)^2  ],
and then take for each the minimum of these as the value for the
assignment variable. Because both regions have quite a few villages, I
will need to compute many such distances, so I think it will probably
be best to do this with a loop. I have a rough idea of what the loop
should do, but I'm not entirely sure how exactly to communicate this
to Stata.

I am attaching the dataset, and below I provide a rough indication of
what I think are the necessary steps. If one of you was able to help
me put this into a syntax Stata does actually understand, that would
be awesome:

gen id1 = id if treatment==1
gen id0 = id if treatment==0
for each id1 {
for each id0 {
gen dist_id1_id0 = sqrt(  (zkx{id1}-zkx{id0})^2   +
(zky{id1}-zky{id0})^2 )
gen assignmentvar_id1 = min (of all dist_id1_*)
}
}

And then do the same also the other way round.

Thank you so much,
Chris

*
*   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/
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.834944,"math_prob":0.7083942,"size":2632,"snap":"2023-40-2023-50","text_gpt3_token_len":749,"char_repetition_ratio":0.11035007,"word_repetition_ratio":0.12850468,"special_character_ratio":0.27317628,"punctuation_ratio":0.13381556,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9503838,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-08T10:08:41Z\",\"WARC-Record-ID\":\"<urn:uuid:4d34868c-23fe-4c19-9e0c-816b9dd4e961>\",\"Content-Length\":\"9087\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bf5c796e-0400-4e4e-b8a5-4cb28a66234e>\",\"WARC-Concurrent-To\":\"<urn:uuid:b7a4d7d4-d712-42b9-86df-60e2b5ccbaad>\",\"WARC-IP-Address\":\"66.76.6.5\",\"WARC-Target-URI\":\"https://www.stata.com/statalist/archive/2009-11/msg01450.html\",\"WARC-Payload-Digest\":\"sha1:CSFSDEW6OYEX57XJVHXMVCF7YHMJ2OHT\",\"WARC-Block-Digest\":\"sha1:LQBMUTE2LHQOLXVPLB4VXS4TQ2ENN66A\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100739.50_warc_CC-MAIN-20231208081124-20231208111124-00512.warc.gz\"}"}