Announcement

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

  • converting business date format into normal %td format

    Dears,

    I have a dateset, and I calculated the business date. I want to change the format of these variables (b_begin_date and b_end_date) in order to merge with other dataset. When I change them (dd) by format dd %td the dates start with 1960s and so on.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 gvkey float(b_begin_date b_end_date dd)
    "001004"    .  499  499
    "001004"  500  562  562
    "001004"  563  636  636
    "001004"  637  692  692
    "001004"  693  750  750
    "001004"    .  894  894
    "001004"  895  943  943
    "001004"  944 1003 1003
    "001004" 1004 1066 1066
    "001004" 1067 1152 1152
    "001004" 1153 1196 1196
    "001004" 1197 1256 1256
    "001004" 1257 1320 1320
    "001004" 1321 1403 1403
    "001004" 1404 1448 1448
    "001004" 1449 1510 1510
    "001004" 1511 1564 1564
    "001004" 1565 1637 1637
    "001004" 1638 1700 1700
    "001004" 1701 1765 1765
    "001004" 1766 1826 1826
    "001004" 1827 1890 1890
    "001004" 1891 1956 1956
    "001004" 1957 2019 2019
    "001004" 2020 2081 2081
    "001004" 2082 2145 2145
    "001004" 2146 2208 2208
    "001004" 2209 2272 2272
    "001004" 2273 2335 2335
    "001004" 2336 2415 2415
    "001004" 2416 2459 2459
    "001004" 2460 2523 2523
    "001004" 2524 2587 2587
    "001004" 2588 2662 2662
    "001004" 2663 2715 2715
    "001004" 2716 2776 2776
    "001004" 2777 2837 2837
    "001004" 2838 2915 2915
    "001004" 2916 2963 2963
    "001004" 2964 3026 3026
    "001004" 3027 3091 3091
    "001004" 3092 3166 3166
    "001004" 3167 3220 3220
    "001004" 3221 3281 3281
    "001004" 3282 3343 3343
    "001004" 3344 3415 3415
    "001004" 3416 3468 3468
    "001004" 3469 3534 3534
    "001004" 3535 3595 3595
    "001004" 3596 3667 3667
    "001004" 3668 3723 3723
    "001004" 3724 3788 3788
    "001004" 3789 3847 3847
    "001004" 3848 3918 3918
    "001004" 3919 3975 3975
    "001004" 3976 4040 4040
    "001004" 4041 4101 4101
    "001004" 4102 4174 4174
    "001004" 4175 4232 4232
    "001004" 4233 4296 4296
    "001004" 4297 4356 4356
    "001004" 4357 4426 4426
    "001004" 4427 4483 4483
    "001004" 4484 4547 4547
    "001004" 4548 4607 4607
    "001004" 4608 4676 4676
    "001004" 4677 4739 4739
    "001004" 4740 4798 4798
    "001004" 4799 4864 4864
    "001004" 4865 4932 4932
    "001004" 4933 4984 4984
    "001004" 4985 5049 5049
    "001004" 5050 5109 5109
    "001004" 5110 5180 5180
    "001004" 5181 5239 5239
    "001004" 5240 5300 5300
    "001004" 5301 5360 5360
    "001004" 5361 5443 5443
    "001004" 5444 5493 5493
    "001004" 5494 5559 5559
    "001004" 5560 5620 5620
    "001004" 5621 5698 5698
    "001004" 5699 5747 5747
    "001004" 5748 5811 5811
    "001004" 5812 5871 5871
    "001004" 5872 5948 5948
    "001004" 5949 5997 5997
    "001004" 5998 6060 6060
    "001004" 6061 6121 6121
    "001004" 6122 6199 6199
    "001004" 6200 6250 6250
    "001004" 6251 6314 6314
    "001004" 6315 6375 6375
    "001004" 6376 6457 6457
    "001004" 6458 6506 6506
    "001004" 6507 6565 6565
    "001004" 6566 6626 6626
    "001004" 6627 6708 6708
    "001004" 6709 6753 6753
    "001004" 6754 6817 6817
    end
    format %tbbuscal b_begin_date
    format %tbbuscal b_end_date
    format %td dd


  • #2
    The business calendar and the Stata date variable calendar have different baselines. So you can't change one to the other by just changing the display format. When you just change the display format, it is like trying to convert Euros to Yen by just changing the currency symbols and not changing the numbers!

    You actually have to create new Stata date variables. Use the -dofb()- function to do that, and then format the new variables %td.
    Last edited by Clyde Schechter; 13 Feb 2024, 11:31.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      The business calendar and the Stata date variable calendar have different baselines. So you can't change one to the other by just changing the display format. When you just change the display format, it is like trying to convert Euros to Yen by just changing the currency symbols and not changing the numbers!

      You actually have to create new Stata date variables. Use the -dofb()- function to do that, and then format the new variables %td.
      Thanks in advance, I want only to create a variable that will have the same date in the business one, but have %td format. The screenshot is below. For instance, if the b_end_date is 22sep1988 is at %tbbuscal format. I need to creat a new variable have the same date but with %td format.
      Click image for larger version

Name:	Untitled.png
Views:	1
Size:	116.8 KB
ID:	1743121

      Comment


      • #4
        For the future, please read the Forum FAQ for excellent advice about the best way to post example data. Screenshots are usually not very helpful for several reasons. The most effective way to post example data is with the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

        That said, on the assumption that your business calendar's name is "buscal", the following is how you use the -dofb()- function:
        Code:
        gen end_date = dofb(b_end_date, "buscal")
        format end_date %td

        Comment

        Working...
        X