[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: RE: RE: RE: product function
At 06:55 PM 5/25/2004 +0100, Nick Cox wrote:
Indeed, it is not explicitly stated, and it does work that way; Bill Gould
assured me that it is something you can depend on (I'm referring to a
message from Bill Gould to Statalist on Sept 20, 2001).
I don't think it is explicit anywhere in the manual, but
you can assume that -generate- and -replace- follow the
current sort order of the observations.
While we usually think of Stata as operating on the whole dataset at once,
there is an implicit and usually invisible sequential aspect to it. This
is one place where the sequential aspect is significant.
This feature is very useful in propagating a value "down the list", and
especially with -by-.
Suppose p signifies present in a given year, values 0 or 1.
sort personid year
by personid: replace p=1 if p==0 & p[_n-1] & _n>1
will change p so it now signifies present in the current or any prior
year. You could also, more generally, propagate any non-zero value thus:
by personid: replace p=p[_n-1] if p==0 & _n>1
And there are many variations on this theme -- very useful in certain
I hope this is interesting.
Institute for Policy Studies
Johns Hopkins University
* For searches and help try: