Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Appending several files

From   Paul Seed <>
Subject   Re: st: Appending several files
Date   Mon, 16 Oct 2006 14:36:15 +0100

Nuno Soares  <> asked :

I'm trying to make Stata to append several files that are in a given
directory without the need of specifying the name of each one. I was
thinking of doing something like this (using the fs package):

cd "C:\data"
qui fs *
foreach f in `r(files)' {
append using `f'

And Ulrich Kohler <>


. fs *.dta
. local firstfile: word 1 of `r(files)'
. use `firstfile', clear
. foreach f in `r(files)' {
.   if "`f'" ~= "`firstfile'" append using `f'
. }

- --

Ulrich's solution works, but I thought it was
worth pointing out another approach:

fs *.dta

local getfile "use"
foreach file in `r(files)' {
	`getfile' `file'
	local getfile "append using "

I often use local macros in this way,
where a different command, or option,
is needed at different stages in a loop.

I can either change the command after the first
run (as here), or when some condition is met.

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index