Announcement

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

  • Check if id is different for duplicate observations within group

    The setup is as in the example below. There are individuals (referenced by id) observed over time (referenced by t) who can have one or more jobs (jobid). The number of jobs is the number of rows per individual and time period and is available as a variable (jobs).

    I want to check whether for an individual with more than one job in a time period, the jobid's are also different. In the example below this is the case for id=1, but for id=2 it is not in t=2. There the person has two jobs but both have the id =1.


    Code:
    input id t jobid jobs
    1 1 1 2
    1 1 2 2
    1 2 1 2
    1 2 2 2
    2 1 1 1
    2 1 2 1
    2 2 1 2
    2 2 1 2
    end

  • #2
    Code:
    bys id t (jobid): gen wanted = jobid[1]!=jobid[_N]

    Comment


    • #3
      This is an FAQ https://www.stata.com/support/faqs/d...ions-in-group/

      Comment

      Working...
      X