[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Understanding the difference between gen and egen
I would add that the confusion stems from the fact that the -egen-
functions occupy a separate namespace from the functions available to
expressions in general (not just to -gen-). All seasoned Stata users
know this, though we may not have thought of it that particular way.
But Stata is full of many different types of entities having separate
namespaces (variables, labels, scalars & matrices, command names,
functions, egen functions); we just learn to read every identifier in
the context of its namespace.
This is not to say that it isn't confusing; it's just that it needs
to be emphasized to beginners as an important part of understanding
Stata, and once you get it, it's fairly easy.
To add to the confusion, not only do -egen- functions occupy a
separate name space, but their names can begin with a digit. You can
create an egen function 3abc, so that you would code...
egen a = 3abc(y)
It could even be just a number!:
egen a = 3(y)
Of course, this is not a good idea, but the syntax allows it.
Another oddity: "sum", the built-in cumulative sum function, can
appear in any expression -- such as the argument to some egen
functions. Thus, you can write,
egen a = sum(sum(y))
The first "sum" is an egen function; the second "sum" is the built-in
cumulative sum function.
All this might add to the confusion, but once you understand it, then
it all becomes easy.
At 12:41 PM 6/13/2006, Richard Campbell wrote:
I am now a confirmed Stata user and love it for all the reasons
that Phil Schumm outlined the other day and more. But the recent
note from a user regarding sums within id reminds me of how
difficult it is sometimes for new users to get a handle on relatively
simple things. In the current case, if I look up "sum" in the master
index, I am directed to -egen-. If I go to -egen-, somewhat surprisingly,
I don't find -sum- listed in the list of egen functions beginning on page 101
of the Data Management manual or summary of that list on page 105.
Nor is it available in the drop down list of egen functions
I can do -sum- as a function using -gen- but then I get a running sum, not
* For searches and help try: