clear
input id year
        4   1987
	  4   1993
        4   1994
        9   1986
        9   1987
        9   1988
        9   1989
        9   1990
        9   1992
        9   1993
        9   1994
        9   1995
        9   1996
        9   1997
end
bysort id (year): gen tag = 1 if _n ==1
bysort id (year): replace tag = 1 if  mod(year, 3) ==1 & tag == . &
tag[_n-1] != 1
keep if tag ==1
drop tag
l, sepby(id)
gives me
    id   year  
     4   1987  
     9   1986  
     9   1990  
     9   1993  
     9   1996  
It dosent keep the year 1993 for id  4
Thanks
rajesh
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scott Merryman
Sent: 19 May 2008 02:50
To: [email protected]
Subject: Re: st: keeping dates which are n periods apart
Does this work?
clear
input id year
        4   1987
        4   1988
        4   1989
        4   1990
        4   1992
        4   1993
        4   1994
        9   1986
        9   1987
        9   1988
        9   1989
        9   1990
        9   1992
        9   1993
        9   1994
        9   1995
        9   1996
        9   1997
end
bysort id (year): gen tag = 1 if _n ==1
bysort id (year): replace tag = 1 if  mod(year, 3) ==1 & tag == . &
tag[_n-1] != 1
keep if tag ==1
drop tag
l, sepby(id)
Scott
On Sun, May 18, 2008 at 8:02 PM, Rajesh Tharyan <[email protected]>
wrote:
> Hi all,
>
> I have this ( a subset of the original dataset, the original dataset has
> about 6000 ids with an  average of 6 years each)
>
>    id   year
>     4   1987
>     4   1988
>     4   1989
>     4   1990
>     4   1992
>     4   1993
>     4   1994
>     9   1987
>     9   1988
>     9   1989
>     9   1990
>     9   1992
>     9   1993
>     9   1994
>
> I need to keep years if they are more than 2 years apart by company.
*
*   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/
*
*   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/