Dear Statlist,
A simple question this morning I think but one I have been struggling to answer (although I have found one very clunky solution). I am using panel data with employment status and I have been trying to generate a dummy variable of 1 for all observation of participants who have at least one instance of job loss during the duration of the panel.
The solution i have found is using the command below and just repeating it until there are no more changes. It's a solution but I would really appreciate a cleaner one.
Thanks for the help.
Kind Regards,
Hugo
A simple question this morning I think but one I have been struggling to answer (although I have found one very clunky solution). I am using panel data with employment status and I have been trying to generate a dummy variable of 1 for all observation of participants who have at least one instance of job loss during the duration of the panel.
The solution i have found is using the command below and just repeating it until there are no more changes. It's a solution but I would really appreciate a cleaner one.
Code:
gen jobloss_anypoint = 1 if jobloss == 1 replace jobloss_anypoint = 1 if jobloss[_n - 1] == 1 & _nomem_encr == _nomem_encr[_n - 1] replace jobloss_anypoint = 1 if jobloss[_n + 1] == 1 & _nomem_encr == _nomem_encr[_n + 1]
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double _nomem_encr float jobloss int _Year float jobloss_anypoint 800009 0 2008 . 800009 0 2009 . 800009 0 2010 . 800009 0 2011 . 800009 0 2012 . 800009 0 2013 . 800009 0 2014 . 800009 0 2015 . 800009 0 2016 . 800009 0 2017 . 800009 0 2018 . 800009 0 2019 . 800015 0 2008 . 800015 0 2009 . 800015 0 2010 . 800015 0 2011 . 800015 0 2012 . 800015 0 2013 . 800015 0 2014 . 800015 0 2015 . 800015 0 2016 . 800015 0 2017 . 800015 0 2018 . 800015 0 2019 . 800042 0 2008 . 800042 0 2009 . 800042 0 2010 . 800042 0 2011 . 800042 0 2012 . 800042 0 2013 . 800042 0 2014 . 800042 0 2015 . 800042 0 2016 . 800042 0 2017 . 800042 0 2018 . 800042 0 2019 . 800057 0 2008 . 800057 0 2009 . 800057 0 2010 . 800057 0 2011 . 800057 0 2012 . 800057 0 2013 . 800057 0 2014 . 800057 0 2015 . 800057 0 2016 . 800057 0 2017 . 800057 0 2018 . 800057 0 2019 . 800073 0 2015 . 800073 0 2016 . 800073 0 2017 . 800073 1 2018 1 800073 0 2019 . 800085 0 2008 . 800085 0 2009 . 800085 0 2010 . 800085 0 2011 . 800085 0 2012 . 800085 0 2013 . 800085 0 2014 . 800085 0 2015 . 800085 0 2016 . 800085 0 2017 . 800085 0 2018 . 800085 0 2019 . 800100 0 2008 . 800100 0 2009 . 800100 0 2010 . 800100 0 2011 . 800100 0 2012 . 800100 0 2013 . 800100 0 2014 . 800100 0 2015 . 800100 0 2016 . 800100 1 2017 1 800100 0 2018 . 800100 0 2019 . 800119 0 2008 . 800119 0 2009 . 800119 0 2010 . 800119 0 2011 . 800119 0 2012 . 800119 0 2013 . 800119 0 2014 . 800119 0 2015 . 800125 0 2008 . 800125 0 2009 . 800125 0 2010 . 800125 0 2011 . 800125 0 2012 . 800125 0 2013 . 800125 0 2014 . 800131 0 2008 . 800131 0 2009 . 800131 0 2010 . 800131 0 2011 . 800131 0 2012 . 800131 0 2013 . 800131 0 2014 . 800131 0 2015 . end format %ty _Year
Kind Regards,
Hugo
Comment