Statalist


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

Re: st: numbering observations when variables change


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: numbering observations when variables change
Date   Tue, 23 Sep 2008 12:34:42 -0500

What you wrote gives the number of observations for each combination of variables. You want

. egen id = group(name year)

Nick
[email protected]

Fabian Brenner wrote:


I want to use variable "id" to number observations. Whenever "name" or "year" changes, "id" should increase by 1. I have sorted the data by name and year (-sort name year-). I tried to solve the problem by -bysort name year: generate id=_N- but it did not work.

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

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index