Announcement

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

  • Cronvert from yyyy-MM-ddTHH:mm:ssZ to mdyhms

    Hello,

    I am not sure whether someone already posted this question but as I am aware of I could not find any previous posts about this issue.

    I have a intra-day dataset with a timespam in this format: 2014-10-31T06:12:00Z and I would like to convert it to: 31oct2014 06:12:00.

    Could someone be kind and tell me how to do it?

    Thank you,
    Claudiu


    Attached Files

  • #2
    I tried to generate a new variable and set up the time as it should work with other time formats

    generate newsocial_at = daily(social_at, "YMDhms")

    but still doens't work

    Comment


    • #3
      There may be more elegant strategies. That said, please check whether this code is what you wish:

      Code:
      set obs 1
      generate str var1 = "2014-10-31T06:12:00Z" in 1
      */ below is where you should start from
      gen var2 = regexr(var1, "T", " ")
      gen var3 = regexr(var2, "Z", "")
      gen double var4 = clock(var3, "YMDhms")
      format var4 %tc
      list
      
           +----------------------------------------------------------------------------------------+
           |                 var1                   var2                  var3                 var4 |
           |----------------------------------------------------------------------------------------|
        1. | 2014-10-31T06:12:00Z   2014-10-31 06:12:00Z   2014-10-31 06:12:00   31oct2014 06:12:00 |
           +----------------------------------------------------------------------------------------+
      Best regards,

      Marcos

      Comment


      • #4
        Thank you so much Marcos!

        It works, I really appreciate your help!

        Comment


        • #5
          Thank you for informing the thread reached a satisfactory closure to you.
          Best regards,

          Marcos

          Comment


          • #6
            Hello Marcos,

            I am coming back to you with regards to the same dataset.

            Could you perhaps tell me how I can obtain the month of the year, 1 for January, 2 for February, 3 for March, etc.?

            I managed to get the day_of_week because is properly explained under "help datetime" on STATA but somehow I have difficulties with the month.


            I tried to generate month_of_year = month(dofm( Month )) but then all the generated values are missing.

            Could you please help me with this issue?

            Regards,

            Claudiu

            Comment


            • #7
              Your approach is right if you are supplying monthly dates. For example, you can check code with display or Mata:


              Code:
              . di month(dofm(ym(2018, 4)))
              4
              
              . mata
              ------------------------------------------------- mata (type end to exit) -------
              : month(dofm(ym(2018, (1..12))))
                      1    2    3    4    5    6    7    8    9   10   11   12
                  +-------------------------------------------------------------+
                1 |   1    2    3    4    5    6    7    8    9   10   11   12  |
                  +-------------------------------------------------------------+
              So, here ym(2018, 4) is the monthly date April 2018 and the Mata example extends the calculation to all the months of 2018.

              Hence

              1. It appears that Month is not a monthly date.

              2. There is, so far as I can see, no mention of Month as variable in the thread so far (and in particular no data example) so I can't tell you what it is.

              Please read and act on https://www.statalist.org/forums/help#stata Being unclear about the data just slows down your own progress.

              Comment


              • #8
                Hello Nick,

                Thank you very much for the quick reply. I saw your contribution to previous posts and I really appreciate your time and effort to help this community!

                I currently have intra-day data starting from 01sep2014 00:00:00 and I managed to extract the day of the week from this format as you can see in the attachment below. 1 stands for Monday, 2 for Tuesday,..., 6 for Saturday.

                For that I used the function:

                gen day_of_week = dow(dofc(statatime))

                Now, I want to do the same but instead of days I want to do it for months.

                I used the function:

                ge month_of_year = month(dofm( Month ))


                however, it does not work and I'm not sure how to tackle this issue.


                Could you please help me to build a new column like the day_of_week but for months? It is not necessary to know the year. I want to regress the returns for specific months. For instance to see whether returns in the summer are lower than in the winter.


                Thank you again!

                Claudiu
                Attached Files

                Comment


                • #9
                  Thanks for your thanks, but I can only repeat the advice from #7. If you read the link there you would read why screenshots do not help. In any case your screenshot is nothing to do with your question, as it concerns quite different variables. You never show how the variable Month was calculated or give an example in the form requested. Hence I can't add anything to my previous answer except repetition:

                  Please read and act on https://www.statalist.org/forums/help#stata



                  Comment

                  Working...
                  X