Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | <redacted> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: appending date variable in 2 datafiles |
Date | Wed, 17 Oct 2012 12:31:11 +0100 |
Dear Nick, Yes, the solution is very simple like you have said. I did gen newDateVar = date(DateVar, "DMY") format newDateVar %td Thanks <redacted> On Wed, Oct 17, 2012 at 12:10 PM, Nick Cox <njcoxstata@gmail.com> wrote: > Stata prefers daily dates to be numeric variables coded with origin 1 > January 1960, so converting all date variables to that form is the way > to go. (The difference you have is of variable or data type, not one > of format in Stata's sense of the word.) > > You said that your variable was MDY, in response to which Stata can > make no sense of the 5th day of the 23rd month, etc. But your variable > is evidently DMY. > > Nick > > On Wed, Oct 17, 2012 at 11:58 AM, <redacted> wrote: > >> I have a date variable in a stata datafile : >> >> DATAFILE A >> >> +-----------+ >> doa >> ----------- >> 1. 14dec2010 >> 2. 19dec2010 >> 3. 30mar2010 >> 4. 16jun2010 >> 5. 06jan2010 >> +-----------+ >> >> and I have a date variable also in a stata datafile that I would like >> to append to the datafile above (DATAFILE A) >> >> DATAFILE B >> >> +------------------------+ >> doa date3 >> ------------------------ >> 1. 23-05-2012 . >> 2. 03-11-2011 11mar2011 >> 3. 02-09-2010 09feb2010 >> 4. 01-07-2010 07jan2010 >> 5. 18-04-2012 . >> +------------------------+ >> >> The problem is both datafiles use different format of date, the former >> uses numeric and the latter uses str. My questions would be >> 1) what is the best way to work around appending this two datafiles >> 2) i have converted the 'doa' in the latter file (DATAFILE B) using >> >> generate date3=date(doa,"MDY") >> format date3 %d >> >> but only obs from 2 to 4 were converted but obs 1 and 5 were not. >> >> Really appreciate if someone can help me with these 2 questions. > * > * 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/