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]
Re: st: appending several files with different variable names
From
daniel klein <[email protected]>
To
[email protected]
Subject
Re: st: appending several files with different variable names
Date
Sat, 3 Mar 2012 09:11:14 +0100
My code came four lines short. Of course you want to take some action
if -rename- fails for whatever reason.
foreach file in files {
qui u `file' ,clear
cap noi unab school : *school*
if _rc {
di as err "error occurred in `file'"
continue // or wahtever you want to do
}
if (`: word count `school'' > 1) {
di as txt "(note: more than one " /*
*/ "variable *school* found in `file'"
[do whatever you want to do in this case]
}
cap noi ren `school' school
if _rc {
di as err "error occurred in `file'"
continue // or wahtever you want to do
}
loc `"foundin `foundin' "new_`file'""'
qui sa new_`file'
}
gettoken firstfile foundin : foundin
u `firstfile' ,clear
ap using `foundin'
sa file_country
Best
Daniel
*
* 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/