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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: appending several files with different variable names


From   daniel klein <klein.daniel.81@googlemail.com>
To   statalist@hsphsun2.harvard.edu
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/


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