Announcement

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

  • How to restrict my Panel Data Sample to Individuals with no Transitions in Panel Variable across waves

    Hi everyone,
    I am working with a panel data of individuals (pid) surveyed over 5 waves (unbalanced). My variable of interest is family which is a categorical variable (1"Married parents" 2"Divorced parents" 3"Cohabiting parents" 4"Single parents"). I have observed that individuals transition from one family state/category to another over waves. However, I want to restrict my sample to only consist of individuals(pid) whose family status/category has been constant across the 5 waves. Any idea on the code to use to achieve that please.


    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	37.1 KB
ID:	1677963




  • #2
    Code:
    egen tag = tag(pid family)
    egen total = total(tag), by(pid)
    keep if total == 1

    Comment


    • #3
      Thanks very much Øyvind Snilsberg. I can observe that the restricted sample also contains individuals (pid's) sampled only once across the waves. How can I exclude these from the sample so I could have only pids that were surveyed at least twice. I suppose this restriction is necessary for implementing panel data (fixed or random effects models).

      Comment


      • #4
        Code:
        by pid (family), sort: keep if family[1] == family[_N] & _N >= 2
        will accomplish both what you asked in #1 and in #3.

        In the future, when showing data examples, 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.


        Comment


        • #5
          Thank you very much Clyde. And thanks also for the information on dataex. I will use it in the future.

          Comment

          Working...
          X