Hello everyone,
I have a dataest of companies with a lot of parameters over the different years from 2005-20016:
The variable NAcount counts, how many items are unavailable per year (not all parameters included in the dataex so the 11 comes from all the different variables).
The goal is to drop all companies if they do not fullfill following conditions:
1. At least 3 years of full data (NAcount = 0) before 2012
2. At least 2 years of full data (NAcount = 0) after 2012
It does not matter whether they are consecutive or not, i just need at least the given amount of years of full data before and after certain event in 2012.
For instance:
"13082U" should NOT be dropped since it fullfills the conditions
"13410M" should be dropped because it has no year of full information before 2012.
I tried to use -inspect- which kind of worked (counting observations of 0) in combination with -bysort- however I could not manage to save the results on the way for each company and drop with respect to the conditions.
If anyone could come up with a solution to my problem, i would be very thankful for any kind of help. Also let me know if i should provide more information.
Thanks in advance
I have a dataest of companies with a lot of parameters over the different years from 2005-20016:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 CompanyID long(xCash xSales) int(time NAcount) "13082U" . 52582 2005 2 "13082U" 4100 62208 2006 0 "13082U" 7471 85370 2007 0 "13082U" 7891 142755 2008 0 "13082U" . 117178 2009 1 "13082U" . 196011 2010 1 "13082U" . 94829 2011 1 "13082U" 7891 25942 2012 0 "13082U" 7081 11636 2013 0 "13082U" 20438 14552 2014 0 "13082U" 27336 25362 2015 0 "13082U" 13402 30294 2016 0 "13410M" . 22822 2005 1 "13410M" . 23693 2006 1 "13410M" . 26246 2007 1 "13410M" . 48744 2008 1 "13410M" . 44985 2009 1 "13410M" . 54624 2010 1 "13410M" . 67878 2011 1 "13410M" . 72092 2012 1 "13410M" 4378 77273 2013 0 "13410M" 5685 82090 2014 0 "13410M" 7456 92173 2015 0 "13410M" 6516 93415 2016 0 "13489T" 2330 90936 2005 0 "13489T" . 152296 2006 1 "13489T" 14156 213482 2007 0 "13489T" 3576 262341 2008 0 "13489T" 21949 177481 2009 0 "13489T" 13826 222720 2010 0 "13489T" 7740 116166 2011 0 "13489T" . . 2012 11 "13489T" . . 2013 11 "13489T" . . 2014 11 "13489T" . . 2015 11 "13489T" . . 2016 11 "13519D" . 370 2005 1 "13519D" . 465 2006 1 "13519D" . 1197 2007 1 "13519D" . 1522 2008 1 "13519D" . 1753 2009 1 "13519D" . 2145 2010 1 "13519D" . 2316 2011 1 "13519D" 2838 2693 2012 0 "13519D" 1203 3622 2013 0 "13519D" 4267 4476 2014 0 "13519D" 5739 5086 2015 0 "13519D" 1977 5598 2016 0 "135490" 13977 108327 2005 0 "135490" 6453 115356 2006 0 end
The goal is to drop all companies if they do not fullfill following conditions:
1. At least 3 years of full data (NAcount = 0) before 2012
2. At least 2 years of full data (NAcount = 0) after 2012
It does not matter whether they are consecutive or not, i just need at least the given amount of years of full data before and after certain event in 2012.
For instance:
"13082U" should NOT be dropped since it fullfills the conditions
"13410M" should be dropped because it has no year of full information before 2012.
I tried to use -inspect- which kind of worked (counting observations of 0) in combination with -bysort- however I could not manage to save the results on the way for each company and drop with respect to the conditions.
If anyone could come up with a solution to my problem, i would be very thankful for any kind of help. Also let me know if i should provide more information.
Thanks in advance

Comment