Hello!
I want to generate a new variable which shows the sum of months (1-12) of unemployment from the time period 2001 to 2015 for each observation/person.
The variable should show the total duration of months a person was unemployed between 2001 and 2015, for example from 2001 to 2015 person xy was unemployed for 37 months in total.
Here an example of my data:
pid: personal identification number
syear: survey year, restricted to 2001 - 2015
arbeitslos_vorjahrmonate: shows the months a person was unemployed in the previous year,
e.g. pid 203 was unemployed in 2001 one month, in 2004 three months and in 2005 nine months.
So the new variable should show that pid 203 was in total 13 months unemployed from 2001-2015.
I tried with this command:
The new variable months1 should show this result only once (not for every survey year) so that I can sum the results.
However, when I'm browsing the results, the variable shows e.g. for pid 203 the 13 months in 2001, 2002, 2003, 2004... to 2015. So in every year, there are the 13 months which is wrong because I want this result only once and then sum the result of all persons.
Does anyone have a clue about how to handle this?
Thank you very much.
Regards
Tina
I want to generate a new variable which shows the sum of months (1-12) of unemployment from the time period 2001 to 2015 for each observation/person.
The variable should show the total duration of months a person was unemployed between 2001 and 2015, for example from 2001 to 2015 person xy was unemployed for 37 months in total.
Here an example of my data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int syear long pid float arbeitslos_vorjahrmonate 2001 201 . 2002 201 . 2003 201 . 2004 201 . 2005 201 . 2006 201 . 2007 201 . 2008 201 . 2009 201 . 2001 203 1 2002 203 . 2003 203 . 2004 203 3 2005 203 9 2006 203 . 2007 203 . 2008 203 . 2009 203 . 2001 601 . 2002 601 . 2003 601 . 2004 601 . 2001 602 . 2002 602 10 2003 602 12 2004 602 . 2005 602 . 2006 602 . 2007 602 . 2008 602 . 2009 602 . 2010 602 . 2011 602 . 2012 602 . 2013 602 . 2001 603 . 2002 603 . 2003 603 . 2004 603 . 2005 603 . 2006 603 . 2007 603 . 2008 603 . 2009 603 . 2010 603 . 2011 603 . 2012 603 . 2013 603 . 2001 604 . 2002 604 . 2003 604 . 2004 604 . 2005 604 . 2006 604 . 2007 604 . 2008 604 . 2009 604 . 2010 604 . 2011 604 . 2001 605 . 2002 605 . 2003 605 . 2004 605 . 2005 605 . 2006 605 . 2007 605 . 2008 605 . 2009 605 . 2010 605 . 2011 605 . 2012 605 . 2013 605 . 2001 901 . 2002 901 . 2003 901 . 2004 901 . 2005 901 . 2006 901 . 2007 901 . 2008 901 . 2009 901 . 2010 901 . 2011 901 . 2012 901 . 2013 901 . 2014 901 . 2015 901 . 2001 1202 . 2002 1202 . 2003 1202 . 2004 1202 . 2005 1202 . 2006 1202 . 2007 1202 . 2001 1501 . 2002 1501 . 2003 1501 . 2004 1501 . 2005 1501 . 2006 1501 . end
syear: survey year, restricted to 2001 - 2015
arbeitslos_vorjahrmonate: shows the months a person was unemployed in the previous year,
e.g. pid 203 was unemployed in 2001 one month, in 2004 three months and in 2005 nine months.
So the new variable should show that pid 203 was in total 13 months unemployed from 2001-2015.
I tried with this command:
Code:
bysort pid (syear): gen months=arbeitslos_vorjahrmonate if syear >2000 & syear <2016 bysort pid: egen months1=total(months),m
However, when I'm browsing the results, the variable shows e.g. for pid 203 the 13 months in 2001, 2002, 2003, 2004... to 2015. So in every year, there are the 13 months which is wrong because I want this result only once and then sum the result of all persons.
Does anyone have a clue about how to handle this?
Thank you very much.
Regards
Tina
Comment