I am facing an issue that I am trying for a while. I want to create a dummy variable taking value 1 if the number in column year2 exists in the column year1 for each id. My logic was to use two loops. One through id and another through year2.
Second option I tried is where I create year dummies. Each time year1 dummy == year2 dummy, I mark it has a success. It did work, but it takes significantly longer time to run the program given that n-1 number of variables need to be created. Is there a simple solution to solve this problem?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id float(year1 year2) 365 1996 2006 365 1999 2006 365 2000 2006 365 2002 2006 365 2003 2006 365 2003 2010 365 2005 2006 365 2006 2009 365 2007 2010 365 2009 2009 365 2009 2010 365 2010 2010 365 2010 2011 365 2012 2012 365 2012 2013 365 2013 2013 end
0 Response to Looping in Stata
Post a Comment