[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

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:

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

**References**:**st: RE: RE: RE: product function***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: Re: STATA Help!! How to test for PPP!!** - Next by Date:
**st: Spurious regression problem** - Previous by thread:
**st: RE: RE: RE: product function** - Next by thread:
**st: t-test command for simple cross-tabs** - Index(es):

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