Saturday, March 18, 2006

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

Use 2 calls to -reshape- ensuring that at each call, the value of the variables is unique within the identifier, or, here, set of identifiers, specified in the i() option :

. li, clean

id dset rec med afev wheeze cough 1. 2 b 1 0 -9 0 0 2. 2 b 2 1 -9 0 0 3. 2 a 1 1 1.7 0 0 4. 2 a 2 0 1.8 0 0 5. 6 b 1 1 -9 0 1 6. 6 b 2 1 -9 0 0 7. 6 a 1 0 2.08 0 1 8. 6 a 2 0 1.85 0 0

. reshape wide med afev wheeze cough, i(id rec) j(dset) string

* note variable dset is a string, hence the string option is specified * note sneaky use of two identifiers whose conjunction _for the subobservation now defined by drec_ yields unique values for med, afev etc

. list, clean

id rec meda afeva wheezea cougha medb afevb wheezeb coughb 1. 2 1 1 1.7 0 0 0 -9 0 0 2. 2 2 0 1.8 0 0 1 -9 0 0 3. 6 1 0 2.08 0 1 1 -9 0 1 4. 6 2 0 1.85 0 0 1 -9 0 0

. reshape wide med* afev* wheeze* cough*, i(id ) j(rec)

. list id med* af* wh*, clean

id meda1 medb1 meda2 medb2 afeva1 afevb1 afeva2 afevb2 wheezea1 wheezeb1 wheezea2 wheezeb2 1. 2 1 0 0 1 1.7 -9 1.8 -9 0 0 0 0 2. 6 0 1 0 1 2.08 -9 1.85 -9 0 0 0 0

(where for clarity I have left out listing some of the variables because of ugly line-wrapping, at least on my screen)

Phil

. At 09:25 PM 16/03/2006 -0800, you 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. > > > > > >Best wishes, >Michael > > >____________________________________ > >Michael McCulloch >Pine Street Clinic >124 Pine Street, San Anselmo, CA 94960-2674 >tel 415.407.1357 >fax 415.485.1065 >email: mm@pinest.org >web: www.pinest.org > www.pinestreetfoundation.org > > > > > >* >* 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/

Philip Ryan Associate Professor, Department of Public Health

Head, Data Management & Analysis Centre Faculty of Health Sciences

postal address: Department of Public Health Mail Drop 511 University of Adelaide 5005 South Australia

location: Level 6 Bice Building Royal Adelaide Hospital North Terrace Adelaide

tel 61 8 8303 3570 fax 61 8 8223 4075 http://www.public-health.adelaide.edu.au/ CRICOS Provider Number 00123M ----------------------------------------------------------- This email message is intended only for the addressee(s) and contains information that may be confidential and/or copyright. If you are not the intended recipient please notify the sender by reply email and immediately delete this email. Use, disclosure or reproduction of this email by anyone other than the intended recipient(s) is strictly prohibited. No representation is made that this email or any attachments are free of viruses. Virus scanning is recommended and is the responsibility of the recipient.

* * 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:


Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?