Stata: Create id by group

Sunday, April 22, 2012

When doing your data analysis, sometimes you will encounter the following situation: in your dataset, everyone has an unique id. However, their IDs are long and each participant has multiple record (or the dataset is in a long format).

To visualize your data, you need to create a new ID for each individual regardless of how many records each person has. For example, the first person has three records, and we would like to assign a new ID 1 for the first person, and the second person would be 2.

Though it sounds difficult and tedious, it is not difficult to do so.  

egen id = group(oldid)

Just one line and your problem will be solved.

Related Posts Plugin for WordPress, Blogger...


One response to “Stata: Create id by group”
Post a Comment | Post Comments (Atom)

Ben said...

How about creating a new id using your old id and three alternatives? So if I have 3 options (1,2,3), and three alternatives that ( R (6,4,2), A(10,4,2), and G(High,Med,Low)). I want to create newid 111111111.

Thank You,

November 15, 2013 at 3:01 AM

Post a Comment