Announcement

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

  • Missing day and months for date

    I have a date variable date1 (in format dmy) with some missing day and month. I want to replace any date with missing day with 1st of the month and dates with missing day and month with 1st of January. Will be grateful for suggestion on this.

    Thanks very much.

  • #2
    Please give us a data example. https://www.statalist.org/forums/help#stata

    Comment


    • #3
      Thank you ver much Nick. Please below is an example data. Want to create date2. Thanks very much




      date1 date2
      09/12/2011. 09dec2011
      24/09/1985. 24sep1985
      12/1991 01dec1991
      1984 01jan1984
      Last edited by Naa Naadu; 17 Aug 2021, 06:15.

      Comment


      • #4
        The link given in #2 asked that you use dataex. What you show is helpful but still requires surgery to be very helpful.

        This works with your example.

        Code:
        clear 
        input str10 date1 
        "09/12/2011"
        "24/09/1985"
        "12/1991"
        "1984" 
        end 
        
        gen wanted = daily(date1, "DMY") 
        replace wanted = dofm(monthly(date1, "MY")) if missing(wanted)
        replace wanted = mdy(1, 1, real(date1)) if missing(wanted)
        
        format wanted %td 
        
        list
        Code:
             +------------------------+
             |      date1      wanted |
             |------------------------|
          1. | 09/12/2011   09dec2011 |
          2. | 24/09/1985   24sep1985 |
          3. |    12/1991   01dec1991 |
          4. |       1984   01jan1984 |
             +------------------------+


        Comment


        • #5
          Thank you very much, Nick. it worked.

          Comment

          Working...
          X