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

Re: st: Calculating lots of date variables from month, day andyear variables


From   "Eric G. Wruck" <ewruck@econalytics.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Calculating lots of date variables from month, day andyear variables
Date   Sat, 12 Nov 2005 14:02:13 -0500

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.

For example, if you have

  +----------------+
  |  m    d      y |
  |----------------|
  | 11   12   2005 |
  +----------------+

. gen date = mdy(m,d,y)

. l, noobs

  +------------------------+
  |  m    d      y    date |
  |------------------------|
  | 11   12   2005   16752 |
  +------------------------+

. format date %dd-m-CY

. l, noobs

  +------------------------------+
  |  m    d      y          date |
  |------------------------------|
  | 11   12   2005   12-Nov-2005 |
  +------------------------------+

Note that the date value of 16752 means that 16,752 days have transpired since January 1, 1960, day 0 in Stata.  Formatting the date gets you something a bit more understandable.

Hope this helps,


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.



>Hello to the Stata listers.
>
>I am new to Stata data processing and have not yet found a way to deal with coordinated variable lists.  For example, I want to use a long list of month, day and year variables to calculate a list of date variables.  Can anyone tell me how they have solved this problem?
>
>Thanks a lot.
>
>				Yours truly,
>				Clare Maxwell



-- 

===================================================

       Eric G. Wruck
       Econalytics
       2535 Sherwood Road
       Columbus, OH  43209

       ph:      614.231.5034
       cell:    614.330.8846
       eFax:    614.573.6639
       eMail:   ewruck@econalytics.com
       website: http://www.econalytics.com

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