Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Need help sorting values


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Need help sorting values
Date   Mon, 18 Feb 2013 01:27:47 +0000

Thanks, but the logic is not that spectacular.

You want to -sort- "h&p" to the beginning of a block of observations,
"end" to the end and everything else in between. For that a variable
that is lowest on "h&p", highest on "end" and in between for other
values is necessary and 0,1,2 as values is one of many solutions.

Nick

On Sun, Feb 17, 2013 at 11:25 PM, Michael Stewart
<michaelstewartresearch@gmail.com> wrote:
> HI Nick,
> It works.
> I tried hard and finally understood your code .
> I have to say that was simply brilliant
> Thanks a lot again
> Sincerely
> Mike
>
> On Sun, Feb 17, 2013 at 11:17 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>> gen what = cond(report == "h&p", 0, cond(report == "end", 2, 1))
>>
>> bysort patient (date what) :
>>
>> If your variable -report- is numeric with value labels, there will be
>> a similar but not identical solution.
>>
>> Nick
>>
>> On Sun, Feb 17, 2013 at 3:32 PM, Michael Stewart
>> <michaelstewartresearch@gmail.com> wrote:
>>
>>> I have data for different as follows
>>>
>>> pateint   date          report
>>> 111     2/15/2012       ed
>>> 111     2/15/2012       ed
>>> 111     2/15/2012       h&p
>>> 111     2/15/2012       d/c
>>> 111     2/15/2012       ed
>>> 111     2/15/2012       con
>>> 111     1/23/2012       con
>>> 111     1/23/2012       d/c
>>> 111     1/23/2012       ed
>>> 111     1/23/2012       con
>>> 111     1/23/2012       h&p
>>> 222   1/20/2012  ed
>>> 222    1/20/2012  h&p
>>> 222  1/20/2012   con
>>>
>>> My need is to sort the report variable for a particular date within a
>>> patient so that the h&p is the first value and ed is the last value
>>> i.e h&p is report[1] and ed is report[_N]
>>>
>>>
>>> something like bysort patient date: _ _ _ _ _
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index