Announcement

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

  • Summary stats for multilevel data

    Hello-
    I have a repeated measures dataset (long form). I would like to summarize a few basic characteristics of the data and cannot figure out how to do so.
    Example: Data are organized by Participant_ID and within Participant_ID are reporting_dates. I would like to get a unique count of reporting dates by participant.

    Participant_ID reporting_date
    ID_1 1-Jan
    ID_1 1-Jan
    ID_1 1-Jan
    ID_1 2-Jan
    ID_1 2-Jan
    ID_1 3-Jan
    ID_1 3-Jan
    ID_1 3-Jan
    ID_2 5-Feb
    ID_2 5-Feb
    ID_2 5-Feb
    ID_2 6-Feb
    ID_2 6-Feb
    ID_2 7-Feb
    ID_2 7-Feb
    ID_2 7-Feb
    ID_2 8-Feb
    ID_2 9-Feb
    ID_2 9-Feb
    I would like to create a new variable called Unique_dates so I can create a summary table like this:
    Participant_ID Unique_dates
    ID_1 3
    ID_2 5
    I am learning to work with repeated measures data in Stata, so any assistance is appreciated.

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5(participant_id reporting_date)
    "ID_1 " "1-Jan"
    "ID_1 " "1-Jan"
    "ID_1 " "1-Jan"
    "ID_1 " "2-Jan"
    "ID_1 " "2-Jan"
    "ID_1 " "3-Jan"
    "ID_1 " "3-Jan"
    "ID_1 " "3-Jan"
    "ID_2 " "5-Feb"
    "ID_2 " "5-Feb"
    "ID_2 " "5-Feb"
    "ID_2 " "6-Feb"
    "ID_2 " "6-Feb"
    "ID_2 " "7-Feb"
    "ID_2 " "7-Feb"
    "ID_2 " "7-Feb"
    "ID_2 " "8-Feb"
    "ID_2 " "9-Feb"
    "ID_2 " "9-Feb"
    end
    
    by participant_id (reporting_date), sort: gen unique_dates = ///
        sum(reporting_date != reporting_date[_n-1])
    by participant_id (reporting_date): replace unique_dates = unique_dates[_N]
    egen flag = tag(participant_id)
    list participant_id unique_dates if flag, noobs clean
    In the future, when showing data examples, please use the -dataex- command to do so, as I have done here. 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.

    Comment


    • #3
      Thank you for this information. I will be sure to do so in future posts.

      Comment

      Working...
      X