Announcement

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

  • Finding out when same entity/unit changes codes across years

    Greetings Stata-user community,

    I have a thorn-in-my-side with a variable (sysschoolid) that may and can change across time for the same entity (schools; school2 variable); see data example below.

    The question I have is how to loop through the entire dataset to find out when the code changes for the same entity across time.
    I am sure there is a rather simple line or group of lines that can help.

    Thanks in advance,
    Saul

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str9 sysschoolid str40 school2 double year
    "601:103"  "appling county high school" 2006
    "601:103"  "appling county high school" 2007
    "601:103"  "appling county high school" 2008
    "601:103"  "appling county high school" 2009
    "601:103"  "appling county high school" 2010
    "601:103"  "appling county high school" 2011
    "601:103"  "appling county high school" 2012
    "601:103"  "appling county high school" 2013
    "601:103"  "appling county high school" 2014
    "601:103"  "appling county high school" 2015
    "601:103"  "appling county high school" 2016
    "601:103"  "appling county high school" 2017
    "601:103"  "appling county high school" 2018
    "601:103"  "appling county high school" 2019
    "601:103"  "appling county high school" 2020
    "601:2050" "appling county high school" 2004
    "601:2050" "appling county high school" 2005
    end

  • #2
    If I understand you correctly, there is no need for a loop; try this:
    Code:
    bys school2 (year): gen change=sys!=sys[_n-1] & _n>1

    Comment


    • #3
      Rich Goldstein Thanks for this!! This is indeed what I need. I now need to add a qualifier so that schools that were not in existence (or for which no data were collected) are not coded as changed...

      Comment

      Working...
      X