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

st: forvalues with dates


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: forvalues with dates
Date   Fri, 21 Oct 2005 07:32:03 -0400

.
. webuse wpi1,clear

. su t if tin(1979q3,1987q1)

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
           t |        31          93    9.092121         78        108

. local lo=r(min)

. local hi=r(max)

. forv i=`lo'/`hi' {
  2. local yy=year(dofq(`i'))
  3. local qq=quarter(dofq(`i'))
  4. di "`i'  `yy'  `qq'"
  5. }
78  1979  3
79  1979  4
80  1980  1
81  1980  2
82  1980  3
83  1980  4
84  1981  1
85  1981  2
86  1981  3
87  1981  4
88  1982  1
89  1982  2
90  1982  3
91  1982  4
92  1983  1
93  1983  2
94  1983  3
95  1983  4
96  1984  1
97  1984  2
98  1984  3
99  1984  4
100  1985  1
101  1985  2
102  1985  3
103  1985  4
104  1986  1
105  1986  2
106  1986  3
107  1986  4
108  1987  1


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html


On Oct 21, 2005, at 2:33 AM, Erikwrote:

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