Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: grouping variable

From   Lars Folkestad <>
To   "" <>
Subject   st: grouping variable
Date   Thu, 12 Jan 2012 12:19:41 +0100

Dear List

After searching the web i will have to ask you - co-listers.

I have a dataset of patients and admissions.

Id sex hospital ward date_admission date_discharge

Data is in long format and i would like it to be reshaped to wide format.
Some participants have up to 150 different admissions.

My problem is that i dont have a unique grouping variable available (some
patients have been admitted to the same wards twice or more on the same

I would like to do the following

Sort by id
Genereate a grouping variable 1-_n for each id
Reshape the lot to wide using i(id) j(groupvar)

But i cannot se how to to this.

Any other ways do reshape?


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index