Announcement

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

  • Tertials (four-month) date formatting

    My apologies in advance if the answer to this problem is obvious, but I haven't found one in the help files nor by googling.

    How do I format a four-month period date variable?

    For instance, the values for 2014 are the following:

    201401
    201402
    201403,

    where 201401 contains data from January to April and so on.

    The Stata manual provides for year, half-year, quarters and month, but as far as I see, not for tortillas (or two-months periods for that matter).

  • #2
    Tortillas?

    It's entirely up to you, within two rules that you should adopt in your best interests:

    1. For just about every Stata purpose, the four-month periods should be represented by increasing integers. You don't want to be negotiating jumps such as that from 201403 to 201501, notionally 98, but "should be" 1.

    2. For just about every human purpose, you want to see intelligible dates in graphs and tables. That means value labels, as existing date formats can at best confuse here.

    #1 is arbitrary but following Stata convention 196001 in your convention could be 0.

    Although it may seem overkill, you may need three variables for maximum flexibility for (a) year (b) tertial within year (c) both.

    If you already have integers such as 201401 in a variable tertial, then

    Code:
    gen year = floor(tertial/100) 
    gen twy = mod(tertial, 100) 
    gen tertial_date = 3 * (year - 1960) + (twy - 1) 
    labmask tertial_date, values(tertial)
    where labmask is to be installed from the Stata Journal archives.

    If you have such integers within a string variable, then destring it first.

    Comment


    • #3
      To my knowledge, there is no built-in Stata data representation for four-month intervals, nor any corresponding format. Stata does have "business calendars," which I have never used and know little about--it is possible that you can create a representation like this with a business calendar, but I don't know.

      I don't know where you're going with this or how you plan to use these dates. But if business calendars won't do what you need, given that this is the data you have, I would probably represent this with two variables, one of them being a Stata date variable corresponding to the date of the first day of the period and the other being an easily human-readable version. So, on the assumption that your values 201401, 201402, 201403, etc. are strings with the name string_date, I would do this:

      Code:
      gen num_date = mdy(4*real(substr(string_date, 5, 2))-3, 1, real(substr(string_date, 1, 4)))
      format num_date %td
      replace string_date = substr(string_date, 1, 4) + "t" + substr(string_date, 6, 1)
      Calculations will generally rely on num_date, but string_date can be carried along as a convenience for human readability.

      Comment


      • #4
        This was posted while I was writing my answer.

        There is a fiddly objection to this, which is that 1 January, 1 April, 1 July and 1 October are not quite equally spaced as daily dates which would mess up lags, leads, etc. But that objection would be squashed utterly by tweaking this in one small detail: use the starting month (not day) and then as necessary declare gaps of 3 to tsset or xtset.

        Comment


        • #5
          Nick makes a good point about unequal spacing. I agree with his modification.

          Comment


          • #6
            Thank you for your rapid replies. Seems to me like the labmask solution will be the most flexible - I'll try it out tomorrow.

            Comment


            • #7
              Clyde's suggestion and mine can be mixed. Suppose you have numeric variable tertial with values like 200401 and 200503. The starting month for each tertial is, as a Stata monthly date,

              Code:
               
              gen mdate = ym(floor(tertial/1000), 4 * mod(tertial, 1000) - 3)  
              format mdate %tm
              and you can attach the values of tertial as value labels using labmask, giving you a choice of presentation.

              Comment


              • #8
                Hello Guys,

                My apologies if my doubt is obvious.

                I am having problems in declaring the gaps of in the four month serie in the tsset function.

                How do I declare this gaps?

                Tks

                Comment


                • #9
                  Specify the -delta(3)- option in your -xtset- or -tsset- command.

                  Comment

                  Working...
                  X