Announcement

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

  • Longitudinal data with cluster ID erroneously changing across time

    I have longitudinal data (3 waves), with clustering in school classes (and in a few schools as the third level). Unfortunately, the data collectors made an error when assigning class IDs: for some school classes, the class ID changes from one measurement occasion to the next. I do not know which school classes this problem applies to…

    I am planning to develop a procedure that identifies students who stay in one particular school class but have received a new class ID at a second measurement occasion -- and then give these students a single, common class ID, reflecting the actual clustering of the data over time. This should be possible since the problem applies to every student in the school class: whole groups of students should switch from a common class ID at one measurement occasion to a new, but still common class ID at the next measurement occasion. Since I am considering moving this form of data manipulation to Stata and have yet to develop a procedure, I thought I should ask here at Statalist.

    This is probably not an unknown problem, and with Stata’s advanced capabilities in data manipulation of survey data, maybe functions are available to fix this problem?

  • #2
    Cristopher:
    first, I would try something along the following lines:
    Code:
    . set obs 6
    Number of observations (_N) was 0, now 6.
    
    . g id=1 in 1/3
    
    
    . replace id=2 if id==.
    
    
    . g class=1 if id==1
    
    
    . replace class=_n-3 if id==2
    
    
    . list
    
         +------------+
         | id   class |
         |------------|
      1. |  1       1 |
      2. |  1       1 |
      3. |  1       1 |
      4. |  2       1 |
      5. |  2       2 |
         |------------|
      6. |  2       3 |
         +------------+
    
    . egen wanted=group(id class)
    
    . list
    
         +---------------------+
         | id   class   wanted |
         |---------------------|
      1. |  1       1        1 |
      2. |  1       1        1 |
      3. |  1       1        1 |
      4. |  2       1        2 |
      5. |  2       2        3 |
         |---------------------|
      6. |  2       3        4 |
         +---------------------+
    
    . bysort id: gen flag=0 if class[1]==class[_N]
    
    
    . bysort id: replace flag=1 if class[1]!=class[_N]
    
    
    . list
    
         +----------------------------+
         | id   class   wanted   flag |
         |----------------------------|
      1. |  1       1        1      0 |
      2. |  1       1        1      0 |
      3. |  1       1        1      0 |
      4. |  2       1        2      1 |
      5. |  2       2        3      1 |
         |----------------------------|
      6. |  2       3        4      1 |
         +----------------------------+
    
    .
    just to have an idea of the situation.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Grazie

      Comment

      Working...
      X