Here is another way:
clear
input id begin end cens
1 1997 2006 0
2 1997 2003 0
3 1997 2004 0
3 2004 2007 0
4 1997 2006 0
end
bys id: gen foo = cond(_n == _N,2,1)
expand foo
bys id (begin): replace begin = end[_n-1] if _n >1
by id: replace end = cond(_n==1, . , begin)
by id:replace cens = 1 if _n == _N
drop foo
l, sepby(id)
Scott
On Wed, Oct 28, 2009 at 6:50 AM, Martin Weiss <[email protected]> wrote:
>
> <>
>
>
>
> *************
> clear*
>
> input byte(id ) begin end cens
> 1 1997 2006 0
> 2 1997 2003 0
> 3 1997 2004 0
> 3 2004 2007 0
> 4 1997 2006 0
> end
>
> compress
> list, noobs sepby(id)
> tempfile temp
> save `temp', replace
>
> collapse (last) end, by(id)
> rename end begin
> gen end=.
> gen cens=1
>
> append using `temp'
>
> order id begin end cens
> sort id begin
> list, noobs sepby(id)
> *************
>
>
>
> HTH
> Martin
>
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/