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
    your question makes no sense; please show us what you have and what you want in a brief example (qofd does give you quarter (at least in a sense)

    Comment


    • #3
      maybe I asked a silly question,

      for example, fdate =31dec2009,the corresponding quarter would be 4, I suppose I could use month function to figure out which quarter it is then.

      thanks,
      Rochelle

      Comment


      • #4
        my solution:
        gen mon=month(fpedats)

        gen qtr=1 if inlist(mon, 1, 2, 3)

        replace qtr=2 if inlist(mon, 4, 5, 6)

        replace qtr=3 if inlist(mon, 7, 8,9)

        replace qtr=4 if inlist(mon, 10, 11, 12)

        Comment


        • #5
          -help quarter-
          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