Announcement

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

  • How To Count Identical Values As One Without Dropping

    Dear Stata Community,

    I'm trying to 'count the number of years each person attended the conference over the period of 20 years'. Datasets year's values are oftentimes repeated its because when a person attends the conference more than once a year. I tried 'collapse (count) Year, by (Attendance Persons)', however, as expected, the code is also counting the repeated years giving me more than 20 years of attendance for some of the people in the dataset. I would really appreciate if you could show me some guidance to fix the problem.

    This is my first post and I'm very new to the Stata. Please let me know if I'm being unclear.

    Thank you so much in advance.

    Best wishes,
    David

  • #2
    It would be easier if you had posted example data, but with the caveat that this may need some adaptation to work with what you have:

    Code:
    by Attendance Persons (year), sort: gen wanted = sum(year != year[_n-1])
    by Attendance Persons (year): replace wanted = wanted[_N]
    In the future, when asking for help with code, show example data, and please use the -dataex- command to do so. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Thank you for your response, very much appreciated !

      And thank you for your notes about my post, I will bear them in mind.

      Comment

      Working...
      X