Hello,
I have an unbalanced dataset from 1999 to 2019, but with gaps (not sure if it's important to mention).
I have a variable called public_dum which is equal to one if the individual works in the public sector, and 0 if he/she works in the private sector.
My goal is to count the number of individuals that goes from the private to the public sector over years. For simplicity, I would stop counting at the first occurrence (even if some individuals might switch several times).
So ideally, I would create a variable called switch that takes 1 if the individual switched (at least once) from private to public, and 0 if she/he has never switched.
I am not very experienced in Stata, and I have difficulty in starting it, so I would appreciate if someone could shed some lights on it.
Here is a subset of the three variables concerned:
I have an unbalanced dataset from 1999 to 2019, but with gaps (not sure if it's important to mention).
I have a variable called public_dum which is equal to one if the individual works in the public sector, and 0 if he/she works in the private sector.
Code:
tab public_dum public_dum | Freq. Percent Cum. ------------+----------------------------------- 0 | 8,816 82.65 82.65 1 | 1,851 17.35 100.00 ------------+----------------------------------- Total | 10,667 100.00
So ideally, I would create a variable called switch that takes 1 if the individual switched (at least once) from private to public, and 0 if she/he has never switched.
I am not very experienced in Stata, and I have difficulty in starting it, so I would appreciate if someone could shed some lights on it.
Here is a subset of the three variables concerned:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long idpers int year float public_dum 11101 1999 . 21101 2001 0 26102 1999 . 42101 2000 . 42101 2001 0 42101 2002 0 42101 2003 0 42101 2004 0 42101 2005 0 42101 2006 0 42101 2007 . 42101 2008 0 42101 2009 0 42101 2010 0 42101 2011 0 42101 2012 0 42101 2013 0 42101 2014 0 42101 2015 0 42101 2016 . 42101 2017 0 42102 2000 0 42102 2001 0 42102 2002 1 42102 2003 1 42102 2004 1 42102 2005 1 42102 2016 1 45101 1999 0 45101 2000 0 45101 2001 0 45101 2007 . 45101 2008 . 45101 2009 . 45101 2010 0 45101 2011 . 45101 2012 . 45101 2013 0 45101 2014 . 45101 2015 . 45101 2016 0 45101 2017 0 45101 2018 0 45102 1999 0 45102 2000 0 45102 2001 0 45102 2007 0 45102 2008 0 45102 2009 0 45102 2010 0 45102 2011 0 45102 2012 0 45102 2013 0 45102 2014 0 45102 2015 0 45102 2016 0 45102 2017 0 45102 2018 0 45102 2019 0 45103 2015 . 45103 2016 . 45103 2017 . 45103 2018 . 45103 2019 . 103101 1999 0 103101 2000 0 103101 2001 0 103101 2009 0 103101 2010 0 103104 2001 . 103104 2009 . 103104 2010 . 103104 2011 . 103104 2012 . 103104 2013 . 103104 2014 . 103105 2000 0 117101 1999 0 117101 2000 0 117101 2001 0 117101 2002 0 117101 2003 0 117101 2004 0 117101 2005 0 117101 2006 0 117101 2007 0 117101 2008 0 117101 2009 0 117101 2010 0 117101 2011 0 117101 2012 0 117101 2013 0 117101 2014 0 117101 2015 0 117101 2016 0 117101 2017 . 117101 2018 . 117102 1999 . 117102 2000 . 117102 2001 . end label values idpers IDPERS
Comment