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

Re: st: Counting and eliminating repeated rows from data set


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Counting and eliminating repeated rows from data set
Date   Mon, 25 Jul 2005 22:16:12 +0200

Jose wrote:
---------------------------------------------------------
Suppose I had data like this:
x1  x2  x3  x4 x5  d
19   8  20   0  1 10
80   5  23   1  0 12
80   5  23   1  0  0
80   5  23   1  0  0
81   2  21   1  1 50
82   4  19   0  0  5
82   4  19   0  0  0
87   6  29   0  1  5
...
 
I want to reshape the data set, eliminating repeated rows 
and creating a new variable (nd) that counts the repeated 
rows (e.g. rows 2-4 and rows 6-7, above) so it looks like 
this:
 
x1  x2  x3  x4 x5  d  nd
19   8  20   0  1 10   1
80   5  23   1  1 12   3
81   2  21   1  1 50   1
82   4  19   0  0  5   2
87   6  29   0  1  5   1

---------------------------------------------------------
 
You present the problem clearly, except that it is not 
obvious how -d- should be handled. If -d- was not included,
the easiest thing would be:
  . contract x1-x5
 
Assuming that -d- should be replaced by the sum for each 
collapsed group you could:
  . generate nd=1
  . collapse (sum) d nd , by(x1-x5)
 
Good luck,
Svend
 
________________________________________________________ 
 
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6 
DK-8000 Aarhus C,  Denmark 
Phone, work:  +45 8942 6090 
Phone, home:  +45 8693 7796 
Fax:          +45 8613 1580 
E-mail:       [email protected] 
_________________________________________________________ 

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