Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

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


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: reshaping problem: unique values in other variables
Date   Fri, 17 Mar 2006 09:00:00 +0100

Michael 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. ...
---------------------------------------------------------------

A way to do it us to create one -rec- variable from -dset- and -rec-,
and next drop -dset-:

   replace rec=rec+10 if dset=="a"
   replace rec=rec+20 if dset=="b"
   drop dset
   reshape wide med-cough , i(id) j(rec)

Hope this helps
Svend

________________________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C,  Denmark
Phone, work:  +45 8942 6090
Phone, home:  +45 8693 7796
Fax:          +45 8613 1580
E-mail:       [email protected]
_________________________________________________________

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index