Announcement

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

  • to change the format of date variable

    hello,

    I am trying to change the format of my date variable

    currently, my date variable is arranged as


    date
    1947 - Q1
    1947 - Q2
    1947 - Q3
    1947 - Q4
    1948 - Q1


    but I would like to change the format (I am just playing with it now), but when I use the command

    format date %tq

    it displays an error message,

    "string %fmt required for string variables"


    My date variable is a string variable. What can I do in this case?


    Thanks a lot

  • #2
    Changing the format won't change the contents of a variable.

    For converting string date variables to numeric date variables, read

    Code:
    help datetime
    In this example, consider

    Code:
    clear 
    input str9 qdate 
    "1947 - Q1"
    "1947 - Q2"
    "1947 - Q3"
    "1947 - Q4"
    "1948 - Q1"
    end 
    
    gen nqdate = quarterly(qdate, "YQ") 
    format nqdate %tq 
    
    list 
    
         +---------------------+
         |     qdate    nqdate |
         |---------------------|
      1. | 1947 - Q1    1947q1 |
      2. | 1947 - Q2    1947q2 |
      3. | 1947 - Q3    1947q3 |
      4. | 1947 - Q4    1947q4 |
      5. | 1948 - Q1    1948q1 |
         +---------------------+

    Comment

    Working...
    X