I have a dataset like below. "tiea"=1 means in a given year the company has a connection to the Senator "a", tiea=0 means the company has no connection to the Senator "a" in the given year. The same applies to Senator "b". Senator b replaced Senator a in the year 2004.
So, I wanted to create a new variable called "currenttie" which should be able to measure whether the company has a tie to the current Senator in any given year. For example, in year 2000 and 2001, the currenttie value should be 1, whereas in year 2002 and 2003 the currenttie value should be 0. After year 2004, the tie to Senator b became current. So the currenttie in 2004, 2006,2007 and 2008 has a value of 1.
Could you please show me how to generate the "currenttie" variable based on the tiea, tieb, and year variables? Thank you very much!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int year byte(tiea tieb currenttie) 2000 1 0 1 2001 1 0 1 2002 0 1 0 2003 0 0 0 2004 1 1 1 2005 0 0 0 2006 0 1 1 2007 0 1 1 2008 0 1 1 end
0 Response to How to generate a new variable based on existing variables
Post a Comment