Announcement

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

  • Can't correctly convert timeseries time variable daily to monthly format in STATA 17.

    Hello, I am a novice in stata, but I have spent several hours trying to solve this issue without any luck.

    I have downloaded several monthly datasets from the Bloomberg terminal to excel files. When choosing monthly data, Bloomberg always gives you the last date in each month (31/01/1985, 28/02/1985, 29/03/1985, etc...). One of the variables is attached, the Baltic Dry Index

    When importing the excel file into STATA with the time variable named "Date", I run the following code:
    Code:
    . tsset Date
    
    Time variable: Date, 31jan1985 to 31jan2022, but with gaps
            Delta: 1 day
    Stata automatically believes the data is daily. When I try to tell stata that the data is monthly, it gives the following warning, with a format I cannot interpret:
    Code:
    . tsset Date, monthly
    warning: Variable Date had been formatted %td (a daily period), and you asked
             for a monthly period. Are you sure that is what you want? Format has
             been changed. Date is now formatted %tm.
    
    Time variable: Date, 2723m7 to 3849m9, but with gaps
            Delta: 1 month
    Is it it displaying month 7 in the year 2723 to month 9 in the year 3849? How do I format it to display 1985m1 to 2022m1?
    Attached Files

  • #2
    Also, the lag operator L. does not work, neither does lead F. or differencing D.

    I thought that was because of the time format being daily, but it does not work when I format it to monthly either.

    When i try to get monthly return for instance, it only generates missing values:

    Code:
    . gen ret_Baltic = logBaltic-L.logBaltic
    (445 missing values generated)

    Comment


    • #3
      Code:
      gen MDate = mofd(Date)
      
      tsset MDate, monthly
      You can't change dates from one kind to another by changing the date display format.

      SJ-12-4 dm0067 . . . . . . . . . Stata tip 113: Changing a variable's format
      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
      Q4/12 SJ 12(4):761--764 (no commands)
      discusses what changing a variable's format does and does
      not mean


      https://www.stata-journal.com/articl...article=dm0067

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Code:
        gen MDate = mofd(Date)
        
        tsset MDate, monthly
        You can't change dates from one kind to another by changing the date display format.

        SJ-12-4 dm0067 . . . . . . . . . Stata tip 113: Changing a variable's format
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
        Q4/12 SJ 12(4):761--764 (no commands)
        discusses what changing a variable's format does and does
        not mean


        https://www.stata-journal.com/articl...article=dm0067

        This solved my problem, THANK YOU! lag/lead operator works now too.

        Comment

        Working...
        X