I want to get the variable of the number of "Past" recession work experience
co_start_date is lifetime career start date, co_end_date is lifetime career end date (CEO 's total career year in his lifetime from co_start_date to co_end_date ; this career is from different firms)
YEAR GVKEY EXECID co_start_date co_end_date
2000 5680 04970 01jan1997 01jan2006
2001 5681 04970 01jan1997 01jan2006
2002 5680 04970 01jan1997 10may2006
2003 24668 04970 01jan1997 10may2006
2004 10920 04970 01jan1997 10may2006
2005 184748 04970 01jan1997 10may2006
2006 8479 04970 01jan1997 10may2006
YEAR GVKEY EXECID co_start_date co_end_date
2002 4598 00016 01mar1955 01oct1994
2003 157415 00016 01mar1955 01oct1994
2004 10920 00016 01mar1955 01oct1994
From example above, CEO id of EXECID 04970 worked in her whole life since 01jan1997 to 10may2006 from 5 different companies (GVKEY)
CEO id of 04970 worked in her whole life since 01mar1955 to 01oct1994 from 3 different companies (GVKEY)
I first want to change career end date (co_end_date) at each YEAR as below.
For ceo id EXECID 04970, I change the co_end_date as the first date of Current calendar year since CEO have worked till the current Year, his lifetime career end date is beyond the current year)
YEAR GVKEY EXECID co_start_date co_end_date
2000 5680 04970 01jan1997 01jan2000
2001 5681 04970 01jan1997 01jan2001
2002 5683 04970 01jan1997 01jan2002
2003 24668 04970 01jan1997 01jan2003
2004 10920 04970 01jan1997 01jan2004
2005 184748 04970 01jan1997 01jan2005
2006 8479 04970 01jan1997 10may2006
For ceo id EXECID 00016, since co_end_date is before YEAR (CEO's career already ended before current YEAR), I do not change and leave as it is.
YEAR GVKEY EXECID co_start_date co_end_date
2002 4598 00016 01mar1955 01oct1994
2003 157415 00016 01mar1955 01oct1994
2004 10920 00016 01mar1955 01oct1994
I want the value of n_recessions_worked of 04970
the value of n_recessions_worked in 2000 is 1 (recession range of 12 before 2000)
the value of n_recessions_worked in 2001 is 1 (recession range of 12 before 2001; current year is 2001 thus does not count the starting year of recession 13;
Do NOT count if starting of recession range year is equal current year since i'm looking at "PAST" recession experience )
the value of n_recessions_worked in 2002 is 2 (recession range of 12 and recession 13 before 2002)
...
the value of n_recessions_worked in 2007 is 2
the value of n_recessions_worked in 2008 is 3 (recession range of 12, 13, 14 before 2008)
...
...
the value of n_recessions_worked in 2011 is 3
LISTS of RECESSIONS:
local recession1 August 1929 March 1933
local recession2 May 1937 June 1938
local recession3 February 1945 October 1945
local recession4 November 1948 October 1949
local recession5 July 1953 May 1954
local recession6 August 1957 April 1958
local recession7 April 1960 February 1961
local recession8 December 1969 November 1970
local recession9 November 1973 March 1975
local recession10 January 1980 July 1980
local recession11 July 1981 November 1982
local recession12 July 1990 March 1991
local recession13 March 2001 November 2001
local recession14 December 2007 June 2009
local recession15 February 2020 April 2020
could you please revise previous code to get the value of n_recessions_work?
co_start_date is lifetime career start date, co_end_date is lifetime career end date (CEO 's total career year in his lifetime from co_start_date to co_end_date ; this career is from different firms)
YEAR GVKEY EXECID co_start_date co_end_date
2000 5680 04970 01jan1997 01jan2006
2001 5681 04970 01jan1997 01jan2006
2002 5680 04970 01jan1997 10may2006
2003 24668 04970 01jan1997 10may2006
2004 10920 04970 01jan1997 10may2006
2005 184748 04970 01jan1997 10may2006
2006 8479 04970 01jan1997 10may2006
YEAR GVKEY EXECID co_start_date co_end_date
2002 4598 00016 01mar1955 01oct1994
2003 157415 00016 01mar1955 01oct1994
2004 10920 00016 01mar1955 01oct1994
From example above, CEO id of EXECID 04970 worked in her whole life since 01jan1997 to 10may2006 from 5 different companies (GVKEY)
CEO id of 04970 worked in her whole life since 01mar1955 to 01oct1994 from 3 different companies (GVKEY)
I first want to change career end date (co_end_date) at each YEAR as below.
For ceo id EXECID 04970, I change the co_end_date as the first date of Current calendar year since CEO have worked till the current Year, his lifetime career end date is beyond the current year)
YEAR GVKEY EXECID co_start_date co_end_date
2000 5680 04970 01jan1997 01jan2000
2001 5681 04970 01jan1997 01jan2001
2002 5683 04970 01jan1997 01jan2002
2003 24668 04970 01jan1997 01jan2003
2004 10920 04970 01jan1997 01jan2004
2005 184748 04970 01jan1997 01jan2005
2006 8479 04970 01jan1997 10may2006
For ceo id EXECID 00016, since co_end_date is before YEAR (CEO's career already ended before current YEAR), I do not change and leave as it is.
YEAR GVKEY EXECID co_start_date co_end_date
2002 4598 00016 01mar1955 01oct1994
2003 157415 00016 01mar1955 01oct1994
2004 10920 00016 01mar1955 01oct1994
I want the value of n_recessions_worked of 04970
the value of n_recessions_worked in 2000 is 1 (recession range of 12 before 2000)
the value of n_recessions_worked in 2001 is 1 (recession range of 12 before 2001; current year is 2001 thus does not count the starting year of recession 13;
Do NOT count if starting of recession range year is equal current year since i'm looking at "PAST" recession experience )
the value of n_recessions_worked in 2002 is 2 (recession range of 12 and recession 13 before 2002)
...
the value of n_recessions_worked in 2007 is 2
the value of n_recessions_worked in 2008 is 3 (recession range of 12, 13, 14 before 2008)
...
...
the value of n_recessions_worked in 2011 is 3
LISTS of RECESSIONS:
local recession1 August 1929 March 1933
local recession2 May 1937 June 1938
local recession3 February 1945 October 1945
local recession4 November 1948 October 1949
local recession5 July 1953 May 1954
local recession6 August 1957 April 1958
local recession7 April 1960 February 1961
local recession8 December 1969 November 1970
local recession9 November 1973 March 1975
local recession10 January 1980 July 1980
local recession11 July 1981 November 1982
local recession12 July 1990 March 1991
local recession13 March 2001 November 2001
local recession14 December 2007 June 2009
local recession15 February 2020 April 2020
could you please revise previous code to get the value of n_recessions_work?

Comment