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: difference between rows


From   "Dougie Elder" <[email protected]>
To   <[email protected]>
Subject   RE: st: difference between rows
Date   Mon, 23 May 2011 13:52:46 +0100

Great - thanks Chris ... it seems obvious now !


Cheers

Dougie

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Chris Parker
Sent: 20 May 2011 23:20
To: [email protected]
Subject: Re: st: difference between rows

Doug,

Try this:

bysort id: start_date - start_date[_n-1] - date[_n-1]

Chris

On Fri, May 20, 2011 at 11:10 PM, Dougie Elder <[email protected]> wrote:
>
> Apologies if this is quite basic, but I've searched everywhere and I 
> cant find the answer !
>
> I have a pile of drug prescription data.
>
> Each patient has several rows of prescriptions e.g.
>
> Id       start_date    days  missed days
> Pt1   10/12/08          21
> Pt1  10/01/09          38
> Pt1  14/03/09          36
> Pt1  15/04/10          36
> Pt2  02/05/09          90
> Pt2  03/06/10          32
>
> I need to calculate the no of days where no drug was available in each 
> row of data i.e calculate the difference between 10/12/08 and 10/01/09 
> and place the result of ((10/01/09 - 10/12/08)-21 ) at the end of row 
> 1
>
> Obviously only for each pt
>
>
> Dougie
>
>
>
>
>
> *
> *   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/
>
> ______________________________________________________________________
>
> This email has been scanned by the MessageLabs Email Security System 
> on behalf of the London Business School community.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________

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