Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Automating calculating durations from beginning and end dates


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Automating calculating durations from beginning and end dates
Date   Tue, 06 Dec 2005 20:55:05 -0500

This is a fairly straightforward job for forval or foreach
forval i=1(1)5 {
gen cdur0`i'=ce0`i'dt-cb0`i'dt+1
}

Michael Blasnik
[email protected]

----- Original Message ----- From: "Clare L Maxwell" <[email protected]>
To: <[email protected]>
Sent: Tuesday, December 06, 2005 8:38 PM
Subject: st: Automating calculating durations from beginning and end dates



Hello to the programmers of Statalist.

I have some beginning and end treatment dates, and I would like to calculate durations of treatment.

beginning date vars: cb01dt cb02dt cb03dt cb04dt cb05dt
ending date vars: ce01dt ce02dt ce03dt ce04dt ce05dt
duration vars: cdur01 cdur02 cdur03 cdur04 cdur05

Some of the data:

id cb01dt cb02dt ce01dt ce02dt
E014 04/21/1997 04/30/1997 04/30/1997 04/30/1997
<snip>

The duration of the 1st treatment, cdur01, for E014 is from 4/21/97 to 4/30/97 = 10 days, for example.

I suspect I should use forvalues 1 to 5 to do all the calculations at once, but I am not sure how to proceed. Would you be able to help with this programming task?

Thank you very much. I have really appreciated your help with previous related problems. I look forward to learning a lot more from this one.

Yours truly,
Clare Maxwell
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index