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

Re: st: Forvalues with Dates


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Forvalues with Dates
Date   Fri, 21 Oct 2005 12:14:04 +0200

Eric wrote:

I have found forvalues to be a huge help & have done things like

forvalues y=1997(1)1999 {
forvalues m = 1(1)12 {
replace amount_`y'_`m' = .....
}
}

But my problem is that I actually have to process the last couple months
of 1996 and the first few months of 2000 as well. So it didn't seem like
I could handle this within the forvalues block & therefore have to treat
those months separately outside these loops. Is there a way to go
through say November 1996 through April 2000 with two forvalues loops?
------------------

You may use -continue- to skip the remaining commands in the current
iteration:

clear
set obs 10
forvalues y=1996(1)2000 {
    forvalues m = 1(1)12 {
       if `y'==1996 & `m'<11 continue
       if `y'==2000 & `m'>4 continue
    generate amount_`y'_`m' = 12*`y' + `m'   // just to do something
    }
}

There may also be some time series procedures relevant to this type of
problems.

Svend
__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________

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