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

Re: st: Lots of date vars from month, day, year vars-FU qx forEric Wruck


From   Clare L Maxwell <maxwellcl1@earthlink.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Lots of date vars from month, day, year vars-FU qx forEric Wruck
Date   Sat, 12 Nov 2005 13:35:20 -0600

Hello, Eric.  Thank you very much for thinking about this.

At 2:02 PM -0500 11/12/05, Eric G. Wruck wrote:
I'm not sure I fully understand what you're looking to do (more detail would increase the likelihood that someone will be able to help you). Nevertheless, you may be interested in Stata's mdy() function.
Yes, the mdy() function is what I can use on three variables at a time. The problem is that I have as many as 50 triplets of m, d, y that I would like to feed into some kind of automated routine to create 50 corresponding date vars. Calculation of dates is the simplest problem of this structure to describe, but there are others less trivial, and that is what is really holding me up.


Eric

p.s. If you have lots of different m, d, & y variables, you may want to learn about foreach or forvalues depending on how your variables are named.
I have done my best to see how foreach could be adapted to this problem. It is possible that if I understood macros better it would help. A miniature version of what I am talking about would be variables mo1, mo2, day1, day2, yr1, yr2, hoping to use them to calculate dt1, dt2, without two statements gen dt1 = mdy(mo1,day1,yr1) and gen dt2 = mdy(mo2,day2,yr2). I'd like to be able to say something like

foreach w of varlist mo1 mo2
and each x of varlist day1 day2
and each y of varlist yr1 yr2
and each z of newlist dt1 dt2 {
gen z = mdy(w,x,y)
}

Any idea how I could go about this?

Thank you so much!

Yours truly,
Clare Maxwell
*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index