Announcement

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

  • How input monthly time series data as monthly?

    Hi everyone,

    I'm sorry if my question is to basic, but I couldn't solve the problem by myself.
    I'm doing a basic regression of time series data. No big deal. For that I'm importing an excel spreadsheet with the monthly data. They don't include days, it's just months and years. BUT Stata believes the data are daily and adds days which i don't know how to get rid of. I've added a few screenshots to show what I did.
    I followed the idea of this video : but the outcome seems odd to me.
    First pic excel sheet, second pic imported data, third pic outcome of tsset.

    Click image for larger version

Name:	Original.JPG
Views:	1
Size:	27.0 KB
ID:	1446832
    Click image for larger version

Name:	Monat.JPG
Views:	1
Size:	25.1 KB
ID:	1446829
    Click image for larger version

Name:	monat2.JPG
Views:	1
Size:	23.4 KB
ID:	1446831
    Click image for larger version

Name:	tsset.JPG
Views:	1
Size:	23.8 KB
ID:	1446830


    I very much appreciate your time and thank you for helping me.

  • #2
    The problem is that monthly dates have been read in as daily dates. I suspect that those daily dates lurk underneath what you show in Excel.

    As you can see, you don't solve that problem with a different display format.

    To understand why, please see

    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/sjpdf....iclenum=dm0067


    You solve that problem by a conversion function.

    This shows the principle:

    Code:
    . di %tm  mofd(mdy(12, 31, 1987))
    1987m12
    mofd() maps daily dates to monthly dates. See also help datetime

    So, you need something like

    Code:
    gen MONAT = mofd(monat)
    format MONAT %tm
    tsset MONAT
    For future questions, please follow FAQ Advice #12 and show data between CODE links, not images.
    Last edited by Nick Cox; 30 May 2018, 15:31.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      The problem is that monthly dates have been read in as daily dates. I suspect that those daily dates lurk underneath what you show in Excel.

      As you can see, you don't solve that problem with a different display format.
      The thing is: all data are taken from Datastream as monthly. So there would be no way to hide a daily format? I played around with the display format, but that of course didn't change the issue. I really tried to understand why Stata does what it does, but it's quite complex for a beginner.


      Originally posted by Nick Cox View Post
      You solve that problem by a conversion function.
      Thank you so much for your answer. I'll try that immediately.

      Comment

      Working...
      X