Announcement

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

  • Distinct occurrences of variable value within each individual in a panel

    The server I’m working on does not allow me to install -dataex-, so I apologize for the lack of standardized example!

    I’m working with a panel. I have individual-level purchase data from a chain of stores, and each person’s purchases were aggregated monthly. I have an id variable for each person (mvp_id) and an indicator variable for month (mthyr). I also have a variable that gives me the store ID where the person spent most money in each month (topstore1). I need to know how many people have (two or more) different top stores across the months in my dataset, versus how many people have the same top store across all months in my dataset.

  • #2
    Aline, after running the code below, you may tab diff_top_store. The number of zeros represents the number of people having the same top stores and the number of ones indicates that having different top stores.

    Code:
    bys mvp_id (topstore1): gen diff_top_store = topstore1[1]!=topstore1[_N] if _n == 1

    Comment


    • #3
      Code:
      by mvp_id (topstore1), sort: gen byte more_than_one_top_store = (topstore1[1] != topstore1[_N])
      Last edited by Clyde Schechter; 30 Aug 2022, 19:30.

      Comment


      • #4
        See https://www.stata.com/support/faqs/d...ions-in-group/ for the story here.

        Comment

        Working...
        X