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

Re: st: RE: macro variables


From   Cameron Hooper <[email protected]>
To   [email protected]
Subject   Re: st: RE: macro variables
Date   Wed, 29 Dec 2004 00:15:12 -0500

Thanks. Missed the forest for the trees!

Reardon, Sean F. wrote:
i don't think you need macros here. try something like this:

generate fyed = mdy(12,31,year) if fyr==12
replace fyed = mdy(fyr+1,1,year) - 1 if fyr <12
replace fyed = mdy(fyr+1,1,year-1) - 1 if fyr <5

_____________________________
sean f. reardon
associate professor of education and (by courtesy) sociology
school of education
485 lasuen mall, #315
stanford university
stanford, ca 94305-3096
650.736.8517 (office phone)
650.725.7412 (office fax)
[email protected]
_____________________________
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Cameron
Hooper
Sent: Tuesday, December 28, 2004 3:06 PM
To: [email protected]
Subject: st: macro variables

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/


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


--
Cameron Hooper <[email protected]>
University of Michigan Business School
701 Tappan St., Ann Arbor, MI 48109
phone: 734-615-4178 fax: 734-936-0282
Public Key: http://wwwkeys.pgp.net:11371/pks/lookup?op=index&search=0xFCCF8C91
*
* 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