Announcement

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

  • Sort a database to reverse a time variable in order to draw a time graph

    Hello Stata people;

    I'm working with Stata 13.1, I have this data:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str18 Month float Inflation
    "August 31, 2025"    -.4
    "July 31, 2025"        0
    "June 30, 2025"       .1
    "May 31, 2025"       -.1
    "April 30, 2025"     -.1
    "March 31, 2025"     -.1
    "February 28, 2025"  -.7
    "January 31, 2025"    .5
    "December 31, 2024"   .1
    "November 30, 2024"   .2
    "October 31, 2024"    .3
    "September 30, 2024"  .4
    "August 31, 2024"     .6
    "July 31, 2024"       .5
    "June 30, 2024"       .2
    "May 31, 2024"        .3
    "April 30, 2024"      .3
    "March 31, 2024"      .1
    "February 29, 2024"   .7
    "January 31, 2024"   -.8
    "December 31, 2023"  -.3
    "November 30, 2023"  -.5
    "October 31, 2023"   -.2
    "September 30, 2023"   0
    "August 31, 2023"     .1
    "July 31, 2023"      -.3
    "June 30, 2023"        0
    "May 31, 2023"        .2
    "April 30, 2023"      .1
    "March 31, 2023"      .7
    "February 28, 2023"    1
    "January 31, 2023"   2.1
    "December 31, 2022"  1.8
    "November 30, 2022"  1.6
    "October 31, 2022"   2.1
    "September 30, 2022" 2.8
    "August 31, 2022"    2.5
    "July 31, 2022"      2.7
    "June 30, 2022"      2.5
    "May 31, 2022"       2.1
    "April 30, 2022"     2.1
    "March 31, 2022"     1.5
    "February 28, 2022"   .9
    "January 31, 2022"    .9
    end
    As you can see, it's a database showing the monthly inflation rate. The "Month" variable starts from August 2025 and goes down to January 2022. Yet, I can't draw a time graph with it sorted in reverse, so, my goal is to have that "Month" variable starting from January 2022, and reformulate it in a way to be able to apply the tsset command on it and draw a time graph for the "Inflation" variable.

    Any help please?
    With many thanks!

  • #2
    help datetime

    Comment


    • #3
      Might go somethign like this:

      Code:
      gen temp_date = date(Month, "MDY")
      gen monthly = mofd(Month)
      format monthly %tm
      drop temp_date
      
      tsset monthly
      
      tsline Inflation
      I'd recommend studying datetime, which is a "do as I say, not as I do" recommendation.

      Comment


      • #4
        George Ford means mofd(temp_date)

        Comment


        • #5
          George Ford and Nick Cox Thanks to both of you!

          Comment

          Working...
          X