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: grouping variable


From   Lars Folkestad <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: grouping variable
Date   Thu, 12 Jan 2012 12:45:20 +0100

Thank you Nick for your answer.

My id is the social security number of each individual. For making the
data easier to read here in the initial phase of my work
I would like to have the data like this:

ID sex admission date (admission1) hospital (admission1) department
(admission1) ... Department (admissionN)

Instead of the way data is now:
Id sex admission date hospital department
1   1   DDMMYY		1	1
1   1	DDMMYY          1       2

And so forth.

Your code (as always) did the trick.

lars

		

Den 12/01/12 12.32 skrev "Nick Cox" <[email protected]>:

>There is no rule that -i()- must specify a single variable. In your
>case however you probably want a new sequence variable
>
>bysort id (date_admission) : gen seq = _n
>
>and then to -reshape- using -i(id seq)- (not -i(id)-). Getting
>admissions on the same day in the right order sounds tricky unless you
>also have a time-of-day variable.
>
>That said, this kind of -reshape- usually makes later analysis more
>difficult, so exactly why you think it will help you is an open
>question.
>
>Nick
>
>On Thu, Jan 12, 2012 at 11:19 AM, Lars Folkestad
><[email protected]> wrote:
>
>> After searching the web i will have to ask you - co-listers.
>>
>> I have a dataset of patients and admissions.
>>
>> Id sex hospital ward date_admission date_discharge
>>
>>
>> Data is in long format and i would like it to be reshaped to wide
>>format.
>> Some participants have up to 150 different admissions.
>>
>> My problem is that i dont have a unique grouping variable available
>>(some
>> patients have been admitted to the same wards twice or more on the same
>> day)
>>
>> I would like to do the following
>>
>> Sort by id
>> Genereate a grouping variable 1-_n for each id
>> Reshape the lot to wide using i(id) j(groupvar)
>>
>> But i cannot se how to to this.
>>
>> Any other ways do reshape?
>*
>*   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/


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