Announcement

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

  • Convert date into end of month date format

    Hi,
    How can I convert the following date format into end-of-month format?
    date
    192607
    192608
    192609
    192610
    192611
    192612
    192701
    192702
    192703
    192704
    192705
    192706
    192707
    192708
    192709
    192710
    192711
    192712
    192801
    192802
    192803
    192804
    192805
    192806
    192807
    192808
    192809
    192810

    I want the date to look like below:
    date
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980
    31dec1980

    Thanks








  • #2
    What is the unit of the first list? They span through 203 units but ended up in one month? Also, 192607, if in days, is May 4th of 2487, not 1980. There could be date conversion problem that needs to be fixed first.

    As for the actual problem, see https://journals.sagepub.com/doi/10....36867X19874247.

    Code:
    gen mos = mofd(date)
    gen wanted = dofm(mos + 1) - 1
    format wanted %td

    Comment


    • #3
      Also, if you are using version 17 or 18, there is the -lastdayofmonth()- function:
      Code:
      gen wanted = lastdayofmonth(date)

      Comment

      Working...
      X