Announcement

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

  • How to pick the day and month data from a %tb.. format date-data?

    Hi all,

    I have a problem with converting date data. I created date data based on the business calendar. However, this new date is formatted as %tb. When I try to convert it into %tb, the results show 1960, which is definitely wrong because my data starts from 2013. I have tried offset or gen a new double/str var. Neither of these worked at all. Can anyone help me solve this?

    Many thanks!

    Cris

  • #2
    I created date data based on the business calendar. However, this new date is formatted as %tb. When I try to convert it into %tb, the results show 1960, which is definitely wrong because my data starts from 2013.
    If it is already formatted %tb, what does "convert it into %tb" mean? Did you mean convert it into %td?

    How did you do that? Stata has a function for that. See -help dofb()-.

    Comment


    • #3
      I don't know if this is a factor here, but there is a sharp distinction between what is stored and what is displayed.

      For example, Stata is predisposed to regard 23699 as just an integer but as soon as we ask to see it as a daily date

      Code:
      . di %td 23699
      19nov2024
      we learn that is interpretable as the daily date as I write. But if 23699 is the value of a scalar or a value of a variable, assigning a format makes absolutely no difference to what is stored.

      So far, so easy, perhaps, but there is a vital corollary. Changing the format does not change what is stored.

      This is particularly insidious with dates, where conversion of dates from one flavour to another, or extraction of date components, is key to many problems. To convert a date, or to extract a date component, is a calculation problem, and as Clyde Schechter exemplifies that calls usually for some kind of dedicated function.

      More on this small theme at Stata Journal | Article
      Last edited by Nick Cox; 19 Nov 2024, 12:19.

      Comment

      Working...
      X