Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: RE: product function


From   David Kantor <dkantor@jhu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: RE: product function
Date   Tue, 25 May 2004 15:03:13 -0400

At 06:55 PM 5/25/2004 +0100, Nick Cox wrote:
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.
[...]
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).

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 situations.

I hope this is interesting.
-- David

David Kantor
Institute for Policy Studies
Johns Hopkins University
dkantor@jhu.edu
410-516-5404

*
* 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