Announcement

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

  • Converting quarterly string to Stata date format

    Dear all, I have a string variable "quarter" in the following format. How do I convert into the Stata date format?
    quarter Freq. Percent Cum.
    12006 4,787 6.44 6.44
    12007 3,598 4.84 11.27
    12008 3,600 4.84 16.11
    12009 3,601 4.84 20.95
    12010 4,800 6.45 27.41
    22006 3,600 4.84 32.25
    22007 3,600 4.84 37.09
    22008 3,601 4.84 41.93
    22009 3,600 4.84 46.77
    22010 3,600 4.84 51.61
    32006 3,600 4.84 56.45
    32007 3,600 4.84 61.29
    32008 3,600 4.84 66.12
    32009 3,599 4.84 70.96
    32010 3,600 4.84 75.80
    42006 3,600 4.84 80.64
    42007 3,598 4.84 85.48
    42008 3,600 4.84 90.32
    42009 3,601 4.84 95.16
    42010 3,600 4.84 100.00
    Appreciate your help!

    Maria

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long quarter int freq float(percent cum)
    12006 4787 6.44  6.44
    12007 3598 4.84 11.27
    12008 3600 4.84 16.11
    12009 3601 4.84 20.95
    12010 4800 6.45 27.41
    22006 3600 4.84 32.25
    22007 3600 4.84 37.09
    22008 3601 4.84 41.93
    22009 3600 4.84 46.77
    22010 3600 4.84 51.61
    32006 3600 4.84 56.45
    32007 3600 4.84 61.29
    32008 3600 4.84 66.12
    32009 3599 4.84 70.96
    32010 3600 4.84  75.8
    42006 3600 4.84 80.64
    42007 3598 4.84 85.48
    42008 3600 4.84 90.32
    42009 3601 4.84 95.16
    42010 3600 4.84   100
    end
    
    gen int year = mod(quarter, 10000)
    gen byte qrtr = floor(quarter/10000)
    gen qdate = yq(year, qrtr)
    format qdate %tq
    In the future, when showing data examples, please use the -dataex- command to do so, as I have done here. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    Comment


    • #3
      Thank you so much!!

      Comment

      Working...
      X