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

Thanks! Re: st: Re: Automating calculating durations frombeginning and end dates


From   Clare L Maxwell <[email protected]>
To   [email protected]
Subject   Thanks! Re: st: Re: Automating calculating durations frombeginning and end dates
Date   Wed, 7 Dec 2005 00:31:43 -0600

Dear Michael,

Thanks!  I am very happy to have this solution.

At 8:55 PM -0500 12/6/05, Michael Blasnik wrote:
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
}
I just got around to implementing Nick Cox's solution to mass producing dates from components this evening. It is the first time I have put together var names from components. I was about to write that I had found a solution along the foreach lines when your letter came. This also works:

* ce stands for common elements
* e stands for element
local ce "01 02 03 04 05"
foreach e of local ce {
gen int cdur`e' = ce`e'dt - cb`e'dt + 1
}

The trick is looking for the common elements in the var names, then using them either as numbers with forval or as a text list with foreach.

I feel sheepish for having troubled you, but I still thank you a lot. Your forvals solution is more compact and is the one I am going to use. I would have had a lot of trouble getting it right without an example.

Yours truly,
Clare
*
* 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