Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: converting series of dates to numeric variable


From   loggyedr salvez <loggyedy@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: converting series of dates to numeric variable
Date   Wed, 23 May 2012 21:28:04 +0200

Dear Nick, thank you so much for your reply.

Yes, now it works


. tsset identif2 edate2
       panel variable:  identif2 (strongly balanced)
        time variable:  edate2, 637 to 675
                delta:  1 unit


Using the function mod to check for equally spaced dates I realized
that one date does not give the same remaider (2) as the rest of the
dates. I assume that the best approach is to open the data file and
change manually that date (by some days) so as to fix the problem. Am
I correct or is there any other more "advanced approach"

thank you again

On 5/23/12, Nick Cox <njcoxstata@gmail.com> wrote:
> 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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index