Announcement

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

  • Assigning Continuous number to year and months

    Hi all,

    I have date like this:

    date
    jan2015
    jan2015
    feb2015
    march2015
    march 2015
    march2015

    I want to create a variable that numbers them like this:

    date
    jan 2015 1
    jan2015 1
    feb2015 2
    march2015 3
    march2015 3
    march2015 3

    Can you help? Thanks!

  • #2
    If these are Stata year-month dates, then

    Code:
    egen wanted= group(date)

    Comment


    • #3
      As urged at FAQ Advice #12 using dataex is essential to clarify what kind of variables are being used. Data "like" this could be literal -- or not. You could have


      (1) a string variable

      (2) a numeric variable with value labels after a misguided encode (the worst of all worlds)

      (3) a numeric monthly date with a date display format, as optimistically guessed by Andrew Musau.

      I doubt the latter as (e.g.) jan2015 and march2015 would be using different display formats. If Andrew's guess at (3) is right, fine, but otherwise please follow https://www.statalist.org/forums/help#stata and use dataex to show us what you have.

      Comment

      Working...
      X