As flagged by Michael, there are several FAQs
relevant to this kind of manipulation.
How do I create individual identifiers numbered from 1 upwards?
http://www.stata.com/support/faqs/data/group.html
How do I create a variable recording whether any members
of a group (or all members of a group) possess some
characteristic?
http://www.stata.com/support/faqs/data/anyall.html
Nick
[email protected]
Michael Blasnik
> 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<.
Joao Pedro Wagner de Azevedo
> > 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.
> >
*
* 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/