Announcement

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

  • separate date into year and month

    Hello everyone,


    I want to separate one variable into two. My initial variable "h_m" which is built (YYYYMM) should be separated into two new variable "year" (YYYY) and a new variable "month" (MM)


    2nd question: I want to do this to merge data with year as key variable since the months differ. Is there a way to apply this to other datasets with the same h_m variable in one take?



    The variable is a type "double"
    Format %10.0g


    Since my data is huge I cannot use dataex and will add a screenshot :



    Thank you a lot for your help
    Attached Files

  • #2
    Since my data is huge I cannot use dataex and will add a screenshot :
    Not so!. The point of dataex is to provide an example, All you need to do is go

    Code:
    dataex h_m
    and show the results. Having a big dataset is a reason to use dataex, not a barrier to that. .

    That said, your question is fairly clear otherwise.

    Code:
    gen year = floor(h_m/100)
    gen month = mod(h_m, 100)
    should get you where you ask to be. But if you have similar variables in other datasets, you might as well merge using those; having separate variables, won't obviously make the task easier.

    Comment


    • #3
      Thank you the code you suggested worked perfectly!

      Comment

      Working...
      X