<>
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: [email protected]
[mailto:[email protected]] On Behalf Of Stata Chris
Sent: Freitag, 27. November 2009 23:49
To: [email protected]
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/