I have panel data that look like these first three columns below (state, year, length). I would like to generate the last column, the "switch" variable, where values become 1 when the length variable switches from 6 to 9. Any advice on how to do this? Many thanks in advance.

STATE YEAR LENGTH SWITCH
A 2003 6 0
A 2004 6 0
A 2005 9 1
A 2006 9 1