Statalist The Stata Listserver


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

RE: st: Appending several files


From   David Kantor <[email protected]>
To   [email protected]
Subject   RE: st: Appending several files
Date   Mon, 16 Oct 2006 10:10:29 -0400

Thanks, Nick, for your comments and your alternative suggestion.

At 08:01 AM 10/16/2006, you wrote:
[...]

2. As you want the numeric interpretation, I find

local j = 0

clearer, particularly as you are testing its
numeric value later. Stata doesn't care, but
a code reader might.
Yes, indeed, but we are also told, understandably, that
local j "0"
is more efficient. But it is a minor inconvenience for Stata to process -local j = 0-. Furthermore, if I had been really attentive to the fact the j is a number, then I would have used scalars instead. But I use macros to make use of the ++ operator. I don't believe that it applies to scalars. (??)


3. If you are a Windows user and accustomed
to putting spaces in your filenames, this will
fall over unless the names come quoted.
Yes, indeed. But I am not one to use spaces in file names, so I hadn't thought of that. (I find them a bit of an anathema. But they are with us now, at least among Windows users, and there's no turning back. I suppose they are a feature that was created to make computers more accessible to the Muggles.)


I feel queasy about going through two loops
simultaneously unless it's unavoidable.
That's mostly just a style prejudice.
[...]
I hadn't even thought of it as two loops simultaneously. I think of it as one loop with f as the driver; j is a "passenger". It is not unusual, in general programming, to have many "passenger" variables in a loop, each acquiring new values in each iteration.

Another matter: I used the "number" j as a convenient way to tell whether you are in the first iteration. You don't really need to know the iteration count; the real issue is whether the loop is in the first iteration. Thus you can do:

local first = 1
foreach f in `r(files)' {
if `first' {
use `f'
local first = 0
}
else {
append using `f'
}

Also, Paul Seed had another interesting technique.

--David

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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