Announcement

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

  • Transforming a variable into a time variable in order to apply the tsset command and draw a time graph

    Hello Stata users;

    I'm using the 13.1 version of Stata. I do have this data at hand:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 Date float GDP
    "31-janv"  2.9
    "28-Feb"  -1.5
    "17-mars" -2.1
    "18-mars" -1.8
    "20-mars" -1.7
    "25-mars" -1.9
    "26-mars" -1.8
    "28-mars" -2.8
    "1-Apr"   -3.7
    "2-Apr"     -3
    "3-Apr"   -2.8
    "4-Apr"   -2.4
    "9-Apr"   -2.4
    end
    It is about the evolution of the American GDP for a short period. The first variable is the date of the observation, the second variable is the value of the GDP (in %) in that date.
    The idea is to transform the "Date" variable into a time date in order to draw a time graph of the evolution of the GDP by date.

    Any help with that please?

    With many thanks!

  • #2
    I didn't know that GDP was calculated daily. and I am confident that its units are not %. But I will just focus on the Stata questions, as perhaps you just made up these data.

    Your data show at least two problems, the absence of a year and the bizarre mix of English and French for months.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 Date float GDP
    "31-janv"  2.9
    "28-Feb"  -1.5
    "17-mars" -2.1
    "18-mars" -1.8
    "20-mars" -1.7
    "25-mars" -1.9
    "26-mars" -1.8
    "28-mars" -2.8
    "1-Apr"   -3.7
    "2-Apr"     -3
    "3-Apr"   -2.8
    "4-Apr"   -2.4
    "9-Apr"   -2.4
    end
    
    gen try1 = daily(Date + "1960", "DMY")
    
    replace Date = subinstr(Date, "janv", "jan", 1)
    replace Date = subinstr(Date, "mars", "mar", 1)
    
    gen try2 = daily(Date + "1960", "DMY")
    
    format try* %td 
    
    list 
    
        +---------------------------------------+
         |   Date    GDP        try1        try2 |
         |---------------------------------------|
      1. | 31-jan    2.9           .   31jan1960 |
      2. | 28-Feb   -1.5   28feb1960   28feb1960 |
      3. | 17-mar   -2.1           .   17mar1960 |
      4. | 18-mar   -1.8           .   18mar1960 |
      5. | 20-mar   -1.7           .   20mar1960 |
         |---------------------------------------|
      6. | 25-mar   -1.9           .   25mar1960 |
      7. | 26-mar   -1.8           .   26mar1960 |
      8. | 28-mar   -2.8           .   28mar1960 |
      9. |  1-Apr   -3.7   01apr1960   01apr1960 |
     10. |  2-Apr     -3   02apr1960   02apr1960 |
         |---------------------------------------|
     11. |  3-Apr   -2.8   03apr1960   03apr1960 |
     12. |  4-Apr   -2.4   04apr1960   04apr1960 |
     13. |  9-Apr   -2.4   09apr1960   09apr1960 |
         +---------------------------------------+
    Naturally, you should use the year that you should know. tsset should work with the second variable tried.

    Comment


    • #3
      Nick Cox Thanks for the respond.

      In what comes to the data, you are kinf od right, the data is about a forecast of the US GDP that hase been done by the FED of Atlanta, I just found the data on the website, I do doubt that a GDP could be forecasted by days, but since the source is kind of reliable, one has to accept that data. The year is the current one, 2025. As for the mix of English and French in what comes to the months, I really didn't pay that much attention to that in fact until you've noticed that in your response.

      Thanks!

      Comment


      • #4
        Dear Aziz Essouaied. Do you get your data from here: GDPNow? I think it is a real time forecast of GDP growth rate, and renew time and again. The model estimate subcomponents of GDP using publicly released data. It has at least nine data sources, seven among them are particularly important. When these original sources released, GDPNow is usually updated within a few hours following.

        Comment


        • #5
          Chen Samulsion Thanks for the suggestion of the source. Actually No, I didn't get that data from that source, I got it from the FED of Atlanta website.

          Comment

          Working...
          X