Announcement

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

  • how can can get stata to read date properly,

    Hello Stata experts;
    I 'm using the following data, and it should be ranging between 01Jan 1990- 3 May 2002, as you can see my dates are so missed up, and Stata not only sorting dates based on years, month, day, when I declare that my daten is my date variable, it says
    Sample: 03jan1960 thru 20jul1968

    can anyone tells me what is exactly the problem?


    thanks in advance
    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float dexjpus str10 date long daten float ret
    134.6 "1/10/1991"   2  -7.649313
    127.1 "1/10/1992"   3   -5.73333
    112.4 "1/10/1994"   4  -12.29102
    100.4 "1/10/1995"   5 -11.290173
    105.3 "1/10/1996"   6  4.7651224
    116.1 "1/10/1997"   7   9.763843
    105.3 "1/10/2000"   8  -9.763843
    116.3 "1/10/2001"   9   9.935964
    132.6 "1/10/2002"  10  13.116404
    145.4 "1/11/1990"  11    9.21514
    134.3 "1/11/1991"  12   -7.94124
    125.1 "1/11/1993"  13  -7.096272
    112.4 "1/11/1994"  14 -10.704946
     99.9 "1/11/1995"  15 -11.789425
    104.8 "1/11/1996"  16    4.78841
    108.8 "1/11/1999"  17   3.745756
    106.1 "1/11/2000"  18  -2.512933
    117.6 "1/11/2001"  19    10.2907
    132.2 "1/11/2002"  20  11.702688
    145.4 "1/12/1990"  21  9.5172615
    125.3 "1/12/1993"  22 -14.877764
    112.4 "1/12/1994"  23 -10.864694
     98.8 "1/12/1995"  24  -12.89663
    105.1 "1/12/1996"  25   6.181463
    132.8 "1/12/1998"  26    23.3932
    112.1 "1/12/1999"  27 -16.945293
    105.8 "1/12/2000"  28  -5.784077
    117.8 "1/12/2001"  29  10.743774
    126.9 "1/13/1992"  30   7.441109
      126 "1/13/1993"  31   -.711748
    111.9 "1/13/1994"  32 -11.867628
     98.8 "1/13/1995"  33   -12.4508
    116.4 "1/13/1997"  34  16.393492
    131.7 "1/13/1998"  35  12.349403
    113.5 "1/13/1999"  36 -14.872375
    106.1 "1/13/2000"  37  -6.742081
    135.1 "1/14/1991"  38  24.163326
    126.8 "1/14/1992"  39  -6.340423
    125.8 "1/14/1993"  40  -.7917697
    111.2 "1/14/1994"  41 -12.336302
    116.9 "1/14/1997"  42   4.998853
    131.4 "1/14/1998"  43  11.692718
    113.3 "1/14/1999"  44 -14.820686
    105.9 "1/14/2000"  45  -6.754393
    131.8 "1/14/2002"  46   21.87904
    135.9 "1/15/1991"  47   3.063363
    128.4 "1/15/1992"  48  -5.676893
    126.1 "1/15/1993"  49 -1.8075113
    117.2 "1/15/1997"  50  -7.319338
    130.4 "1/15/1998"  51  10.672475
    114.2 "1/15/1999"  52 -13.265533
    131.1 "1/15/2002"  53  13.800917
    145.5 "1/16/1990"  54  10.421565
    136.9 "1/16/1991"  55   -6.09254
    128.3 "1/16/1992"  56  -6.487939
    105.9 "1/16/1996"  57 -19.187603
    116.5 "1/16/1997"  58     9.5396
    128.9 "1/16/1998"  59   10.11456
    117.3 "1/16/2001"  60  -9.430208
    131.8 "1/16/2002"  61  11.655087
    145.5 "1/17/1990"  62   9.889044
    132.9 "1/17/1991"  63  -9.057917
    127.5 "1/17/1992"  64 -4.1480556
       99 "1/17/1995"  65  -25.29965
    105.4 "1/17/1996"  66    6.26428
    117.1 "1/17/1997"  67   10.52656
    118.4 "1/17/2001"  68  1.1040478
    132.1 "1/17/2002"  69  10.949052
    146.1 "1/18/1990"  70   10.07321
    132.8 "1/18/1991"  71   -9.54471
    110.8 "1/18/1994"  72 -18.111746
     99.6 "1/18/1995"  73 -10.656466
    105.4 "1/18/1996"  74    5.66005
    105.5 "1/18/2000"  75  .09483023
    117.8 "1/18/2001"  76  11.027735
    132.6 "1/18/2002"  77  11.834883
    145.7 "1/19/1990"  78   9.421257
    125.6 "1/19/1993"  79 -14.844745
    110.9 "1/19/1994"  80 -12.447333
     99.4 "1/19/1995"  81 -10.947678
    105.4 "1/19/1996"  82   5.861052
    113.8 "1/19/1999"  83    7.66799
    105.4 "1/19/2000"  84   -7.66799
    117.2 "1/19/2001"  85   10.61192
    146.3 "1/2/1990"   86   22.17775
    134.6 "1/2/1991"   87  -8.335187
    124.5 "1/2/1992"   88  -7.800175
    103.9 "1/2/1996"   89  -18.08768
    115.5 "1/2/1997"   90  10.584162
    132.4 "1/2/1998"   91  13.655706
    114.7 "1/2/2001"   92  -14.35076
      132 "1/2/2002"   93  14.048193
    124.9 "1/20/1993"  94  -5.528849
    111.6 "1/20/1994"  95  -11.25924
     99.4 "1/20/1995"  96  -11.57689
    128.8 "1/20/1998"  97   25.91087
    113.5 "1/20/1999"  98   -12.6458
    105.5 "1/20/2000"  99  -7.309188
    123.2 "1/21/1992" 100  15.509808
      125 "1/21/1993" 101   1.450471
    end
    format %td daten
    label values daten tt
    label def tt 2 "1/10/1991", modify
    label def tt 3 "1/10/1992", modify
    label def tt 4 "1/10/1994", modify
    label def tt 5 "1/10/1995", modify
    label def tt 6 "1/10/1996", modify
    label def tt 7 "1/10/1997", modify
    label def tt 8 "1/10/2000", modify
    label def tt 9 "1/10/2001", modify
    label def tt 10 "1/10/2002", modify
    label def tt 11 "1/11/1990", modify
    label def tt 12 "1/11/1991", modify
    label def tt 13 "1/11/1993", modify
    label def tt 14 "1/11/1994", modify
    label def tt 15 "1/11/1995", modify
    label def tt 16 "1/11/1996", modify
    label def tt 17 "1/11/1999", modify
    label def tt 18 "1/11/2000", modify
    label def tt 19 "1/11/2001", modify
    label def tt 20 "1/11/2002", modify
    label def tt 21 "1/12/1990", modify
    label def tt 22 "1/12/1993", modify
    label def tt 23 "1/12/1994", modify
    label def tt 24 "1/12/1995", modify
    label def tt 25 "1/12/1996", modify
    label def tt 26 "1/12/1998", modify
    label def tt 27 "1/12/1999", modify
    label def tt 28 "1/12/2000", modify
    label def tt 29 "1/12/2001", modify
    label def tt 30 "1/13/1992", modify
    label def tt 31 "1/13/1993", modify
    label def tt 32 "1/13/1994", modify
    label def tt 33 "1/13/1995", modify
    label def tt 34 "1/13/1997", modify
    label def tt 35 "1/13/1998", modify
    label def tt 36 "1/13/1999", modify
    label def tt 37 "1/13/2000", modify
    label def tt 38 "1/14/1991", modify
    label def tt 39 "1/14/1992", modify
    label def tt 40 "1/14/1993", modify
    label def tt 41 "1/14/1994", modify
    label def tt 42 "1/14/1997", modify
    label def tt 43 "1/14/1998", modify
    label def tt 44 "1/14/1999", modify
    label def tt 45 "1/14/2000", modify
    label def tt 46 "1/14/2002", modify
    label def tt 47 "1/15/1991", modify
    label def tt 48 "1/15/1992", modify
    label def tt 49 "1/15/1993", modify
    label def tt 50 "1/15/1997", modify
    label def tt 51 "1/15/1998", modify
    label def tt 52 "1/15/1999", modify
    label def tt 53 "1/15/2002", modify
    label def tt 54 "1/16/1990", modify
    label def tt 55 "1/16/1991", modify
    label def tt 56 "1/16/1992", modify
    label def tt 57 "1/16/1996", modify
    label def tt 58 "1/16/1997", modify
    label def tt 59 "1/16/1998", modify
    label def tt 60 "1/16/2001", modify
    label def tt 61 "1/16/2002", modify
    label def tt 62 "1/17/1990", modify
    label def tt 63 "1/17/1991", modify
    label def tt 64 "1/17/1992", modify
    label def tt 65 "1/17/1995", modify
    label def tt 66 "1/17/1996", modify
    label def tt 67 "1/17/1997", modify
    label def tt 68 "1/17/2001", modify
    label def tt 69 "1/17/2002", modify
    label def tt 70 "1/18/1990", modify
    label def tt 71 "1/18/1991", modify
    label def tt 72 "1/18/1994", modify
    label def tt 73 "1/18/1995", modify
    label def tt 74 "1/18/1996", modify
    label def tt 75 "1/18/2000", modify
    label def tt 76 "1/18/2001", modify
    label def tt 77 "1/18/2002", modify
    label def tt 78 "1/19/1990", modify
    label def tt 79 "1/19/1993", modify
    label def tt 80 "1/19/1994", modify
    label def tt 81 "1/19/1995", modify
    label def tt 82 "1/19/1996", modify
    label def tt 83 "1/19/1999", modify
    label def tt 84 "1/19/2000", modify
    label def tt 85 "1/19/2001", modify
    label def tt 86 "1/2/1990", modify
    label def tt 87 "1/2/1991", modify
    label def tt 88 "1/2/1992", modify
    label def tt 89 "1/2/1996", modify
    label def tt 90 "1/2/1997", modify
    label def tt 91 "1/2/1998", modify
    label def tt 92 "1/2/2001", modify
    label def tt 93 "1/2/2002", modify
    label def tt 94 "1/20/1993", modify
    label def tt 95 "1/20/1994", modify
    label def tt 96 "1/20/1995", modify
    label def tt 97 "1/20/1998", modify
    label def tt 98 "1/20/1999", modify
    label def tt 99 "1/20/2000", modify
    label def tt 100 "1/21/1992", modify
    label def tt 101 "1/21/1993", modify
    ------------------ copy up to and including the previous line ------------------


  • #2
    Oh~ it's a misapplication of -encode-, my favorite Stata horror sub-genre!

    First, keep the date as string, we'd convert that into a number that Stata understands without using -encode-. The command -encode- assigns a number to the string in their ascending order. It has nothing to do with making it a Stata-readable date.

    Code:
    * Drop daten
    drop daten
    * Create a numeric date:
    gen date2 = date(date, "MDY")
    * Format this with %td instead:
    format %td date2
    
    list in 1/10, sep(0)
    Results:
    Code:
         +---------------------------------------------+
         | dexjpus        date         ret       date2 |
         |---------------------------------------------|
      1. |   134.6   1/10/1991   -7.649313   10jan1991 |
      2. |   127.1   1/10/1992    -5.73333   10jan1992 |
      3. |   112.4   1/10/1994   -12.29102   10jan1994 |
      4. |   100.4   1/10/1995   -11.29017   10jan1995 |
      5. |   105.3   1/10/1996    4.765122   10jan1996 |
      6. |   116.1   1/10/1997    9.763843   10jan1997 |
      7. |   105.3   1/10/2000   -9.763843   10jan2000 |
      8. |   116.3   1/10/2001    9.935964   10jan2001 |
      9. |   132.6   1/10/2002     13.1164   10jan2002 |
     10. |   145.4   1/11/1990     9.21514   11jan1990 |
         +---------------------------------------------+

    Comment


    • #3
      Perfect, Thank you Sir

      Comment

      Working...
      X