[R] Equivalent to Stata egen

Stas Kolenikov skolenik at gmail.com
Thu Apr 16 17:57:07 CEST 2009


http://www.stata.com/help.cgi?egen -- it creates new variables dealing
with some special relatively non-standard tasks that don't boil down
to a one-line arithmetic expressions. For that reason, there will be
no equivalent to -egen- in general, as it has so many functions that
are so different. -rowtotal- is of course just a shorthand for sum(),
except for treatment of missing values ( ifelse(is.na(x),0,x ). But
-anycount- is a moderately complicated double cycle over variables and
list of values (40 lines of underlying Stata code, including parsing
and labeling the resulting variables)... which will probably become a
triple R cycle including the cycle over observations, although the
latter can probably be avoided.

Yes, R documentation looks exteremely terse to me as a regular Stata
user. I am used to seeing the concpets explained well, even in the
help files, and certainly more so in the shelved books. As every
option and every part of the syntax is devoted at least three to five
sentences, and the most common uses are exemplified, I can usually
figure out how to run a particular task relatively quickly. (The data
management tricks, which is what Peter was asking about above, are
probably an exception: you either know them, or you don't. In this
example, I don't know the corresponding R tricks, although I can
probably brute force the solution if I needed to.) The fraction of
commands in R that I personally have been coming across that are
comparably well documented is about a quarter. For other, it is either
a guesswork+CRANning+googling around or "Forget it, I'll just go back
to Stata to do it" after a few futile attempts. May be I just don't
know where to look for the good stuff, but it is certainly outside R
as a package+its documentation.

On 4/15/09, David Winsemius <dwinsemius at comcast.net> wrote:
> Peter Kraglund Jacobsen <peter <at> kraglundjacobsen.dk> writes:
>
>  >
>  > What are the R equivalents to the Stata command egen?
>  >
>  > egen temp = anycount(t0vas t30vas t60vas t120vas t240vas t360vas),
>  > values(0,1,2,3,4,5,6,7,8,9,10)
>  > egen temp2 = rowtotal(t0vas t30vas t60vas t120vas t240vas t360vas)
>  >
>
>
> And people call R documentation cryptic! As far as I can tell the corresponding
>  function would be ave, but that is only a guess since there really is not much
>  help regarding egen's purpose from the voluminous Stat documentation.
>
>
>  --
>  David Winsemius
>  > ______________________________________________
>  > R-help <at> r-project.org mailing list
>
> > https://stat.ethz.ch/mailman/listinfo/r-help
>  > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>  > and provide commented, minimal, self-contained, reproducible code.
>  >
>  >
>
>  ______________________________________________
>  R-help at r-project.org mailing list
>  https://stat.ethz.ch/mailman/listinfo/r-help
>  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>  and provide commented, minimal, self-contained, reproducible code.
>


-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.




More information about the R-help mailing list