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

st: macro variables


From   Cameron Hooper <[email protected]>
To   [email protected]
Subject   st: macro variables
Date   Tue, 28 Dec 2004 18:06:23 -0500

I have a question about macro variables. I want to code the following as a loop:

// Create fiscal year end date
generate fyed = mdy(12,31,year)
replace fyed = mdy(2,1,year-1) - 1 if fyr == 1
replace fyed = mdy(3,1,year-1) - 1 if fyr == 2
replace fyed = mdy(4,1,year-1) - 1 if fyr == 3
replace fyed = mdy(5,1,year-1) - 1 if fyr == 4
replace fyed = mdy(6,1,year) - 1 if fyr == 5
replace fyed = mdy(7,1,year) - 1 if fyr == 6
replace fyed = mdy(8,1,year) - 1 if fyr == 7
replace fyed = mdy(9,1,year) - 1 if fyr == 8
replace fyed = mdy(10,1,year) - 1 if fyr == 9
replace fyed = mdy(11,1,year) - 1 if fyr == 10
replace fyed = mdy(12,1,year) - 1 if fyr == 11

year and fyr are variables in my dataset. I tried the following (and a number of other things):

generate fyed = mdy(12,31,year)
forvalues i = 1/11 {
if `i' <= 5 local yy = year - 1
else local yy = year
replace fyed = mdy(`i'+1,1,`yy') - 1 if fyr == `i'
}

This does not work. The macro variable yy is not accessing each observation's value on year. Clearly I'm not going about this correctly. Any suggestions? Thanks.

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