I have the following dataset. Year, city and variable. The variable changes infrequently. I would like to create another variable (variable_2) that tracks variable. Prior to a change in variable, the value of variable_2 will be 0 and after the change the value of variable_2 changes to 1. Here is the original data. year city variable 2000 Allen 5000 2001 Allen 5000 2002 Allen 5000 2003 Allen 5100 2004 Allen 5100 2005 Allen 5100 2000 Frisco 6300 2001 Frisco 6300 2002 Frisco 6000 2003 Frisco 6000 2004 Frisco 6000 2005 Frisco 6000 After the transformation year city variable Variable_2 2000 Allen 5000 0 2001 Allen 5000 0 2002 Allen 5000 0 2003 Allen 5100 1 2004 Allen 5100 1 2005 Allen 5100 1 2000 Frisco 6300 0 2001 Frisco 6300 0 2002 Frisco 6000 1 2003 Frisco 6000 1 2004 Frisco 6000 1 2005 Frisco 6000 1
... View more