Announcement

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

  • Turning a daily binary variable into a monthly one

    Dear Statalisters,
    I believe my question is very simple, yet I can't seem to find an answer. Please have a look at my data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double event float(d_date m_date)
    0 21915 720
    0 21916 720
    0 21917 720
    0 21918 720
    0 21919 720
    0 21920 720
    0 21921 720
    0 21922 720
    0 21923 720
    0 21924 720
    0 21925 720
    0 21926 720
    0 21927 720
    0 21928 720
    0 21929 720
    0 21930 720
    0 21931 720
    0 21932 720
    0 21933 720
    0 21934 720
    end
    format %td d_date
    format %tm m_date
    event is a binary variable that takes 1 if something happened during the date showed by d_date (a daily one). However, I do not need to be that precise and I would like to generate a new event variable in a way that the new variable takes value 1 if something happened during the monthly date (m_date). This will be useful for merging and regressing.

    I read the dates manual by using the help command but it does not seem I can change the timespan of a particular binary variable using a specific command. Does any of you have a solution?

    Thank you for your time.

    Julia

  • #2

    Code:
    egen wanted = max(event), by(m_date)
    If you have a identifier as well, that belongs in by() too.

    Comment


    • #3
      The code worked well. Thanks a lot!

      Comment

      Working...
      X