Dear all,
I have a dummy variable, enact, which can only =1 once in the sample period. I want to create a "pseudo" dummy variable, enact1, which =1 in the year before the actual enact dummy =1. e.g., for firm 2, it has enact =1 in 2013, then enact1 should be =1 in 2012. I know this can be partly achieved by using the following code
One problem with this code is, my sample period is 2010-2019, and some firms have less than 10 years of observation. If a firm has enact =1 in 2010, and 2010 is the first year of the sample period for that firm, then the code above won't create the enact1 dummy, because I don't have 2009 for that firm. I wonder what code could help to create the year t-1 first, and then code enact1 =1 for that year. Thanks a lot in advance for any help!
Som sample data
I have a dummy variable, enact, which can only =1 once in the sample period. I want to create a "pseudo" dummy variable, enact1, which =1 in the year before the actual enact dummy =1. e.g., for firm 2, it has enact =1 in 2013, then enact1 should be =1 in 2012. I know this can be partly achieved by using the following code
Code:
bysort firm(year): gen enact1 = enact[_n+1] replace enact1=0 if enact1==.
Som sample data
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte firm float(year enact) 1 2010 1 1 2011 0 1 2012 0 1 2013 0 1 2014 0 1 2015 0 1 2016 0 1 2017 0 1 2018 0 1 2019 0 2 2010 0 2 2011 0 2 2012 0 2 2013 1 2 2014 0 2 2015 0 2 2016 0 2 2017 0 2 2018 0 2 2019 0 3 2014 1 3 2015 0 3 2016 0 3 2017 0 3 2018 0 3 2019 0 4 2011 1 4 2012 0 4 2013 0 4 2014 0 4 2015 0 4 2016 0 4 2017 0 4 2018 0 4 2019 0 end
Comment