Dear All, I find this question here (https://bbs.pinggu.org/forum.php?mod...=1#pid56831974). The dataset is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long code str10 pubyear str79 vioyear
 4 "2013-06-06" "2010,2011,2012,2013"                    
 4 "2010-01-30" "2008,2009,2010"                         
 5 "2010-06-25" "2007,2008,2009"                         
 7 "2013-09-23" "2012,2013"                              
 7 "2014-08-28" "2011,2012,2013,2014"                    
 7 "2014-09-30" "2011,2012,2013,2014"                    
 7 "2015-05-26" "2014,2015"                              
 7 "2015-12-23" "2014"                                   
 7 "2015-03-24" "2014"                                   
 7 "2014-06-18" "2012,2013"                              
 7 "2016-02-26" "2014,2015"                              
 7 "2016-05-11" "2014,2015"                              
 9 "2011-05-09" "2010,2011"                              
10 "2011-11-30" "2003,2005,2007,2009,2010,2011"          
10 "2009-12-25" "2003,2004,2005,2006,2007,2008,2009"     
10 "2015-12-25" "2015"                                   
10 "2010-06-29" "2003,2004,2005,2006,2007,2008,2009,2010"
10 "2017-07-07" "2016"                                   
10 "2017-06-09" "2015,2016"                              
end
The purpose is, for each `code' (firm), to create a dummy of violation whenever the years appear in `pubyear' (announce different types of violations). For instance, code=4, the dummy variable should be equal to 1 if the years are 2008, 2009, 2010, 2011, 2012, 2013, 0 otherwise. when code=7, the dummy variable should be equal to 1 if the years 2011, 2012, 2013, 2014, 2015, 0 otherwise. Any suggestions?