Bookmark and Share

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]

st: Looping with merge


From   Adam Guerrero <adamgue@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Looping with merge
Date   Mon, 13 May 2013 10:42:05 -0400

Hello All,

I am trying to write a loop for the following lines of code

merge m:1 zip_num using zip_pov.dta, keepusing(povrate)
drop if _merge==2
drop _merge
merge m:1 zip_num using p15_zip.dta, keepusing(permcf)
drop if _merge==2
drop _merge
merge m:1 zip_num using p37_zip.dta, keepusing(perbachelor)
drop if _merge==2
drop _merge

This is what, but has not been working

foreach file in zip_pov.dta p15_zip.dta p37_zip.dta {
foreach var of varlist "povrate" "permcf" "perbachelor" {
merge m:1 zip_num using `file', keepusing(`var')
drop if _merge==2
drop _merge
    }
}

Any advice would be very much appreciated.   Thanks in advance.

Adam Guerrero
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index