Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Transforming Unique IDs

From   Maarten Buis <>
Subject   Re: st: Transforming Unique IDs
Date   Mon, 23 May 2011 12:35:15 +0200

On Mon, May 23, 2011 at 12:17 PM, Dennis Kramer wrote:
> I am working with a large panel data set and I need to transform the
> current unique IDs into a new set of unique IDs while maintaining the
> panel nature of the data.
> does anyone have a algorithm to produce a new set of unique IDs while
> maintaining the panel function?

I don't think you need to do anything special, just -generate- your new IDs.

A general warning when working with IDs is that if the numbers are
large than it is probably safest to work with strings rather than

*----------- begin example -------------------
// create example data
drop _all
set obs 3
gen id = _n
expand 3
bys id: gen year = _n

// create two new ids
gen newid1 = 10 + id
gen str newid2 = "1" + string(id)


// newid2 is a string, this is much
// safer when working with id's that
// are large numbers
*----------------- end example ----------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index