Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nearstat count number of neighbors that satisfy a certain condition

    Hello everyone,

    Currently, I am trying to generate a variable that indicates me the number of neighbors that are within 1 km and received a treatment. The indicator must be in control observations and treatment observations. So, if the observation is control, it would give me the total number of treated observations within 1 km, the same for the treated observation.

    I have tried with the following code:

    nearstat latitude longitude, near(latitude longitude) distvar(mydist) ncount(number_treated_HH) dband(0 1) contvar(puretreatment)

    where puretreatment = 1 if the observation received the treatment. Nevertheless, I haven't succed. It returns the total number of neighbors within 1 km, regardless if the observation received or not the treatment.

    Thank you very much in advance for your help,

    Regards

    Sara R

  • #2
    What about using the option on -nearstat- to return an id for each neighbor? Then you could use -merge- to get whatever treatment information you need merged based on the id variable. I have not done this with -nearstat-, but I presume it would work. You'd want this in long format for this purpose.

    However, I would use -geonear- (-ssc describe geonear-) instead, which I do know would work for this purpose, and which for large problems (the last time I tried it) was orders of magnitude faster than -nearstat-. (I had a situation in which some experiments indicated that -nearstat- would have required several months to solve a problem, while -geonear- did it in about 10 minutes!)

    Comment

    Working...
    X