Hi all,

My data has four variables: acty, deady, nation, and id.
"acty" is the year when company is listed in stock market.
"deady" is the year when company is delisted from stock market.
"nation" is the country code.
"id" is the company id.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(acty deady) str3(nation id)
2000 2000 "AUS" "1" 
2012 2017 "AUS" "2" 
2002 2004 "AUS" "3" 
2005 2008 "AUS" "4" 
2000 2006 "AUS" "5" 
2000 2010 "AUS" "6" 
2000 2002 "AUS" "7" 
2000 2006 "AUS" "8" 
2008 2019 "AUS" "9" 
2000 2000 "AUS" "10"
2016 2019 "AUS" "11"
2001 2019 "AUS" "12"
2000 2001 "AUS" "13"
2000 2005 "AUS" "14"
2007 2019 "AUS" "15"
2000 2000 "AUS" "16"
2000 2000 "AUS" "17"
2017 2019 "AUS" "18"
2000 2019 "AUS" "19"
2000 2002 "AUS" "20"
2000 2019 "AUS" "21"
2002 2019 "AUS" "22"
2006 2009 "AUS" "23"
2001 2019 "AUS" "24"
2007 2019 "AUS" "25"
2015 2019 "AUS" "26"
2000 2004 "AUS" "27"
2000 2004 "AUS" "28"
2000 2003 "AUS" "29"
2000 2005 "AUS" "30"
2000 2003 "AUS" "31"
2000 2002 "AUS" "32"
2000 2017 "AUS" "33"
2000 2001 "AUS" "34"
2005 2019 "AUS" "35"
2003 2007 "AUS" "36"
2015 2017 "AUT" "1" 
2000 2002 "BEL" "1" 
2015 2019 "BEL" "2" 
2016 2018 "BEL" "3" 
2015 2019 "BEL" "4" 
2001 2016 "BEL" "5" 
2009 2019 "BEL" "6" 
2014 2019 "BEL" "7" 
2017 2018 "BEL" "8" 
2002 2020 "CAN" "1" 
2000 2020 "CAN" "2" 
2005 2009 "CAN" "3" 
2002 2014 "CAN" "4" 
2011 2015 "CAN" "5" 
end
format %ty acty
format %ty deady
I need to count the number of companies (in each nation) that are active in a specific year and record the number as new variable.
For example, in AUS, there are 21 companies that were active in the year of 2000 (acty<=2000<=deady), 19 companies that were active in the year of 2001(acty<=2001<=deady), and so on.
The output would look like;
nation year nbr
AUS 2000 21
AUS 2001 19
AUS 2002 19
AUS 2003
AUS 2004
AUS 2005
AUS 2006
AUS 2007
AUS 2008
AUS 2009
AUS 2010
AUS 2011
AUS 2012
AUS 2013
AUS 2014
AUS 2015
AUS 2016
AUS 2017
BEL 2000
BEL 2001
BEL 2002
BEL 2003
BEL 2004
BEL 2005
BEL 2006
BEL 2007
BEL 2008
BEL 2009
BEL 2010
BEL 2011
BEL 2012
BEL 2013
BEL 2014
BEL 2015
BEL 2016
BEL 2017
CAN 2000
CAN 2001
CAN 2002
CAN 2003
CAN 2004
CAN 2005
CAN 2006
CAN 2007
CAN 2008
CAN 2009
CAN 2010
CAN 2011
CAN 2012
CAN 2013
CAN 2014
CAN 2015
CAN 2016
CAN 2017
Please help me with this task.
Thank you for any help you can offer.