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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: grouping variable
Date   Thu, 12 Jan 2012 11:32:49 +0000

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/


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