I am trying to identify when an observation is a "new "occurrence in within a panel. I have read this FAQ document on identifying first and last occurrences in panel data (https://www.stata.com/support/faqs/d...t-occurrences/), but this is different from what I am looking to do. I have searched the forum and have thought quite a bit, but couldn't figure out how to accomplish what I want to do. I would greatly appreciate any help! Below is a hypothetical dataset to illustrate what I am trying to do.
Code:
id period category 1 1 gold 1 1 gold 1 2 gold 1 2 gold 1 3 gold 1 3 gold 1 3 silver 1 4 gold 1 4 gold 1 4 silver 2 1 gold 2 2 gold 2 3 gold 2 3 bronze 2 4 gold 2 4 bronze 2 4 copper 2 5 gold 2 5 bronze 2 5 copper
For each "id", I would like to identify whether an observation has "new" "category" that did not exist in prior periods emerges. For instance, for "id"==1, it has only one "category" (gold) appearing in "period" 1-2. In "period" 3 for "id"==1, there is now three observations, and here appears a new "category" silver. In "period" 4 for "id"==1, however, "category" silver is no longer new, because it appeared in "period" 3. I would like to identify such new occurrence of category (as in "period" 3 for "id"==1).
Similarly, for "id"==2, there is no new "category" until "period" 2. In "period" 3, "category" bronze is new (i.e., did not occur in prior "period" for "id"==2). In "period" 4, "category" bronze is no longer new, but "category" copper is new.
I hope the example data and my two examples above explain what I am trying to do. The difficulty that I am facing is that I do not know a priori what is a "new" category. For instance, if a "new" category is always silver, I think I can figure out the first period when category is equal to silver for each id. However, because there are many candidates for "new" categories, I cannot follow this methodology. The key point that I am struggling with is identifying a "new" value of a variable that did not exist in prior periods within a panel.
Thank you for reading my question, and I would really appreciate any thoughts/help/guidance on this issue.
0 Response to Finding "new" occurrences in panel data
Post a Comment