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

RE: st: RE: row mean (mean across columns)

From   "Nick Cox" <>
To   <>
Subject   RE: st: RE: row mean (mean across columns)
Date   Thu, 9 Oct 2008 14:16:22 +0100

Thanks for the thanks. 

I exaggerated a bit, but the warning was still genuine. -egen- is odd
that it is a pre-processor for -egen- functions and -- in particular --
it does not include a -syntax- statement that results in a local macro
varlist containing a varlist. This is because it has to be general to
cover the variety of syntaxes that are possible with -egen- functions,
all the way down to empty arguments and all the way up to more general

Putting it the other way round, almost always this issue would be
tackled for you very early in a program by 

syntax varlist 


syntax [varlist] 

that would process your input before you created any temporary
variables. But, if you have any temporary variables elsewhere, using
_all or * could still be problematic. In essence, however, it gets to be
rare that you want to write a program to do exactly the same thing to
all variables (if only because most people have identifiers too, and so

The point was shown up forcefully in Jacob's post because he's,
presumably, at an early stage in Stata programming. As many know, with
Stata programming there are several things that need to be learned more
or less simultaneously if you are not to get very confused and -syntax-
is one of them. 

I left out of my earlier post a general point that puzzles me: What is
the easiest way to get a list of all permanent variable names? (And
nothing else.) 

In practice 

unab all : * 
unab temp : __*
local perm : list all - temp 

usually works, but this hinges on the empirical fact that Stata's names
for temporary variables all start with a double underscore. But nothing
stops a user creating permanent variables with such names directly as in

gen __foobar = 42 

and any such practice would break that code. What am I missing? 


Eva Poen


thank you very much for this very helpful and comprehensive
explanation. I have a question/comment on the last paragraph:

2008/10/9 Nick Cox <>:

> But there's a larger lesson. * and _all within programs (and also
> interactively) will include, necessarily, any temporary variables that
> exist. So, looping across varlists defined by such wildcards is a
> of bugs. Arguably, they are yours, not Stata's.

It certainly is consequential that * and _all comprise all variables,
including existing temporary variables. However, as a user I would
expect * and _all to consist only of those variables that existed at
the time I issued the command (since these are the only variables I
know about; I have little control over what is done internally by
command -x-). Anything but this behaviour would vastly reduce the
usefulness of * and _all, IMHO.

What is the status quo on this? Many Stata commands generate temporary
variables; therefore this might be a comprehensive issue for those
users making use of * and _all shorthands.

*   For searches and help try:

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