Statalist


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

Re: st: numbering observations when variables change


From   Johannes Geyer <JGeyer@diw.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: numbering observations when variables change
Date   Tue, 23 Sep 2008 17:50:49 +0200

> -bysort name year: generate id=_N- but it did not work.

the problem is that _N (id) contains the number of observations 
in each combination -name year- which is in general not a good 
identifier.

instead you can use Martin's suggestion - egen ,group() - or you 
generate that index via:

bysort name year: gen id = _n == 1
replace id = sum(id)

Johannes


> 
> Hopefully someone can help me.
> 
> Regards,
> Fabian
> 
> Example:
> "id"       "name"    "year" 
> 1         A            1990
> 1         A            1990
> 2         A            2001
> 3         B            2001
> 4         B            2003
> 5         B            2007
> 5         B            2007 
> 6         C            2007
> 
> -- 
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
> *
> *   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/


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



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