Announcement

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

  • Generate quarter from datetime

    Dear Statalisters,

    I have a variable called it fdate, it is stored as int type and format %d, e.g. 31dec2009, I know how to generate year by
    gen year=year (fdate)

    how do I generate quarter ? do i need to do qofd, then convert it back to quarter?

    Many thanks,

    Rochelle

  • #2
    Code:
    . gen td=mdy(7,5,2013)
    . format td %td
    . gen q = qofd(td)
    . format q %tq
    . list
    
         +--------------------+
         |        td        q |
         |--------------------|
      1. | 05jul2013   2013q3 |
         +--------------------+

    Comment


    • #3
      Duplicate and expanded in:

      http://www.statalist.org/forums/foru...-from-datetime
      You should:

      1. Read the FAQ carefully.

      2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

      3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

      4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

      Comment

      Working...
      X