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   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: reshaping problem: unique values in other variables
Date   Fri, 17 Mar 2006 09:39:15 +0100

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

-- 
[email protected]
+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/



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