Announcement

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

  • Extracting the year from a variable in stata

    Hello,
    I probably have a very simple query but I can't work out how to solve it
    I have a variable entitled 'y_m_delivery' which is a numeric variable example 199906, I want to create a new variable taking out the month out so that I am only left with the year i.e remove the 06 so it leaves 1999. I have tried
    gen year = year (y_m_delivery)
    but this does not work
    Any help gratefully received
    thanks

  • #2
    Code:
    gen year = floor(y_m_delivery/100)
    The year() function extracts calendar year from a Stata daily date, which is not what you have.

    Comment


    • #3
      ok thanks Nick - any idea how I can extract just the year then from my variable?

      Comment


      • #4
        Already answered: see the code given.

        Comment


        • #5
          Brilliant that worked - thanks so much
          Sarah

          Comment

          Working...
          X