Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: Looping 2x over same list |

Date |
Wed, 31 Mar 2010 14:07:34 +0100 |

One facet of this is working with x-y and y-x dyads. Only last week there was some discussion of a related problem, if not the same problem: http://www.stata.com/statalist/archive/2010-03/msg01633.html Nick n.j.cox@durham.ac.uk Kieran McCaul I don't know if this will help, but if you merge all the recipients with all the donors and then: sort recipient donor by recipient: gen total=_N All records where total = 1 will be recipients who receive aid from one donor only. Those with total>1 will be recipients who receive aid from multiple donors. Christopher O'Keefe I'm attempting to create a dataset that assesses overlap in recipients across multilateral aid institutions (donors). I have created separate datasets of recipients (by institution) and now I want to compare overlap across pairs of institutions. So far, I have attempted to do this by looping over the values of a macro called donor, once for each part of the dyad. Of course, this results in dyads x-y, y-x, and x-x. I want to figure out how to get rid of the y-x dyads (and x-x dyads too, but those are easy enough to get rid of without losing important data). In some respects this is similar to the problems here and here (in section 3). What is different is that I'm looping over the same list to merge files, create variables, save files, and append everything into the final dataset. Does anyone have any insight into how I can stop producing the y-x dyads (or how to exclude them when I append these files into a single dataset?). (Code is below). Thanks so much for your help. Code: foreach d of local donor { foreach e of local donor { foreach p of local ten_yr { use `d'_ten`p'_comp.dta, clear merge recipient using `e'_ten`p'_comp.dta gen shar_recip = 1 if _merge == 3 replace shar_recip = 0 if _merge != 3 collapse (sum) shar_recip local n = r(N) gen shar_recip_b = shar_recip/`n' *gen shar_recip_10 = shar_recip/10 gen dyad = "`d'-`e'" save `d'_`e'_ten`p', replace } } } clear tempfile base gen shar_recip = . gen dyad = "" save `base' use `base', clear foreach d of local donor { foreach e of local donor { foreach p of local ten_yr { capture append using `d'_`e'_ten`p' drop if dyad == "`d'-`d'" } } } * * 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/

**References**:**st: Looping 2x over same list***From:*"Christopher O'Keefe" <cokeefe@ucsd.edu>

**st: RE: Looping 2x over same list***From:*"Kieran McCaul" <Kieran.McCaul@uwa.edu.au>

- Prev by Date:
**st: RE: psmatch2-identifying matched pairs** - Next by Date:
**st: AW: -findname- available from SSC** - Previous by thread:
**st: RE: Looping 2x over same list** - Next by thread:
**st: warning after areg** - Index(es):