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 |
Subject | Re: st: converting series of dates to numeric variable |
Date | Wed, 23 May 2012 10:29:27 +0100 |
But you need to check that your dates really are equally spaced. You can use -mod(,)- for that purpose. . di mod(date("1 Nov 2009", "DMY"), 28) 2 . di mod(date("29 Nov 2009", "DMY"), 28) 2 All equally spaced dates have the same remainder. For more on -mod(,)- see SJ-7-1 pr0031 . Stata tip 43: Remainders, selections, sequences, extractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q1/07 SJ 7(1):143--145 (no commands) tip for uses of the modulus For more on -floor()- and -ceil()- see SJ-3-4 dm0002 . . . . . . . . Stata tip 2: Building with floors and ceilings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q4/03 SJ 3(4):446--447 (no commands) tips for using floor() and ceil() Nick On Wed, May 23, 2012 at 10:19 AM, Nick Cox <njcoxstata@gmail.com> wrote: > Yes, it should be mildly alarming, as it shows that you are trying > something which is inappropriate for you. But you can fix that. > > The -date()- function converts to daily dates. That is its job. In > terms of daily dates, the resolution of your data (delta) is one day > and you have (lots of) gaps. Stata doesn't look out for equally spaced > dates in what it sees as gappy time series. > > In your case I would recommend working with -floor(edate1/28)- as a > time variable, which gives equally spaced dates with 28 days as an > interval. Using -int()- or -ceil()- instead of -floor()- would work as > well. For example, > > . di floor(date("1 Nov 2009", "DMY")/28) > 650 > > . di floor(date("29 Nov 2009", "DMY")/28) > 651 > > So go > > gen edate2 = floor(edate1/28) > tsset identif2 edate2 > > Nick > > On Wed, May 23, 2012 at 10:07 AM, loggyedr salvez > <loggyedy@googlemail.com> wrote: > >> I have observations every 4 weeks (4-week period data). >> >> In the excel.csv file i format the cells for the date column as follows >> >> dates11 identier variable >> November 1, 2009 1 >> November 29, 2009 1 >> December 27, 2009 1 >> January 31, 2010 1 >> November 1, 2009 2 >> November 29, 2009 2 >> December 27, 2009 2 >> January 31, 2010 2 >> >> and then I use the commads: >> >> gen edate1 = date(dates11, "MDY") >> format edate1 %d >> tsset identifier edate1 >> >> >> >> and I get the following stata message: >> >> tsset identif2 edate1 >> panel variable: identif2 (strongly balanced) >> time variable: edate1, 02nov2008 to 09oct2011, but with gaps >> delta: 1 day >> >> >> Is this message something alarming? why "gaps"? and why delta "1 day" * * 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/