Announcement

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

  • Qdate to year

    Hi all, I have a variable "qdate" that only contains the last quarter of a year. I want to convert that to "year". So from the first example to the second.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int qdate
    207
    211
    215
    219
    223
    219
    223
    207
    211
    215
    219
    223
    207
    211
    215
    219
    223
    207
    211
    215
    219
    223
    215
    219
    207
    211
    211
    215
    207
    211
    215
    219
    211
    215
    207
    211
    207
    211
    215
    219
    223
    207
    211
    215
    219
    215
    219
    223
    223
    219
    215
    219
    219
    215
    219
    215
    219
    223
    215
    207
    211
    215
    end
    format %tq qdate

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double fyear
    2010
    2011
    2012
    2013
    end

  • #2
    Here are two ways to get the year. Both follow from reading

    Code:
    help datetime

    which is essential if you have dates in Stata.

    Code:
    gen year1 = year(dofq(qdate))
    gen year2 = 1960 + floor(qdate/4)
    The first method is to push quarterly dates into daily dates and take the year out using nested functions. The second method is based directly on definition of quarterly dates as counted from origin 1960Q1 = 0. It follows that 0 to 3 mean 1960, 4 to 7 mean 1961, etc.

    Comment

    Working...
    X