Announcement

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

  • Conversion of monthly sting variable into monthly float variable for time series analysis

    Hello everyone i am really new to stata and i have an econometrics paper due in a couple days and i have to perform some time series analysis on the data i have.
    I am using Monthly data from 2007-12-01 to 2019-10-01 in a "YMD" format. I have been trying to declare my dataset as a time series data but i have been unable to do so because my monthly data is currently in a string type. I have used numerous of Date and Time functions to fix this problem such as date(), month(), monthly(), mofd(), but none of them have given me my desired result.
    When i used the mofd(date("2009-08-01", "YMD")) and changed the format all my monthly observations appeared as 2009m8 instead of 2007m12 - 2019m10 which is what i want.
    Please if anyone is capable or willing to help me i would deeply appreciate it. I have watched countless youtube videos and gone through the help guide but unable to find the correct command function.
    Again i need this to be able to declare time series dataset and perform a Dickie Fuller test for stationary in my time series data. So any help is welcomed

  • #2
    Welcome to Statalist.

    Perhaps this example will point you in a useful direction.
    Code:
    // here is sample data to demonstrate the code
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 date_s
    "2007-12-01"
    "2019-10-01"
    end
    
    // here is the code to create numeric Stata Internal Format monthly dates from string Human Readable Format daily dates.
    generate date_d = daily(date_s,"YMD")
    format %td date_d
    generate date_m = mofd(date_d)
    format %tm date_m
    list, clean noobs
    Code:
    . list, clean noobs
    
            date_s      date_d    date_m  
        2007-12-01   01dec2007   2007m12  
        2019-10-01   01oct2019   2019m10

    Comment


    • #3
      Thank you so much, i appreciate the help

      Comment

      Working...
      X