Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: RESHAPE HELP


From   "Zhiqiang Wang" <[email protected]>
To   <[email protected]>
Subject   st: Re: RESHAPE HELP
Date   Thu, 17 Oct 2002 10:47:50 +0930

Beth
You may need to provide more information on why you wanted a wide format.
SAVE your data before trying the following:

1. If you are not interested in gcount on particular edate.
In the example you gave, I added hypothetic gcount variable
           id      edate    gcount
  1.       45  26jun1994        12
  2.       45  26jun1994        23
  3.       52  21jun1994        34
  4.       52  21jun1994        45

. egen j=seq, by(id)
. reshape gcount edate, i(id) j(j)
This will give:
           id     edate1   gcount1     edate2   gcount2
  1.       45  26jun1994        12  26jun1994        23
  2.       52  21jun1994        34  21jun1994        45

2. if possible, combine same date into one observation. For example if
gcount were the sum of event numbers,
. collapse (sum) gcount, by(id edate)
. reshape gcount, i(id) j(edate)
           id  gc~12590  gc~12595
  1.       45         .        35
  2.       52        79         .

Any way, it depends on your data structure and what analysis you want to do
with the wide format.

Zhiqiang
Menzies School of Health Research
Darwin Australia



----- Original Message -----
From: <[email protected]>
To: <[email protected]>
Sent: Thursday, October 17, 2002 8:13 AM
Subject: st: RESHAPE HELP


> Hi.  I am a new STATA user that is working on a secondary analysis for my
> dissertation research. I am trying to reconfigure a file that was set up
with
> multiple record cases.  For example, a particular id# may be contained in
> this file numerous on the following variables: event # (gcount) and edate
> (month, day, year of the event). I am trying to convert the data from long
> form to wide form so that each id# is only represented in this file once
and
> have run into some difficulty with the RESHAPE command. I know based upon
> what I have read in the Reference manual and the FAQ reshape information
that
> I must need to create some additional variables because the j(edate
variable)
> is not unique for each id #. Let me explain that the reason the edates are
> not unique is because an individual may have experienced mutiple events,
such
> as a fall, on any given date.  I wondered if anyone might be able to point
me
> in the right direction for how I should proceed with creating additional
> variables? I have included a condensed version of my syntax and output
below.
>
> Thanks in advance for your help,
> Beth
>
> . reshape wide gcount, i(id) j(edate)
> (note: j = 11928 11946 11956 11959.............)
> edate not unique within id;
> there are multiple observations at the same edate within id.
> Type "reshape error" for a listing of the problem observations.
> r(9);
>
> reshape error
>
> i (id) indicates the top-level grouping such as subject id.
> j (edate) indicates the subgrouping such as time.
> The data are in the long form;  j should be unique within i.
>
> There are multiple observations on the same edate within id.
>
> The following 253 out of 3741 observations have repeated edate values:
>
>              id       edate
>   75.        45  06/26/1994
>   76.        45  06/26/1994
>   92.        52  06/21/1994
>   93.        52  06/21/1994
>
> (data now sorted by id edate)
> *
> *   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/
>

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