Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Change string to year and month date |
Date | Fri, 18 Oct 2013 16:31:08 +0100 |
-help dates and times- documents that -date()- generates daily dates and _only_ daily dates. The name is a historical hangover from a time when daily dates were the only dates supported by Stata. There is a synonym -daily()- that works, which in my view should be more prominent in the documentation. Imagine that you are Stata. What would you do given the information you supplied? Without an explicit day of the month, day 1 being imputed is a reasonable default. You have monthly dates and should use -monthly()- to translate from string to numeric. Nick njcoxstata@gmail.com On 18 October 2013 16:16, DeMichele, Matthew <mdemichele@rti.org> wrote: > I'm trying to create a date variable using only the year and the month > from a string variable formatted as YYYYMM. For example, 200405 = May, > 2004. I ran the syntax below, but this results in DAY appearing in the > first two columns as "01" such that the example above would be > 01May2004. > > gen DATE_OF_BIRTH3= date(DATE_OF_BIRTH2, "YM") > format DATE_OF_BIRTH3 %td > > thank you. Matthew > > > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/