Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: Problem with wildcards

From   daniel klein <>
Subject   Re: st: Problem with wildcards
Date   Tue, 5 Mar 2013 00:49:04 +0100


the obvious difference is, that -egen- is one line to type, while my
approach involves three lines of code.

I would prefer an -egen- solution in a do-file, though I think I would
rely on -anymatch()- rather than -rowax()-, which might be even more
intuitive to understand.

Programming an ado-file, I am rather reluctant to use -egen-, because
despite being powerful, it is interpreted code (I know, so is -unab-)
and therefore tends to execute slow(er). You would not notice the
difference probably, and if so it would probably be a matter of less
than a second, so this might be a rather weak argument.

The main point of my approach is to show (or remind you of) more
general concepts, like (extended) functions. These concepts might look
clumsy for your specific problem (and they probably are), but they
proof to be very helpful in many other situations. One example is the
"inverse" use of -inlist()-, that I first learned from Nick Cox
(, and
have used a lot ever since.

Thank you, Dimitriy and Daniel.

I'd be very interested in understanding the
differences/benefits/drawbacks between these two approaches, if
someone could explain them to me.

*off to read about rowmax and rowtotal*,

On Mon, Mar 4, 2013 at 4:48 PM, Dimitriy V. Masterov <> wrote:
You could use egen (extended generate) to do this:

egen anypsych = rowmax(psych1 - psych42)


On Mon, Mar 4, 2013 at 6:01 PM, daniel klein <> wrote:
> Here is my approach.
> unab psych : psych1-psych42
> loc psych : subinstr loc psych " " ", " ,all
> g byte anypsych = inlist(1, `psych')
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index