Announcement

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

  • is there any way to align the date format?

    Hi

    I have two sets of dates in my dataset, but they are importing as different types.

    "NamesDate" shows as "1/2/2013" but when I select the cell in the data editor, it appears as "01jan2013".
    "EventDate" shows as 6/23/2014 and shows as the same when selected.
    Click image for larger version

Name:	Screenshot 2024-04-19 at 13.06.13.png
Views:	1
Size:	32.5 KB
ID:	1750551
    Click image for larger version

Name:	Screenshot 2024-04-19 at 13.06.01.png
Views:	1
Size:	34.1 KB
ID:	1750552



    I have tried changing the format, but it puts "00/2/2013"

    I am trying to run the code below but am met with "type mismatch" error.
    Code:
    by CompanyID: gen target=datenum if NamesDate == EventDate

  • #2
    You're trying to get a string variable and a numeric variable to show in similar fashion. There are various ways to do that, but the best is almost certainly to take your string variable and map it to a numeric date variable. To get best advice, please copy and paste the results of

    Code:
    dataex NamesDate EventDate
    as explained at https://www.statalist.org/forums/help#stata

    Comment


    • #3
      I get the results

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input int NamesDate str10 EventDate
      19360 " 6/23/2014"
      19361 " 6/23/2014"
      19362 " 6/23/2014"
      19365 " 6/23/2014"
      19366 " 6/23/2014"
      19367 " 6/23/2014"
      19368 " 6/23/2014"
      19369 " 6/23/2014"
      19372 " 6/23/2014"
      19373 " 6/23/2014"
      19374 " 6/23/2014"
      19375 " 6/23/2014"
      19376 " 6/23/2014"
      19380 " 6/23/2014"
      19381 " 6/23/2014"
      19382 " 6/23/2014"
      19383 " 6/23/2014"
      19386 " 6/23/2014"
      19387 " 6/23/2014"
      19388 " 6/23/2014"
      19389 " 6/23/2014"
      19390 " 6/23/2014"
      19393 " 6/23/2014"
      19394 " 6/23/2014"
      19395 " 6/23/2014"
      19396 " 6/23/2014"
      19397 " 6/23/2014"
      19400 " 6/23/2014"
      19401 " 6/23/2014"
      19402 " 6/23/2014"
      19403 " 6/23/2014"
      19404 " 6/23/2014"
      19408 " 6/23/2014"
      19409 " 6/23/2014"
      19410 " 6/23/2014"
      19411 " 6/23/2014"
      19414 " 6/23/2014"
      19415 " 6/23/2014"
      19416 " 6/23/2014"
      19417 " 6/23/2014"
      19418 " 6/23/2014"
      19421 " 6/23/2014"
      19422 " 6/23/2014"
      19423 " 6/23/2014"
      19424 " 6/23/2014"
      19425 " 6/23/2014"
      19428 " 6/23/2014"
      19429 " 6/23/2014"
      19430 " 6/23/2014"
      19431 " 6/23/2014"
      19432 " 6/23/2014"
      19435 " 6/23/2014"
      19436 " 6/23/2014"
      19437 " 6/23/2014"
      19438 " 6/23/2014"
      19439 " 6/23/2014"
      19442 " 6/23/2014"
      19443 " 6/23/2014"
      19444 " 6/23/2014"
      19445 " 6/23/2014"
      19449 " 6/23/2014"
      19450 " 6/23/2014"
      19451 " 6/23/2014"
      19452 " 6/23/2014"
      19453 " 6/23/2014"
      19456 " 6/23/2014"
      19457 " 6/23/2014"
      19458 " 6/23/2014"
      19459 " 6/23/2014"
      19460 " 6/23/2014"
      19463 " 6/23/2014"
      19464 " 6/23/2014"
      19465 " 6/23/2014"
      19466 " 6/23/2014"
      19467 " 6/23/2014"
      19470 " 6/23/2014"
      19471 " 6/23/2014"
      19472 " 6/23/2014"
      19473 " 6/23/2014"
      19474 " 6/23/2014"
      19477 " 6/23/2014"
      19478 " 6/23/2014"
      19479 " 6/23/2014"
      19480 " 6/23/2014"
      19481 " 6/23/2014"
      19484 " 6/23/2014"
      19485 " 6/23/2014"
      19486 " 6/23/2014"
      19487 " 6/23/2014"
      19488 " 6/23/2014"
      19491 " 6/23/2014"
      19492 " 6/23/2014"
      19493 " 6/23/2014"
      19494 " 6/23/2014"
      19495 " 6/23/2014"
      19498 " 6/23/2014"
      19499 " 6/23/2014"
      19500 " 6/23/2014"
      19501 " 6/23/2014"
      19502 " 6/23/2014"
      end
      format %tdnn/dd/CCYY NamesDate

      Comment


      • #4
        Thanks for the data example. It's puzzling because the dates are already shown similarly, but here is some technique:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input int NamesDate str10 EventDate
        19360 " 6/23/2014"
        19361 " 6/23/2014"
        19362 " 6/23/2014"
        19365 " 6/23/2014"
        19366 " 6/23/2014"
        19367 " 6/23/2014"
        19368 " 6/23/2014"
        19369 " 6/23/2014"
        19372 " 6/23/2014"
        19373 " 6/23/2014"
        19374 " 6/23/2014"
        19375 " 6/23/2014"
        19376 " 6/23/2014"
        19380 " 6/23/2014"
        end
        
        gen EventDate2 = daily(EventDate, "MDY")
        format %tdnn/dd/CCYY NamesDate EventDate2 
        
        list 
        
        
        
             +------------------------------------+
             | NamesDate    EventDate   EventDa~2 |
             |------------------------------------|
          1. |  1/2/2013    6/23/2014   6/23/2014 |
          2. |  1/3/2013    6/23/2014   6/23/2014 |
          3. |  1/4/2013    6/23/2014   6/23/2014 |
          4. |  1/7/2013    6/23/2014   6/23/2014 |
          5. |  1/8/2013    6/23/2014   6/23/2014 |
             |------------------------------------|
          6. |  1/9/2013    6/23/2014   6/23/2014 |
          7. | 1/10/2013    6/23/2014   6/23/2014 |
          8. | 1/11/2013    6/23/2014   6/23/2014 |
          9. | 1/14/2013    6/23/2014   6/23/2014 |
         10. | 1/15/2013    6/23/2014   6/23/2014 |
             |------------------------------------|
         11. | 1/16/2013    6/23/2014   6/23/2014 |
         12. | 1/17/2013    6/23/2014   6/23/2014 |
         13. | 1/18/2013    6/23/2014   6/23/2014 |
         14. | 1/22/2013    6/23/2014   6/23/2014 |
             +------------------------------------+

        Comment

        Working...
        X