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

st: Re: Numbering observations [was: Questions on Stata]


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   st: Re: Numbering observations [was: Questions on Stata]
Date   Mon, 13 Dec 2004 14:29:57 +0100

Please make sure that the subject line is informative; it increases the
chances that someone reads you mail.

Here is a workable solution:

------------------------------------------------
clear
input  var1   var2   var3
  80     30      1
  75     30      1
  85     30      1
  76     33      1
  78     33      1
  75     33      1
  80     29      2
  82     29      2
  83     29      2
end

// You ought to have an id variable from the beginning,
// but assuming that each individual has exactly three
// measurements and that the sorting is right, 
// you can create one (var4).
// I add 2.1 (not 2) to avoid rounding errors:
generate var4=floor((_n+2.1)/3)

// This creates the observation number within id (var4):
bysort var4: gen var5=_n
list
------------------------------------------------

Hope this helps
Svend Juul


__________________________________________

Svend Juul
Institut for Epidemiologi og Socialmedicin
(Dept. Epidemiology and Social Medicine)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [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