Announcement

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

  • Destring a Month-Year variable in order to apply the tsset command for a time graph

    Hi Stata people;

    I'm using Stata 13.1 version with this data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str14 Month long(Imports_in_Millions_of_USD Trade_Balance_in_Millions_of_USD)
    "January 2023"   327789  -69960
    "February 2023"  323412  -70521
    "March 2023"     317232  -60321
    "April 2023"     323721  -72756
    "May 2023"       316947  -66066
    "June 2023"      315873  -64806
    "July 2023"      318530  -64607
    "August 2023"    318137  -59631
    "September 2023" 323864  -62222
    "October 2023"   325116  -64333
    "November 2023"  321284  -64754
    "December 2023"  324802  -64915
    "January 2024"   326028  -66859
    "February 2024"  335099  -69341
    "March 2024"     329499  -68547
    "April 2024"     338483  -75905
    "May 2024"       337701  -76632
    "June 2024"      339613  -74180
    "July 2024"      346900  -79886
    "August 2024"    344020  -71444
    "September 2024" 354823  -85014
    "October 2024"   339939  -73727
    "November 2024"  351755  -78239
    "December 2024"  364581  -98062
    "January 2025"   401158 -130652
    "February 2025"  401120 -122662
    end
    The goal is to transform the 'Month" variable into a variable on which I can apply the "tsset" command and draw a time graph for the other two variables.

    Ant help please? With many thanks!

  • #2
    Did you try looking at the help, say

    Code:
    help datetime
    -- because it answers this and many other similar questions?

    This example yields to simple technique:

    Code:
    gen mdate = monthly(Month, "MY")
    
    format mdate %tm 
    
     tsset mdate

    Comment

    Working...
    X