Statalist The Stata Listserver


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

Re: st: RE: Understanding the difference between gen and egen


From   Ulrich Kohler <kohler@wz-berlin.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Understanding the difference between gen and egen
Date   Wed, 14 Jun 2006 09:57:31 +0200

> Dick Campbell
> > This all may be an oversight or a failure on my part to see
> > the obvious, but
> > in general, I find the distinction between -gen- and -egen-
> > to be confusing.
> > It would seem logical that all of this stuff could be handled
> > by -gen-. But
> > -gen- is not accessible to users, being a built in command,
> > while -egen- is and
> > various users have added various things to it. Thus, I guess
> > the reason for
> > -egen- is that it is user accessible, not that it has some
> > special status
> > relative
> > to -gen-. To a new user, however, and even to more experienced ones,
> > this is all a bit confusing.

Besides the accessibility to end users, there is another difference between 
the two. -egen- function are, well, egen-functions. They are available only 
for -egen- and at no other place in Stata world. -gen-, on the other hand, 
expects an expression behind the equal sign (gen varname = <exp>). The 
expression can be any Stata function, and have their place at quite some 
other places of the Stata world (if <exp>, local macname = <exp>, `=<exp>', 
twoway function y = <exp>, if <exp> { ; else if <exp>). 

As a consequence, if you learn to generate a specific variable with a specific 
egen function, you learn how to generate a specific variable with that 
specific -egen- function. If you learn to generate the same variable with 
-gen- and Stata-functions you learn something that can be also used outside 
the specific problem. This clearly does not help new users with their 
confusion. However when teaching Stata one should not forget it. 

BTW there is a similar situation with macros. The standard definition of 
macros is -local macname = <exp>-, and there is a second list of functions 
that are only available for macros, namely the extended macro function. 
Syntax here is -local macname: <extended fcn>-. In direct analogy, one might 
bond -gen- with -egen- by using -gen varname = <exp>-, and -gen varname : 
<egen-fcn>. I don't know whether this would be less confusing for new users. 
In addition this brings the problem of continuity and consistency back in. 

Uli

-- 
kohler@wz-berlin.de
+49 (030) 25491-361
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index