Bookmark and Share

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


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

Re: st: long to wide conversion


From   Ada Ma <[email protected]>
To   [email protected]
Subject   Re: st: long to wide conversion
Date   Thu, 7 Oct 2010 13:36:26 +0100

Ooops sorry correction:
sort id collect_date order_type, stable
by id collect_date order_type: gen seq=_n
reshape drug_code drug_result, i(id collect_date order_type) j(seq)

David Cox's solution might be more sensible, depending on what you wanted to do.


On Thu, Oct 7, 2010 at 1:33 PM, Ada Ma <[email protected]> wrote:
> This should work:
>
> sort id collect_date order_type, stable
> by id collect_date order_type: gen seq=_n
> reshape drug_code     drug_result, i(id collect_date order_type) j(seq)
>
>
> On Thu, Oct 7, 2010 at 11:53 AM, King, Carina <[email protected]> wrote:
>> Hi,
>>
>> I have a data set in long form and i want to convert it to wide. I have tried the 'reshape' command (using various combinations of variables) but it won't work. The problem is, there aren't any unique j values for the i's.
>>
>> The variables I want to be sorted on are the id, collect_date and order_type. The for it to read across for drug_code and drug_result (They are all string variables). Below as an example of how my data is set up.
>>
>> Id       collect_date     order_type        drug_code     drug_result
>>
>> 34       03aug2010        CFS                   Amp            SS
>> 34       03aug2010        CFS                   Oxy            0.1-SS
>> 34       10aug2010        CFS                   Methc          R
>> 57       05mar2008        Urine                 Amox           R
>> 57       05mar2008        Urine                 Amik           0.001-SS-HIDE
>> 87       07sep2009        Blood                 Oxy            HIDE
>> 62       12oct2007         Urine                Vanc           0.063-SS
>> 62       12oct2007         Urine                Methc          0.063-SS
>> 62       12oct2007         Urine                Vanc           R-HIDE
>> 62       12oct2007         Blood                Amp            SS
>>
>> Any suggestions? Thanks!
>>
>> Carina
>>
>>
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
> --
> Ada Ma
> Research Fellow
> Health Economics Research Unit
> University of Aberdeen, UK.
> http://www.abdn.ac.uk/heru/
> Tel: +44 (0) 1224 555189
> Fax: +44 (0) 1224 550926
>



-- 
Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 555189
Fax: +44 (0) 1224 550926

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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