I have a dataset consisitng of firms and employess in each year. I would like to create a variable "change".
If the surname in a given year is the same as in the previous year, then the variable is supposed to equal zero. Otherwise it is supposed to be equal to one.
Below is the end result I want to get (my input is in the same form, but of of course without the variable "change"). My question is, how to create this variable? It reminds me of a nested loop, but I'm not sure it's a good way...
Code:
firmno year surname change 1 2007 "Jones" "." 1 2007 "Taylor" "." 1 2007 "Brown" "." 1 2007 "Wilson" "." 1 2008 "Davies" "1" 1 2008 "Wright" "1" 1 2008 "Evans" "1" 1 2008 "Brown" "0" 1 2008 "Wilson" "0" 1 2009 "Roberts" "1" 1 2009 "Wood" "1" 1 2009 "Wright" "0" 2 2010 "Cox" "." 2 2010 "Ali" "." 2 2010 "Moore" "." 2 2011 "Doherty" "1" 2 2011 "Cox" "0" 2 2012 "Doherty" "0" 2 2012 "Cox" "0" 2 2012 "Thompson" "1" 2 2012 "Smyth" "1"
0 Response to problem with creating a variable
Post a Comment