I am doing peer effects analysis based on geography. I have an id for the unit level and then the id of the 4 closest units. If a fraction of units were exposed to a treatment then I would like to know if a unit's closest neighbors were exposed to this treatment. for example
So the goal would be to define a new dummy variable that is contingent on one of the neighbors having treated == 1 or the unit itself having treated == 1
so the desired output would be
I could imagine making a loop but I fear that this could be computationally expensive considering that I have many observations but I would appreciate any suggestions.
Code:
ssc install dataex input long id long neighbor1 long neighbor2 long neighbor3 long neighbor4 float treated 1 9 10 2 3 1 2 10 1 3 4 0 3 1 2 4 5 0 4 2 3 5 6 0 5 3 4 6 7 0 6 4 5 7 8 0 7 5 6 8 9 0 8 6 7 9 10 0 9 7 8 10 1 0 10 8 9 1 2 0
so the desired output would be
Code:
ssc install dataex input long id long neighbor1 long neighbor2 long neighbor3 long neighbor4 float treated float exposed 1 9 10 2 3 1 1 2 10 1 3 4 0 1 3 1 2 4 5 0 1 4 2 3 5 6 0 0 5 3 4 6 7 0 0 6 4 5 7 8 0 0 7 5 6 8 9 0 0 8 6 7 9 10 0 0 9 7 8 10 1 0 1 10 8 9 1 2 0 1
Comment