Announcement

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

  • simplify date into year/quarter

    Hi all,

    I currently have dates in the format eg 2007-05-23. I need to change this into quarter and year variables but don't know how. I am unsure as to whether I need to convert it from string first; and if so how do i do this?

    my lecturer gave us a vague pointer of:

    * Simplify date into year/quarter*

    drop if date==.format %tdNN/DD/CCYY date

    gen quarter= quarter(date)

    I have tried this, and many variations of this but nothing has worked.

    PLEASE HELP IM SO CONFUSED!

    Many thanks,
    Harriet

  • #2
    I can't imagine quite what your lecturer had in mind with the drop idea.

    Meta-tips:

    0. "Nothing has worked" is on all fours with "I am not feeling well" or "My car won't start". Even experts need more detail. Show us data; show us code; explain why something is wrong or puzzling or unwanted.

    1. What you need is all documented. See e.g. help dates. You just need a little patience and perseverance to skim and skip through stuff you don't want or need now.

    2, With date problems I don't know the answer to, I always try out simple examples with display where I know immediately what's right or wrong.

    With a daily date variable quarter() is what you need to extract the quarter. The answer will be 1, 2, 3 or 4.

    If you want quarterly dates, qofd() is what you need.


    Code:
    . di %td  mdy(2, 5, 2017)
    05feb2017
    
    . di %tq  qofd(mdy(2, 5, 2017))
    2017q1
    
    . di quarter(mdy(2, 5, 2017))
    1
    
    . di year(mdy(2, 5, 2017))
    2017

    Comment


    • #3
      Nick is right, your question is not clear at all. If you intend to convert some daily frequency data to weekly, monthly, quarterly or year frequency, you can use ascol from SSC
      Code:
      ssc des ascol
      ssc install ascol
      help ascol
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        thank you for your pointers, eventually go there in the end!

        Comment

        Working...
        X