Reputation: 31
I have a Stata data set like this:
HouseholdId PersonId OtherVariables
1 1
1 2
2 1
2 2
3 1
3 2
Here HouseholdId
is a unique identifier for each household and PersonId
is a unique identifier for each person in a household. If I want to create a unique personal id for each person within the sample, period. How would I do this?
I have tried egen per_id = group(PersonID HouseholdID)
but that doesn't seem to work.
Upvotes: 1
Views: 234
Reputation: 37208
I take it that you want a unique identifier for each person within the entire dataset. That could be just
sort HouseholdId PersonId
gen long obs Id = _n
as follows from an accessible discussion in this Stata FAQ. That would have been found by typing in Stata
search identifier
or even
search id
(Meta-answer: You can and should look within Stata for information on basic notions like this.)
I add a strong recommendation that the word unique still carries its original meaning of appearing once only. The word distinct is, I suggest, a much better word when that is what you mean. More on that on p.558 of this paper.
Upvotes: 1