Statalist The Stata Listserver

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

Re: st: First occurence

From   "Austin Nichols" <>
Subject   Re: st: First occurence
Date   Thu, 17 May 2007 09:37:22 -0400

Meryle Weinstein --
It's always advisable to frame your question in terms of data everyone
can use, e.g. by starting your example with -sysuse auto- and showing
the result you want.  That said, one way (among many) to generate an
indicator for first year is:

egen minyr=min(year), by(bdsmaster)
gen fyr=(year==fyr)

On 5/17/07, Meryle Weinstein <> wrote:
I've tried following the syntax in FAQ and archives but am having difficulty
with it.  I have a dataset that has an idcode and a year for a number of
schools.  I want to identify the first year that the idcode appears.  I've
tried the following but still don't' get the first occurrence.

by bdsmaster (year), sort: gen noccur = sum(bdsmaster)
by bdsmaster: gen byte first = noccur == 1  & noccur[_n - 1] != noccur

gen byte first = sum(bdsmaster == 1) == 1  & sum(bdsmaster[_n - 1] == 1) ==

*   For searches and help try:

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