Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Augmented Dickey-Fuller unit root test: Time setting to weekly data

    I have to do an ADF test on weekly data (T-bill from ALFRED, 1/2/1970 ~ ). To do the test I have to change the date to weekly with command:

    . tsset Date, weekly

    But this doens't work since I have gaps in my date according to Stata (but there no gaps). So I used:

    . gen date2 = mofd(Date)

    . format datum %tw


    which gave me:

    Date WGS10YR TBILL termsp~l date2
    1. 1/2/1970 7.94 8.02 -0.08 1962w17
    2. 1/9/1970 7.93 7.91 0.02 1962w17
    3. 1/16/1970 7.82 7.83 -0.01 1962w17
    4. 1/23/1970 7.69 7.83 -0.14 1962w17
    5. 1/30/1970 7.73 7.89 -0.16 1962w17
    6. 2/6/1970 7.51 7.61 -0.10 1962w18
    7. 2/13/1970 7.27 7.20 0.07 1962w18
    8. 2/20/1970 7.13 6.79 0.34 1962w18
    9. 2/27/1970 7.01 6.88 0.13 1962w18
    10. 3/6/1970 6.97 6.89 0.08 1962w19


    This is obviously not right since 1/2/1970 is not week 17 in 1962. It should give me 1970w1

    When I used mofd(Date) on monthly data is worked, so I could format it to %tm and us it for my ADF test. But with weekly data I get the wrong date the whole time. Right now I have the date in excel in:

    nummeric form: ddmmjjjj
    string form: dd-mm-jjjj
    excel date form: dd/mm/jjjj

    I tried everything to get it in the form: jjjj w Nr. to use it in my test. But nothing worked for me so far. Can someone please help me out with this?

    Thank you




    Last edited by Rose Mrsl; 04 Jun 2017, 17:17.

  • #2
    Welcome to Statalist.

    I'm somewhat confused by your post.

    First, the weekly option of the tsset command does not convert the date to weekly, but rather it informs tsset that the data are weekly, if tsset cannot or should not deduce that information from the variable's format.

    The mofd() function converts daily dates to monthly dates, which is why it helped when you were analyzing monthly data. Converting your data to monthly and then applying a weekly format will not be helpful, as you found.

    A further problem is that you really don't want to be using Stata weekly dates for what you are doing. The problem in brief is that January 1 of each year marks the start of the first week for that year, and each year has 52 weeks, with the final week including extra days. That is a very peculiar idea, but that's what happens when you try to divide a calendar year into weeks without overlap into previous or following years.

    What you want, I think, is to use the delta option
    Code:
    tsset Date, daily delta(7)
    which tells tsset first that Date is a daily time increment (which it will figure out without you using the daily option if you have a %td format for Date) and second that your observations are separated by intervals of 7 days.

    I hope this solves your problem. I'd like to give a few pieces of more general advice.

    While the solution to your problem lies in an option to the tsset command, your questions show some unfamiliarity with how Stata handles dates. Before working with dates and times, any Stata user should thoroughly review the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF. After that, the help datetime documentation will usually be enough to point the way. All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

    I would have provided an example of code applying tsset to your data, but it was not presented in a way that makes it easy to read into Stata. To better present your questions in the future, you should review the Statalist FAQ linked to from the top of the page, looking especially at sections 9-12 on how to best pose your question. It is helpful to post, as you did, a small example of your data, perhaps with just a few variables and observations. But do please read FAQ #12 and use dataex and CODE delimiters when posting data, programs, and results to Statalist.

    Comment


    • #3
      Thank you very much! There is no error message anymore. And thanks for the advice!

      Comment

      Working...
      X