Announcement

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

  • Identifying observations that changed from one year to the next

    I am not sure how to use dataex on this one, please forgive me. I have data that has individual observations over three school years. For example, each school has 3 separate observations, 1 for the year 17-18, one for 18-19, and one for 20-21. If they are a CEP school CEP = 1 and if not CEP = 0. The number of CEP schools doubled in this time period. I am trying to see if there are similarities in the schools that changed from 0 to 1in this time frame. I can usually find a starting point, but on this one I am stumped. I feel like this should be super simple, but I can't figure this one out. Thank you in advance.

  • #2
    Perhaps this example will start you in a useful direction. With three years and two possible values for CEP each year, there are only 8 possible patterns.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(school year cep)
    101 1 0
    101 2 0
    101 3 0
    102 1 1
    102 2 0
    102 3 0
    103 1 0
    103 2 1
    103 3 0
    104 1 1
    104 2 1
    104 3 0
    105 1 0
    105 2 0
    105 3 1
    106 1 1
    106 2 0
    106 3 1
    107 1 0
    107 2 1
    107 3 1
    108 1 1
    108 2 1
    108 3 1
    end
    // school changed cep
    bysort school (year): egen change = max(cep!=cep[_n-1] & _n>1)
    // school went from cep 0 to cep 1
    bysort school (year): egen from0to1 = max(cep==1 & cep[_n-1]==0)
    // school went from cep 1 to cep 0
    bysort school (year): egen from1to0 = max(cep==0 & cep[_n-1]==1)
    list, noobs sepby(school)
    Code:
    . list, noobs sepby(school)
    
      +----------------------------------------------------+
      | school   year   cep   change   from0to1   from1to0 |
      |----------------------------------------------------|
      |    101      1     0        0          0          0 |
      |    101      2     0        0          0          0 |
      |    101      3     0        0          0          0 |
      |----------------------------------------------------|
      |    102      1     1        1          0          1 |
      |    102      2     0        1          0          1 |
      |    102      3     0        1          0          1 |
      |----------------------------------------------------|
      |    103      1     0        1          1          1 |
      |    103      2     1        1          1          1 |
      |    103      3     0        1          1          1 |
      |----------------------------------------------------|
      |    104      1     1        1          0          1 |
      |    104      2     1        1          0          1 |
      |    104      3     0        1          0          1 |
      |----------------------------------------------------|
      |    105      1     0        1          1          0 |
      |    105      2     0        1          1          0 |
      |    105      3     1        1          1          0 |
      |----------------------------------------------------|
      |    106      1     1        1          1          1 |
      |    106      2     0        1          1          1 |
      |    106      3     1        1          1          1 |
      |----------------------------------------------------|
      |    107      1     0        1          1          0 |
      |    107      2     1        1          1          0 |
      |    107      3     1        1          1          0 |
      |----------------------------------------------------|
      |    108      1     1        0          0          0 |
      |    108      2     1        0          0          0 |
      |    108      3     1        0          0          0 |
      +----------------------------------------------------+

    Comment


    • #3
      Thank you so much!

      Comment

      Working...
      X