Announcement

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

  • Dealing with the date

    Hi,

    I have a dataset and when I try to convert the date into string it shows like this

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long datadate float Date
     8856  8856
     8947  8947
     9039  9039
     9131  9131
     9221  9221
     9312  9312
     9404  9404
     9496  9496
     9586  9586
     8856  8856
     8947  8947
     9039  9039
     9131  9131
     9251  9251
     9343  9343
     9435  9435
     9527  9527
     9616  9616
     9708  9708
     9800  9800
     9892  9892
     9981  9981
    10073 10073
    10165 10165
    10257 10257
    10347 10347
    10439 10439
    10531 10531
    10623 10623
    10712 10712
    10804 10804
    10896 10896
    10988 10988
    11077 11077
    11169 11169
    11261 11261
     8825  8825
     8917  8917
     9009  9009
     9100  9100
     9190  9190
     9282  9282
     9374  9374
     9465  9465
     9555  9555
     9647  9647
     9739  9739
     9830  9830
     9920  9920
    10012 10012
    10104 10104
    10195 10195
    10286 10286
    10378 10378
    10470 10470
    10561 10561
    10651 10651
    10743 10743
    10835 10835
    10926 10926
    11016 11016
    11108 11108
    11200 11200
    11291 11291
    11381 11381
    11473 11473
    11565 11565
    11656 11656
    11747 11747
    11839 11839
    11931 11931
    12022 12022
    12112 12112
    12204 12204
    12296 12296
    12387 12387
    12477 12477
    12569 12569
    12661 12661
    12752 12752
    12842 12842
    12934 12934
    13026 13026
    13117 13117
    13208 13208
    13300 13300
    13392 13392
    13483 13483
    13573 13573
    13665 13665
    13757 13757
    13848 13848
    13938 13938
    14030 14030
    14122 14122
    14213 14213
    14303 14303
    14395 14395
    14487 14487
    14578 14578
    end
    format %td datadate

    although in the ordinal variable it is like this 31jan1988. I need to create a new variable that will be string

  • #2
    Maybe the following code will be helpful:
    Code:
    gen str_datadate=strofreal(datadate,"%td")

    Comment


    • #3
      Chen Samulsion's advice in #2 will do what you ask. But may I ask why you want to do this? There are few things more useless in Stata than a string variable that reads like a date. You cannot do any calculations with it. You cannot even compare before-after with it. All you can do is list them out. And listing out can be done just as nicely with the numeric date variables having an appropriate display format applied, just like your variable datadate. So what do you hope to accomplish by converting to a string?

      Comment

      Working...
      X