Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Creating id number by subgroup


From   "Mike Kim" <[email protected]>
To   <[email protected]>
Subject   st: Creating id number by subgroup
Date   Tue, 6 Jan 2009 12:05:48 -0600

Dear statalisters,

I would like to create 'var1' in the following table based on id and title.
I tried "bysort id title: gen var2=_n" and this creates var2 which is different from var1.
I also tried "by id: egen var1=group(title)", but egen does not allow 'by'.
How can I create var1?

id  title  var1  var2
1    A      1    1
1    A      1    2
1    B      2    1
1    B      2    2
1    B      2    3
2    C      1    1
2    C      1    2
2    C      1    3
2    D      2    1
2    D      2    2
3    E      1    1
.......

Thank you in advance.
Mike.

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