Friedrich,
Thank you very much for your help. The point is that in my dataset the missing values are not coded as missing, instead the whole row is not there.
state year age sex residence
1 1970 1 1 2
1 1970 1 2 1
1 1970 1 2 2
1 1970 2 2 1
1 1970 2 2 2
1 1970 3 1 1
1 1970 3 2 1
1 1970 3 2 2
As you can see in the above, age 1 sex 1 and residence 1 is missing but it is not explicitly coded in the dataset. as a result, when I use egen group( ) I have a continuous set of numbers for ID ( with no jump when a record is missing).
thanks again,
Mansour
>>> "Friedrich Huebler" <[email protected]> 11/21/07 6:49 PM >>>
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/
*
* 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/