### Friday, March 17, 2006

## Re: st: reshaping problem: unique values in other variables

Michael McCulloch wrote: > I have data with the following structure: > > list id rec med afev wheeze cough date agev > +---------------------------------------------------+ > > | id dset rec med afev wheeze cough | > |---------------------------------------------------| > | 2 b 1 0 -9 0 0 | > | 2 b 2 1 -9 0 0 | > | 2 a 1 1 1.70 0 0 | > | 2 a 2 0 1.80 0 0 | > | 6 b 1 1 -9 0 1 | > | 6 b 2 1 -9 0 0 | > | 6 a 1 0 2.08 0 1 | > | 6 a 2 0 1.85 0 0 | > > +---------------------------------------------------+ > > I wish to reorganize the data so that there is one row for each ID, with > subsets for dset (a or b) and rec (1 or 2) for each of the variables: med, > afev, wheeze, cough. > > My goal is to have: > id med(a1) med(b1) med(a2) med(b2) afev(a1) afev(b1) > afev(a2) afev(b2) > 2 1 0 0 1 1.70 > -9 1.80 -9 > 6 0 1 0 1 2.08 > -9 1.85 -9 > > I have tried using the reshape command but each subset does not have unique > values of the variables afev, wheeze, and cough. > I have tried using the collapse command, but I do not want to create > summary statistics. > I have tried using the contract command, but I do not want to create > frequency counts. > Any assistance would be greatly appreciated.

Do you mean

. egen group = group(dset rec) . reshape wide med afev, i(id) j(group)

Uli

-- kohler@wz-berlin.de +49 (030) 25491-361 * * 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/

Tag: statalist