Announcement

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

  • Taking a midpoint of quarter

    I have two numeric variables labeled quarter (1,2,3,4) and year. I want to generate a new variable that uses first day of midpoint of the quarter (e.g., 01 Feb for 1st quarter, 01 May for 2nd quarter, etc) as day and month so I can combine it with year to generate SIF MDY variable. Any help is appreciated.

  • #2
    Code:
    //  CREATE A TOY DATA SET TO ILLUSTRATE THE CODE
    clear*
    set obs 8
    gen year = cond(_n <= 4, 2012, 2013)
    gen quarter = mod(_n, 4)
    replace quarter = quarter + 1
    sort year quarter
    
    //  SOLUTION TO PROBLEM POSED
    gen qdate = yq(year, quarter)
    format qdate %tq
    gen mid_quarter = dofm(mofd(dofq(qdate))+1)
    format mid_quarter %td

    Comment


    • #3
      This worked perfectly. Thanks

      Comment


      • #4
        Hi! I have a similar problem to the above, but I would like to find the actual midpoint per quarter, not the 1st dat of the middle month (so for q2, this would be 15 may, for q3 this would be 15 august etc). How do I change this syntax to get the desired result?

        Comment


        • #5
          Just add 14.

          Code:
           
           gen mid_quarter = 14 + dofm(mofd(dofq(qdate))+1)

          Comment


          • #6
            Thank you Nick!

            Comment

            Working...
            X