Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Kieran McCaul" <Kieran.McCaul@uwa.edu.au> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | st: RE: Looping 2x over same list |
Date | Wed, 31 Mar 2010 07:33:14 +0800 |
... 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. -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Christopher O'Keefe Sent: Wednesday, 31 March 2010 6:16 AM To: Stata list Subject: st: Looping 2x over same list Hi all- 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. Best, Chris O'Keefe 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'" } } } -- ____________ PhD Student University of California, San Diego Dept. of Political Science http://dss.ucsd.edu/~cokeefe * * 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/ * * 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/