Announcement

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

  • Converting month-year variable

    Hi all,

    I imported an excel sheet with dates like this: "2018m1" but they are in string format. I want them to look the same, but be in the Stata month-year format which is not a string, so I can merge to another file. Can you assist? Thanks!

    Code:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str7 moyr long households
    "2018m1"   959031
    "2018m2"   958444
    "2018m3"   958651
    "2018m4"   958143
    "2018m5"   958288
    "2018m6"   953940
    "2018m7"   952503
    "2018m8"   954430
    "2018m9"   953467
    "2018m10"  953070
    "2018m11"  949366
    "2018m12"  945533
    "2019m1"   945432
    "2019m2"    93193
    "2019m3"   939194
    "2019m4"   938729
    "2019m5"   937782
    "2019m6"   938895
    "2019m7"   941757
    "2019m8"   947660
    "2019m9"   943248
    "2019m10"  944514
    "2019m11"  943674
    "2019m12"  937337
    "2020m1"   938827
    "2020m2"   941031
    "2020m3"   942908
    "2020m4"   995550
    "2020m5"  1022787
    "2020m6"  1022331
    "2020m7"   995866
    "2020m8"   997132
    "2020m9"  1007323
    "2020m10"  999575
    "2020m11"  981517
    "2020m12"  784598
    "2021m1"   974113
    "2021m2"   970279
    "20201m3"  964654
    "2021m4"   962449
    "2021m5"   958318
    "2021m6"   954489
    "2021m7"   958633
    "2021m8"   965668
    "2021m9"   976812
    "2021m10"  976754
    "2021m11"  989208
    end

  • #2
    Code:
    gen int mdate = monthly(moyr, "YM")
    format mdate %tm

    Comment

    Working...
    X