Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: creating count within id and date


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: creating count within id and date
Date   Sun, 27 Feb 2005 08:26:16 -0500

. bys id date: g visitno = _n

     +------------------------------------+
     | id    date   var1   var2   visitno |
     |------------------------------------|
  1. |  1   16267      x     53         1 |
  2. |  1   16267      y    106         2 |
  3. |  1   16267      y     84         3 |
  4. |  1   16267      y     90         4 |
  5. |  1   16267      z     76         5 |
  6. |  1   16267      z     65         6 |
  7. |  1   16298      x     87         1 |
  8. |  1   16298      y     76         2 |
  9. |  2   15678      x     98         1 |
 10. |  2   15678      y     98         2 |
 11. |  2   16541      x    150         1 |
     +------------------------------------+

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

On Feb 27, 2005, at 2:33 AM, statalist-digest wrote:

I have the following data structure

id date var1 var2

1 16267 x 53
1 16267 y 106
1 16267 y 84
1 16267 y 90
1 16267 z 76
1 16267 z 65
1 16298 x 87
1 16298 y 76
2 15678 x 98
2 15678 y 98
2 16541 x 150

etc
I wish to create identifier (visitno) 1,2,3,... for each sequential date
within id.
I have tried to use :
sort id date
by id date: gen visitno = [_n] which obviously doesnt produce the
required variable
I would be greatful for solution & ?or direction to FAQ dealing with
this
*
*   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/



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