Announcement

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

  • Translating run-together dates

    Dear all,

    Sorry for basic question. I would like to translate the following date into Stata date format.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 dscd str8 date
    "ID:AAL" "10101990"
    "ID:AAL" "10111990"
    "ID:AAL" "1011990" 
    "ID:AAL" "10121990"
    "ID:AAL" "10151990"
    "ID:AAL" "10161990"
    "ID:AAL" "10171990"
    "ID:AAL" "10181990"
    "ID:AAL" "10191990"
    "ID:AAL" "1021990" 
    "ID:AAL" "10221990"
    "ID:AAL" "10231990"
    "ID:AAL" "10241990"
    "ID:AAL" "1031990" 
    "ID:AAL" "1041990" 
    "ID:AAL" "1051990" 
    "ID:AAL" "1081990" 
    "ID:AAL" "1091990" 
    "ID:AAL" "1101990" 
    "ID:AAL" "11101989"
    "ID:AAL" "1111990" 
    "ID:AAL" "11131989"
    "ID:AAL" "11141989"
    "ID:AAL" "11151989"
    "ID:AAL" "11161989"
    "ID:AAL" "11171989"
    "ID:AAL" "111990"  
    "ID:AAL" "11201989"
    "ID:AAL" "11211989"
    "ID:AAL" "1121990" 
    end

    I tried both:
    Code:
     gen date2 = date(date, "MDY")
    format date2 %td
    and
    Code:
    numdate daily date3 = date, pattern(MDY)
    But both treat 1041990 (October 4 1990) and some others as missing. Could you please help? Thank you.



    Best regards,


  • #2
    How do you know whether, e.g., 1111990 is 11 january 1990 or 1 november 1990?

    Comment


    • #3
      You have some rogue dates in there. This may help, but inspect the protocol and results for incomplete dates very carefully.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str6 dscd str8 date
      "ID:AAL" "10101990"
      "ID:AAL" "10111990"
      "ID:AAL" "1011990"
      "ID:AAL" "10121990"
      "ID:AAL" "10151990"
      "ID:AAL" "10161990"
      "ID:AAL" "10171990"
      "ID:AAL" "10181990"
      "ID:AAL" "10191990"
      "ID:AAL" "1021990"
      "ID:AAL" "10221990"
      "ID:AAL" "10231990"
      "ID:AAL" "10241990"
      "ID:AAL" "1031990"
      "ID:AAL" "1041990"
      "ID:AAL" "1051990"
      "ID:AAL" "1081990"
      "ID:AAL" "1091990"
      "ID:AAL" "1101990"
      "ID:AAL" "11101989"
      "ID:AAL" "1111990"
      "ID:AAL" "11131989"
      "ID:AAL" "11141989"
      "ID:AAL" "11151989"
      "ID:AAL" "11161989"
      "ID:AAL" "11171989"
      "ID:AAL" "111990"  
      "ID:AAL" "11201989"
      "ID:AAL" "11211989"
      "ID:AAL" "1121990"
      end
      
      gen length = length(date)
      gen wanted = cond(length == 8, daily(date, "MDY"), cond(length == 7, daily("0" + date, "MDY"), cond(length == 6, daily("01" + date, "DMY"), .)))
      
      sort length wanted
      
      list date wanted length, sepby(length)
      
          +----------------------------+
           |     date   wanted   length |
           |----------------------------|
        1. |   111990    11262        6 |
           |----------------------------|
        2. |  1011990    10958        7 |
        3. |  1021990    10959        7 |
        4. |  1031990    10960        7 |
        5. |  1041990    10961        7 |
        6. |  1051990    10962        7 |
        7. |  1081990    10965        7 |
        8. |  1091990    10966        7 |
        9. |  1101990    10967        7 |
       10. |  1111990    10968        7 |
       11. |  1121990    10969        7 |
           |----------------------------|
       12. | 11101989    10906        8 |
       13. | 11131989    10909        8 |
       14. | 11141989    10910        8 |
       15. | 11151989    10911        8 |
       16. | 11161989    10912        8 |
       17. | 11171989    10913        8 |
       18. | 11201989    10916        8 |
       19. | 11211989    10917        8 |
       20. | 10101990    11240        8 |
       21. | 10111990    11241        8 |
       22. | 10121990    11242        8 |
       23. | 10151990    11245        8 |
       24. | 10161990    11246        8 |
       25. | 10171990    11247        8 |
       26. | 10181990    11248        8 |
       27. | 10191990    11249        8 |
       28. | 10221990    11252        8 |
       29. | 10231990    11253        8 |
       30. | 10241990    11254        8 |
           +----------------------------+
      Alternatively see https://www.stata-journal.com/articl...article=dm0062 for how to impute an unstated day of the month.
      Last edited by Nick Cox; 06 Nov 2021, 03:28.

      Comment

      Working...
      X