Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: FW: RE: Looping gen sequentially over datasets


From   "Alex Sutherland" <[email protected]>
To   <[email protected]>
Subject   st: FW: RE: Looping gen sequentially over datasets
Date   Fri, 27 Sep 2013 13:14:39 +0100

Dear Joe, dear Steve,

Thanks both for the solutions, that?s nailed it. Joe, I am slightly
embarrassed I didn?t know about the append option!

Regards,

Alex

Steve?s solution:
use "dataset1"
g id=1
lab def idlab foo
lab val id idlab
save, replace

forval i = 2/40 {
                append using "dataset`i'"
                replace id=`i' if (missing)id
}

save "newdata", replace

Joe?s:
local id=0
foreach file in "file1" "file2" ... {
       use `file', clear
       local ++id
       gen School_ID=`id'
       save , replace
} 


***********************************************************


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index