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

st: AW: create unique variables


From   Buechte, Sebastian (Institut f�r Arbeitswissenscha ften) <[email protected]>
To   <[email protected]>
Subject   st: AW: create unique variables
Date   Fri, 4 Feb 2005 10:44:43 +0100

Paolo,

you might want to try this:

bysort lastname firstname dateofbirth: gen id=_n if _n==1
replace id=sum(id)

What happens to the dataset ->

1st step
Obs firstname lastname dateofbirth id
 1      A        B      1.1.1980    1
 2      A        B      1.1.1980    .
 3      A        B      1.1.1980    .
 4      A        B      1.1.1980    .
 5      B        C      2.2.1990    1
 6      B        C      2.2.1990    .
 7      B        C      2.2.1990    .
 8      D        E      3.3.2000    1
 9      D        E      3.3.2000    .

2nd step
Obs firstname lastname dateofbirth id
 1      A        B      1.1.1980    1
 2      A        B      1.1.1980    1
 3      A        B      1.1.1980    1
 4      A        B      1.1.1980    1
 5      B        C      2.2.1990    2
 6      B        C      2.2.1990    2
 7      B        C      2.2.1990    2
 8      D        E      3.3.2000    3
 9      D        E      3.3.2000    3


(I learnt this way from the following book, which unfortunately available only in German:
	Kohler U: Datenanalyse mit Stata. M�nchen, Wien. Oldenbourg 2001)


Kind regards,
sebastian



> -----Urspr�ngliche Nachricht-----
> Von: [email protected] 
> [mailto:[email protected]] Im Auftrag von 
> Paolo Grillo, MD
> Gesendet: Freitag, 4. Februar 2005 10:13
> An: [email protected]
> Betreff: st: create unique variables
> 
> 
> I have a dataset with the following variables:
> 
> last name
> first name
> date of birth
> 
> Since this dataset contains more than one record for 
> individual, I would 
> create a  unique variable for subject (ID).
> Could anyone help me in this problem?
> Thank in advance
> 
> -- 
> 
> 
> 
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
> 
> Paolo Grillo MD
> Nephrologist 
> Statisticians
> EPOCA Research Center for Occupational, Clinical & 
> Environmental Epidemiology Department of Occupational and 
> Environmental Health "Clinica L. Devoto" University of Milan 
> Via San Barnaba 8 20122 Milano - ITALY
> Tel: +39 02 503-20148
> Fax: +39 02 503-20126
> 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/
> 

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