Hello,
I want to create 2 variables based on the pre/post period of another variable (i.e., Breached_firm).
Specifically, I want to create a Pre_Breach variable which takes the value of 1 if a breach occured in the 3 years window leading up to the breach date (so if Breached_firm=1 in 2020, Pre_Breach is coded 1 for 2017, 2018, 2019).
Also, I want to create a Post_Breach variable which takes the value of 1 if a breach occured in the 3 years window following the breach date (so if Breached_firm=1 in 2020, Post_Breach is coded 1 for 2021, 2022 ,2023).
For example, for companyid 147 the breach happened in 2007, so the Pre_Breach would =1 in 2006, 2005 and 2004. And the Post_Breach=1 in 2008, 2009 and 2010.
P.S. I am using Stata/SE 16.0.
Thank you!
I want to create 2 variables based on the pre/post period of another variable (i.e., Breached_firm).
Specifically, I want to create a Pre_Breach variable which takes the value of 1 if a breach occured in the 3 years window leading up to the breach date (so if Breached_firm=1 in 2020, Pre_Breach is coded 1 for 2017, 2018, 2019).
Also, I want to create a Post_Breach variable which takes the value of 1 if a breach occured in the 3 years window following the breach date (so if Breached_firm=1 in 2020, Post_Breach is coded 1 for 2021, 2022 ,2023).
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int Year long companyid float Breached_firm 2019 55 0 2019 55 0 2019 55 0 2019 55 0 2019 55 0 2019 55 0 2019 55 0 2019 55 0 2019 55 0 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2007 147 1 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2008 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2009 147 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2008 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2010 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 2011 177 0 end
For example, for companyid 147 the breach happened in 2007, so the Pre_Breach would =1 in 2006, 2005 and 2004. And the Post_Breach=1 in 2008, 2009 and 2010.
P.S. I am using Stata/SE 16.0.
Thank you!
Comment