Announcement

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

  • Decode date to change format

    Dear statlist,



    Please find the data hereafter

    I have a list of companies with different dates and I like to change the format from MDY to DMY;
    When I use the following code :
    gen new_date=date( Date , "DMY")

    I have the following error :

    type mismatch
    r(109),

    So i try to put the data in string (since it's numeric) with the following code:
    . decode Date, gen DATE

    But i have the error here :

    Date not labeled
    r(182);

    When I use the following code

    la variable Date Date

    It doesn't work, the variable seem to be labelled but I still cant encode the variable

    I think I don't manage to label my variable.
    My final purpose is to have the variable date in format DD/MM/YYYY



    Here is the data I am using:



    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(NOMBRE Company Date) double PRICE str58 Name str12 ISIN
    1 1 17304 15.8 "MICROPOLE - PRICE INDEX" "FR0000077570"
    2 1 17307 15.2 "MICROPOLE - PRICE INDEX" "FR0000077570"
    3 1 17308 15.2 "MICROPOLE - PRICE INDEX" "FR0000077570"
    4 1 17309 15.1 "MICROPOLE - PRICE INDEX" "FR0000077570"
    5 1 17310 15.1 "MICROPOLE - PRICE INDEX" "FR0000077570"
    6 1 17311 15.1 "MICROPOLE - PRICE INDEX" "FR0000077570"
    7 1 17314 15.1 "MICROPOLE - PRICE INDEX" "FR0000077570"
    8 1 17315 15.4 "MICROPOLE - PRICE INDEX" "FR0000077570"
    9 1 17316 15.4 "MICROPOLE - PRICE INDEX" "FR0000077570"
    10 1 17317 15.2 "MICROPOLE - PRICE INDEX" "FR0000077570"
    11 1 17318 14.8 "MICROPOLE - PRICE INDEX" "FR0000077570"
    12 1 17321 15 "MICROPOLE - PRICE INDEX" "FR0000077570"
    --more--


    Thanks a lot for your answer,
    Best regards






  • #2
    Your date variable is numeric and looks fine to me. For example, 17304 is 18 May 2007, for example.

    Code:
    . di %td 17304
    18may2007
    As it's numeric date() is, as you found, wrong and all the other ideas -- decode, encode, label -- are off target too. .

    All you need, I think, is

    Code:
    format date . %tdDD/NN/CCYY
    and then daily dates will be shown as you wish.

    Comment


    • #3
      your Date variable is already numeric and already in SIF; you appear to want to do
      Code:
      format Date %tdDD/NN/CCYY
      in general, see
      Code:
      help datetime_display_formats

      Comment

      Working...
      X