Announcement

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

  • Set panel data monthly

    Hi all, I want to set my panel data to monthly so that I can calculate the 3 month moving average of the data. I do not think my variable DateMY is saved as a date correctly, because when I set the panel to monthly the time variable has strange dates on it. When I set the panel regularly, there is not a problem. Any ideas?


    Click image for larger version

Name:	Screenshot 2024-11-23 at 4.57.10 PM.png
Views:	1
Size:	66.4 KB
ID:	1768161

  • #2
    Your dates are presented as daily dates, but are really monthly dates in disguise, as Stata is trying to hint. As months are of unequal length, you can't solve this problem with a delta() option. You need to convert to monthly dates.


    Code:
    generate mdate = mofd(dateMY)
    format mdate %tm 
    tsset mdate

    Comment


    • #3
      Thank you Nick!

      Comment


      • #4
        The easiest way to understand this is that -- with the exception of years, where Stata just believes what you say -- Stata's rule is that the earliest possible date in 1960 is 0. So for daily dates 0 means 1 January 1960 and for monthly dates 0 means January 1960.

        At some earlier point your 1 January 2001 was stored as an integer, Quite what is something you need not worry about, until it bites.

        Code:
        . di td(1jan2001)
        14976
        Now in effect you were saying to Stata "My dates which have daily date display formats are really monthly dates" but in terms of its rules 14976 is a monthly date far in the future.

        Code:
        . di %tm 14976
         3208m1
        And naturally this is a problem for all your dates.

        For a take in terms of what is stored and what is displayed see https://www.stata-journal.com/articl...article=dm0067 Nothing is said there about tsset or xtset. but it's the same issue.

        Comment

        Working...
        X