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

st: Re: help creating a unique identifier


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: help creating a unique identifier
Date   Thu, 17 Mar 2005 12:19:13 -0500

A similar question was recently asked and FAQ certainly addresses the unique identifier, but here are some answers:

egen SeqId=group(id_dom)

or

sort id_dom age
gen SeqId=sum(id_dom!=id_dom[_n-1])

for your second question, if there are no missing values on age, then this works:

bysort id_dom (age): gen byte hasover15=age[_N]>=15

otherwise, the easiest approach may be:

egen maxage=max(age),by(id_dom)
gen byte hasover15=maxage>15 if maxage<.


There is no need for collapse or merge and I can't see any reason why you would think so.

Michael Blasnik
[email protected]

----- Original Message ----- From: "Joao Pedro Wagner de Azevedo" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 17, 2005 11:42 AM
Subject: st: help creating a unique identifier



Hello,

I have a dataset with the variable id_dom (numeric) which s a unique
identifier of households and the variable age (see extract below). I would
like to create a couple of new variable and I would sincerely appreciate if
anyone on the list give me a hand.

First, I would like to create a sequential unique identifier such as
variable SeqID. Second, I would like to create a variable which would flag
all those households with at least on adult (age>=15).

Initially I would like to avoid having to use collapse and merge (given the
size of my dataset), and I have been trying to use command such as bysort,
_n and _N.

Any help will be much appreciated.

Cheers,

JP


id_dom age SeqID
9211001200001 5 1
9211001200001 10 1
9211001200001 15 1
9211001200001 20 1
9211001200001 25 1
9211001200002 5 2
9211001200002 10 2
9211001200002 15 2
9211001200002 20 2
9211001200002 25 2
9211001200003 4 3
9211001200003 8 3
9211001200003 12 3
9211001200003 16 3
9211002100002 3 4
9211002100002 6 4
9211002100002 9 4
9211002500004 7 5
9211002500004 14 5
9211002500004 21 5
9211002500004 28 5
9211002500004 35 5
9211002500004 42 5
9211002500004 49 5
*
*   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