Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Generating a unique ID


From   "Friedrich Huebler" <[email protected]>
To   [email protected]
Subject   Re: st: Generating a unique ID
Date   Wed, 21 Nov 2007 18:49:49 -0500

Mansour,

You can use -egen group- if you only want a unique ID that does not
necessarily contain information on the underlying data.

. egen id = group(state year age sex residence)

Missing data in any of the five variables will result in a missing
value for the ID. Another option, closer to what you suggested, is to
concatenate the identifying variables.

. gen id = string(state) + " " + string(year) + " " + string(age) + "
" + string(sex) + " " + string(residence)

Friedrich

On Nov 21, 2007 6:22 PM, Mansour Farahani <[email protected]> wrote:
> Dear Statalisters:
>  I have a unbalanced dataset where variables of interest, categorized by age and place of residence (urban rural) in 15 age groups, are observed in 15 states, over 33 years. For example, mortality rate for rural boys age 10-15 in state i at time t. some of categories in certain years and states are (randomly?) missing.
>
> I want to create a unique ID number based on state (1 to 15), year (1 to 33), age (1 to 15), sex (1,2),and  place of residence (1,2), so that I have a UNIQUE ID for every row in the data. One possible format is that the ID have a max of 8 digits, xx xx xx x x such that first 2 digits are state (00 to 15) then year and so on.
>
> I appreciate any idea on how I can do it in Stata.
>
> Many thanks,
>
> Mansour
*
*   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