Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: extracting month and year from a date variable


From   "Kieran McCaul" <Kieran.McCaul@uwa.edu.au>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: extracting month and year from a date variable
Date   Thu, 27 Aug 2009 12:35:15 +0800

...

There are -year()-, -month()-, and -day()- functions that can extract
these components from a date variable.

See -help dates-

______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2701
Fax: (08) 9224 8009
email: Kieran.McCaul@uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
If you live to be one hundred, you've got it made.
Very few people die past that age - George Burns

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ariel Linden,
DrPH
Sent: Thursday, 27 August 2009 11:37 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: extracting month and year from a date variable

Hi Fellow Stata Listservers,

I am trying to generate a variable that contains only the month and
year,
extracted from another complete date variable. The ultimate intent is to
aggregate a given outcome by the month/year.

So for example, the original date value is 17374, which is displayed as
07/27/2007. I would like to generate a variable that is "Jul 2007" or
"07_2007" (I am not picky on the style, this is just to allow me to
aggregrate by this variable).

I get the feeling that I will have to convert this to a string and then
generate the variable with a substr statement, but I hope there is an
easier
way.

Thanks in advance

Ariel 

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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