Announcement

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

  • Transforming readable dates into integers

    Dear All,

    I transformed the string dates by doing the following:

    gen date1=date(dateString1,"MDY")
    format date1 %td

    However, when I now try to declare my dataset as a panel data (xtset company_name date1), there appears an error message (r451): time variable must contain only integer values. Is there a way to solve this? One way I thought of was reversing the last step (format date1 %td) as then I would be left with only integer values I believe.

    Many thanks in advance for the help and a great weekend ahead!

  • #2
    Your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show example data, including the variables dateString1 and date1. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

    Put another way, the format you apply to the variable date1 does not affect the values stored in the variable date1 - it only affects how they are presented for display. Changing the format will not change non-integers to integers.

    The command
    Code:
    browse if floor(date1)!=date1
    will open Stata's Data Browser showing observations which have non-integer values. Perhaps this will shed some light on the source of your problem.
    Last edited by William Lisowski; 29 Apr 2022, 11:13.

    Comment


    • #3
      I am puzzled too to know what is going on but I am clear that it is not the format that is biting. It's hard to know how the result of date() could be an non-integer. My only guess is that you've simplified a problem for our benefit yet the variables you really used are not as implied here.

      Comment

      Working...
      X