Announcement

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

  • year month date

    Hi all:
    i hope all of you have wonderful holidays!. I have a question about generating year-month data. below is the sample. the first column is year and the second column is month. i want to generate year-month data like 181601, or 181612.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    year  month
    1816  1
    1816  2
    1816  3
    1816  4
    1816  5
    1816  6
    1816  7
    1816  8
    1816  9
    1816 10
    1816 11
    1816 12
    end
    However, what i found so far generate data like this: "1816m1". This is the code:
    Code:
    gen modate = ym(year, month) 
    format modate %tm
    Can anyone help me on this? Thanks in advance.
    Best
    Jiong
    ------------------

  • #2
    It's not entirely clear what type of data (date-time variable type) that you want, but the following gives you a display of "monthly date" values (months since January 1960) like what you say you want.

    .ÿ
    .ÿquietlyÿinputÿintÿyearÿbyteÿmonth

    .ÿ
    .ÿgenerateÿintÿmodateÿ=ÿym(year,ÿmonth)

    .ÿformatÿmodateÿ%tmCYN

    .ÿ
    .ÿlist,ÿnoobsÿseparator(0)

    ÿÿ+-----------------------+
    ÿÿ|ÿyearÿÿÿmonthÿÿÿmodateÿ|
    ÿÿ|-----------------------|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ1ÿÿÿ181601ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ2ÿÿÿ181602ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ3ÿÿÿ181603ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ4ÿÿÿ181604ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ5ÿÿÿ181605ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ6ÿÿÿ181606ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ7ÿÿÿ181607ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ8ÿÿÿ181608ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿÿ9ÿÿÿ181609ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿ10ÿÿÿ181610ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿ11ÿÿÿ181611ÿ|
    ÿÿ|ÿ1816ÿÿÿÿÿÿ12ÿÿÿ181612ÿ|
    ÿÿ+-----------------------+

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .

    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      It's not entirely clear what type of data (date-time variable type) that you want, but the following gives you a display of "monthly date" values (months since January 1960) like what you say you want.

      .ÿ
      .ÿquietlyÿinputÿintÿyearÿbyteÿmonth

      .ÿ
      .ÿgenerateÿintÿmodateÿ=ÿym(year,ÿmonth)

      .ÿformatÿmodateÿ%tmCYN

      .ÿ
      .ÿlist,ÿnoobsÿseparator(0)

      ÿÿ+-----------------------+
      ÿÿ|ÿyearÿÿÿmonthÿÿÿmodateÿ|
      ÿÿ|-----------------------|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ1ÿÿÿ181601ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ2ÿÿÿ181602ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ3ÿÿÿ181603ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ4ÿÿÿ181604ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ5ÿÿÿ181605ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ6ÿÿÿ181606ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ7ÿÿÿ181607ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ8ÿÿÿ181608ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿÿ9ÿÿÿ181609ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿ10ÿÿÿ181610ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿ11ÿÿÿ181611ÿ|
      ÿÿ|ÿ1816ÿÿÿÿÿÿ12ÿÿÿ181612ÿ|
      ÿÿ+-----------------------+

      .ÿ
      .ÿexit

      endÿofÿdo-file


      .
      Thanks, Joseph. That's exactly what i want! I appreciate it.

      Comment

      Working...
      X