Announcement

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

  • converting string form quarterly data into a form for tsset

    My data looks like this:

    I want it to look like

    1987q1
    1987q2
    1987q3
    1987q4
    1988q1
    1988q2
    1988q3
    1988q4 etc

    where qtr has format %tq.
    I tried

    replace qtr=subinstr(qtr,"Jan to Mar","",.)+"q1" but this only works the first time round. Please advise.

    Robert


  • #2
    Copy and paste the output of

    Code:
    dataex qtr in 1/20
    At the moment, we have no clue about the contents of this variable.

    Comment


    • #3
      I agree with Andrew Musau, except that there is a fragment of a detail there which allows some wild guesses. You may be able to adapt this.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str16 problem
      "Jan to Mar 2024"
      "Apr to Jun 2024"
      "Jul to Sep 2024"
      "Oct to Dec 2024"
      end
      
      gen wanted = qofd(dofm(monthly(word(problem, 1) + word(problem, -1), "MY")))
      
      list 
      
           +--------------------------+
           |         problem   wanted |
           |--------------------------|
        1. | Jan to Mar 2024      256 |
        2. | Apr to Jun 2024      257 |
        3. | Jul to Sep 2024      258 |
        4. | Oct to Dec 2024      259 |
           +--------------------------+
      
      . format wanted %tq
      
      . l
      
           +--------------------------+
           |         problem   wanted |
           |--------------------------|
        1. | Jan to Mar 2024   2024q1 |
        2. | Apr to Jun 2024   2024q2 |
        3. | Jul to Sep 2024   2024q3 |
        4. | Oct to Dec 2024   2024q4 |
           +--------------------------+

      Comment

      Working...
      X