[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: RE: Re: Like %GL(r,n) in GLIM
-egen, seq()- was published in STB-50 in 1999
and added to Stata 7.
An earlier program -seq- was published in STB-37 in 1997.
It is now obsolete.
I wanted to construct such sequences often enough
myself and people used to post questions like Herb's
on Statalist at the time. I know also that in writing
the code I looked at books on GLIM and also on S
to see what was available to users of those programs.
There is much two-way traffic here. I understand that
R now has reshape commands similar to -reshape-. For
that matter, many programs have say square root
or log functions, all with remarkably similar names.
A more interesting general question is that users may
want to do something quite simple and may be unclear
0. Need to program it themselves.
1. Can find a way of doing it with functions.
2. Can find a way of doing it with an inbuilt
If it's really simple it is unlikely that you are
the first to want it!
-egen, seq()- is really just a convenience function
as probably everything it does could be done in
one line with more basic functions and _n. It is
just that many of us would need to fiddle a bit
to get there. You need to subtract 1 and add 1
in the right places and getting it slightly wrong
is getting it wrong.
For sequences like 1, 2, 3, 4, 1, 2, 3, 4, ...
note first that the remainder on dividing
integers 1 up by 4 goes
1, 2, 3, 0, 1, 2, 3, 0, ...
and the remainder on dividing integers 0 up
by 4 goes
0, 1, 2, 3, 0, 1, 2, 3, ...
from which one solution is 1 + mod(_n - 1, 4).
For sequences 1, 1, 1, 1, 2, 2, 2, 2,
there is a solution
1 + int((_n - 1) / 4)
with some similarity of structure, but
more direct is
ceil(_n / 4)
There is more on -floor()-, -ceil()- and -mod()-
in the series on Tips in the Stata Journal.
> Thanks all, and some clever solutions, too.
> I know that back in the day, Stata had not had such a function, and as
> Nick's original e-mail suggests, someone probably wrote one up --egen
> seq()- for one of us GLIM aficianados!
> As I said previously, I was having the hardest time trying to
> think of a good keyword to search on...
* For searches and help try: