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: Query regarding changing dates and events


From   Maul Eugenio <[email protected]>
To   [email protected]
Subject   Re: st: Query regarding changing dates and events
Date   Wed, 7 Apr 2010 13:24:52 -0400

Ricardo, I am not an elegant stata user but my approach would be the
following:
Assuming that:
- database 1 (data1.dta) has ptid, datein dateout and database2 (data2.dta)
has ptid, datehosp, dosex
- You already have a summary measure with one dose per date
- The id variable is called the same in both databases

use data1.dta, clear
merge 1:m ptid, using data2.dta
//Thi command should only be executed if patients have doses outside of the
hospitalization dates that you want to exclude
drop if datehosp<datein | datehosp>dateout
// COntinuing
by ptid, sort: gen temp1=3Dsum(dosex)
byptid, sort:egen total_dosex=3D max(temp1)
drop temp1

// Then if you want to keep only the summary measure for each patient, and
drop the rest of the data
by ptid,sort: keep if _n=3D=3D1
drop datehosp dosex


Greetings,
Are we colleagues in Chile?

Eugenio Maul

On Apr 7, 2010, at 9:40 AM, Ricardo Castro wrote:

> Hi to all:
> 
> I need assistance with the following query regarding dates:
> 
> I have a hospital dataset with 3 columns: patient id (patid),
> admission date (admit) and discharge date (disch). In another dataset
> I have a variable varr with a numerical value (like a dose of a drug)
> that is recorded for every day (of course its value is different for
> every day).
> 
> What I need is to assign for every patient the total amount of varr
> according to the specific days he/she was hospitalized, to finally sum
> them up and obtain a total dose of varr for every patient during
> his/her hospitalization.
> 
> Before doing that, I think I need to have one row for every day of
> hospitalization, to combine with the varr database. I have tried with
> the expand command but it clones the dates and does not generate
> sequentially a number of rows according to the number of
> hospitalization days (keeping the same patid).
> 
> Example:
> 
> Patid    admit     disch
> 
> 1001     05jan2010 10jan2010
> 
> I need…
> 
> 
> 
> Patid    admit     disch       day
> 
> 1001     05jan2010 10jan2010   05jan2010
> 
> 1001     05jan2010 10jan2010   06jan2010
> 
> 1001     05jan2010 10jan2010   07jan2010
> 
> 1001     05jan2010 10jan2010   08jan2010
> 
> 1001     05jan2010 10jan2010   09jan2010
> 
> 1001     05jan2010 10jan2010   10jan2010
> 
> 
> 
> After that I need to attribute the varr value to every date day for
> every patient.
> 
> 
> 
> Can you help me with this? or if is there a more elegant way of doing
> what I need, I will greatly appreciate that information.
> 
> Many thanks
> 
> Ricardo
> 
> *
> *   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