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 on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: difference between rows


From   "Dougie Elder" <d.elder@dundee.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Chris Parker
Sent: 20 May 2011 23:20
To: statalist@hsphsun2.harvard.edu
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 <d.elder@dundee.ac.uk> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index