Announcement

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

  • Reordering monthly data

    Hello,

    I have the below monthly data from a Stata output. As you can see there is an issue with the sequence ( 1, 10 ,11, 12, 2, 3, 4 , 5 , 6 , 7, 8, 9). Can anyone help me order the data in an an ascending order (M1-M12) taking in account the other variables (A, B, C)?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str7 month float a byte(b c)
    "2000M1"      56 32 29
    "2000M10"     23 41 77
    "2000M11"      5 74 64
    "2000M12"    -23 56 41
    "2000M2"   -48.5 65 30
    "2000M3"     -74 32 28
    "2000M4"   -99.5 39 30
    "2000M5"    -125 86  7
    "2000M6"  -150.5 32 82
    "2000M7"    -176 79 27
    "2000M8"      23 23 99
    "2000M9"      23 51 55
    "2001M1"       6 94 88
    "2001M10"      2 54 64
    "2001M11"      5 60 66
    "2001M12"     56 26 85
    "2001M2"    37.9 48 61
    "2001M3"    44.4 95 64
    "2001M4"    50.9 98 76
    "2001M5"    57.4 81 25
    "2001M6"    63.9 75 26
    "2001M7"    70.4 28 62
    "2001M8"    76.9 88 65
    "2001M9"       5 16 78
    "2002M1"      56 82 51
    "2002M10"   37.9 18 12
    "2002M11"   44.4 37 94
    "2002M12"   50.9 93 34
    "2002M2"    62.9 14 15
    "2002M3"   70.92 75 31
    "2002M4"   78.94 49 41
    "2002M5"   86.96 39 71
    "2002M6"   94.98 49 76
    "2002M7"     103 54 68
    "2002M8"  111.02 66 25
    "2002M9"  119.04 26 14
    "2003M1"  127.06 59 22
    "2003M10" 135.08 39 88
    "2003M11"  143.1 61 78
    "2003M12" 151.12 32 28
    "2003M2"  159.14 65 87
    "2003M3"  167.16 75 34
    "2003M4"  175.18 57 92
    "2003M5"   183.2 20 91
    "2003M6"      56 49 11
    "2003M7"      66 30 98
    "2003M8"      12  1 21
    "2003M9"      23 92 59
    end
    Thank you

  • #2
    currently your dates are strings which is not useful; you want to convert them to SiF (Stata Internal Format) dates; since these are monthly, see
    Code:
    help datetime##s3

    Comment


    • #3
      Rich Goldstein is bang on.


      Code:
      gen mdate = monthly(month, "YM")
      format mdate %tm 
      sort mdate
      is the kind of code you need.

      Comment


      • #4
        Thank you!

        Comment

        Working...
        X