Announcement

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

  • concatenate year and quarter

    hello everyone: I want to concatenate a variable (year) with another variable (quarter), both numeric, but would like to include a slash (/) in between. I would like to combine 1999 and T1 to obtain 1999/T1... I tried creating this last combined variable in excel before importing that file to stata but I would like to use it as the X axis variable in a "line" graph and the variable is not accepted to be string ... Do any of you know how to solve this? maybe there is another way to do it (not with the concatenate function). Thank you very much. Juan

  • #2
    I guess the solution starts with

    gen newvar = yq( year , quarter )

    But then as far as I remember I should use the "format" command (format newvar...) and don't know what to type to get year/quarter like 1999/T1 or just 1999/01
    For the sake of simplicity, let's assume my variables are
    year: 1999 and 2000
    quarter: 1, 2, 3, 4

    Thank you again

    Comment


    • #3
      I think this code will set you on a useful path. It seems to me that you've been reading the output of help datetime which got you to the yq() function. In that same output, in the section titled "Displaying SIFs in HRF", following the basic table of formats you will see a clickable link for "Datetime display formats". Click that link, it's where all the magic for constructing formats is given.
      Code:
      * Example generated by -dataex-. To install: ssc install dataex\
      clear
      input float(year quarter)
      1999 1
      1999 2
      1999 3
      1999 4
      2000 1
      2000 2
      2000 3
      2000 4
      end
      
      gen newvar = yq( year , quarter )
      format newvar %tqCCYY/!Tq
      list, noobs sepby(year)
      Code:
      . list, noobs sepby(year)
      
        +--------------------------+
        | year   quarter    newvar |
        |--------------------------|
        | 1999         1   1999/T1 |
        | 1999         2   1999/T2 |
        | 1999         3   1999/T3 |
        | 1999         4   1999/T4 |
        |--------------------------|
        | 2000         1   2000/T1 |
        | 2000         2   2000/T2 |
        | 2000         3   2000/T3 |
        | 2000         4   2000/T4 |
        +--------------------------+

      Comment


      • #4
        William your tip worked !!! thank you very much, Juan

        Comment

        Working...
        X