Hello!
I am trying to clean a dataset which is a long chain of merges from various versions of EPA data and Compustat data. Below is the example from how my data looks (just few variables attached here for ease);
This is a panel data of firms (gvkey) and year (fyear) from Compustat. Further these firms have multiple facilities (frsid), and each facility can have multiple federal cases going on against it (activity_id) because of its environmental violations and in which year (year) the cases were lodged. So in this panel data, I only want the information of each facility to show in the year the case was lodged against it and all other rows should be missing. The structure should look like there is a firm panel data, then under each firm whenever the case was started against its either of facility, data should show up and all rows for other years of the firm panel should be missing with plant level information.
As trivial as it may seem, I can't come up with the code. Any help will be greatly appreciated. Thanks!
I am trying to clean a dataset which is a long chain of merges from various versions of EPA data and Compustat data. Below is the example from how my data looks (just few variables attached here for ease);
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long gvkey double(frsid activity_id) float year double fyear float(total_cost total_penalty) 1075 110042068473 2600020355 2015 1970 1.685e+08 1500000 1075 110042068473 2600020355 2015 1971 1.685e+08 1500000 1075 110042068473 2600020355 2015 1972 1.685e+08 1500000 1075 110042068473 2600020355 2015 1973 1.685e+08 1500000 1075 110042068473 2600020355 2015 1974 1.685e+08 1500000 1075 110042068473 2600020355 2015 1975 1.685e+08 1500000 1075 110042068473 2600020355 2015 1976 1.685e+08 1500000 1075 110042068473 2600020355 2015 1977 1.685e+08 1500000 1075 110042068473 2600020355 2015 1978 1.685e+08 1500000 1075 110042068473 2600020355 2015 1979 1.685e+08 1500000 1075 110042068473 2600020355 2015 1980 1.685e+08 1500000 1075 110042068473 2600020355 2015 1981 1.685e+08 1500000 1075 110042068473 2600020355 2015 1982 1.685e+08 1500000 1075 110042068473 2600020355 2015 1983 1.685e+08 1500000 1075 110042068473 2600020355 2015 1984 1.685e+08 1500000 1075 110042068473 2600020355 2015 1985 1.685e+08 1500000 1075 110042068473 2600020355 2015 1986 1.685e+08 1500000 1075 110042068473 2600020355 2015 1987 1.685e+08 1500000 1075 110042068473 2600020355 2015 1988 1.685e+08 1500000 1075 110042068473 2600020355 2015 1989 1.685e+08 1500000 1075 110042068473 2600020355 2015 1990 1.685e+08 1500000 1075 110042068473 2600020355 2015 1991 1.685e+08 1500000 1075 110042068473 2600020355 2015 1992 1.685e+08 1500000 1075 110042068473 2600020355 2015 1993 1.685e+08 1500000 1075 110042068473 2600020355 2015 1994 1.685e+08 1500000 1075 110042068473 2600020355 2015 1995 1.685e+08 1500000 1075 110042068473 2600020355 2015 1996 1.685e+08 1500000 1075 110042068473 2600020355 2015 1997 1.685e+08 1500000 1075 110042068473 2600020355 2015 1998 1.685e+08 1500000 1075 110042068473 2600020355 2015 1999 1.685e+08 1500000 1075 110042068473 2600020355 2015 2000 1.685e+08 1500000 1075 110042068473 2600020355 2015 2001 1.685e+08 1500000 1075 110042068473 2600020355 2015 2002 1.685e+08 1500000 1075 110042068473 2600020355 2015 2003 1.685e+08 1500000 1075 110042068473 2600020355 2015 2004 1.685e+08 1500000 1075 110042068473 2600020355 2015 2005 1.685e+08 1500000 1075 110042068473 2600020355 2015 2006 1.685e+08 1500000 1075 110042068473 2600020355 2015 2007 1.685e+08 1500000 1075 110042068473 2600020355 2015 2008 1.685e+08 1500000 1075 110042068473 2600020355 2015 2009 1.685e+08 1500000 1075 110042068473 2600020355 2015 2010 1.685e+08 1500000 1075 110042068473 2600020355 2015 2011 1.685e+08 1500000 1075 110042068473 2600020355 2015 2012 1.685e+08 1500000 1075 110042068473 2600020355 2015 2013 1.685e+08 1500000 1075 110042068473 2600020355 2015 2014 1.685e+08 1500000 1075 110042068473 2600020355 2015 2015 1.685e+08 1500000 1075 110042068473 2600020355 2015 2016 1.685e+08 1500000 1075 110042068473 2600020355 2015 2017 1.685e+08 1500000 1075 110042068473 2600020355 2015 2018 1.685e+08 1500000 1075 110042068473 2600020355 2015 2019 1.685e+08 1500000 1075 110042068473 2600020355 2015 2020 1.685e+08 1500000 1075 110042068473 2600020355 2015 2021 1.685e+08 1500000 1075 110042068473 2600020355 2015 2022 1.685e+08 1500000 1078 110007806188 4128 1991 1973 10000 10000 1078 110007806188 4128 1991 1974 10000 10000 1078 110007806188 4128 1991 1975 10000 10000 1078 110007806188 4128 1991 1976 10000 10000 1078 110007806188 4128 1991 1977 10000 10000 1078 110007806188 4128 1991 1978 10000 10000 1078 110007806188 4128 1991 1979 10000 10000 1078 110007806188 4128 1991 1980 10000 10000 1078 110007806188 4128 1991 1981 10000 10000 1078 110007806188 4128 1991 1982 10000 10000 1078 110007806188 4128 1991 1983 10000 10000 1078 110007806188 4128 1991 1984 10000 10000 1078 110007806188 4128 1991 1985 10000 10000 1078 110007806188 4128 1991 1986 10000 10000 1078 110007806188 4128 1991 1987 10000 10000 1078 110007806188 4128 1991 1988 10000 10000 1078 110007806188 4128 1991 1989 10000 10000 1078 110007806188 4128 1991 1990 10000 10000 1078 110007806188 4128 1991 1991 10000 10000 1078 110007806188 4128 1991 1992 10000 10000 1078 110007806188 4128 1991 1993 10000 10000 1078 110007806188 4128 1991 1994 10000 10000 1078 110007806188 4128 1991 1995 10000 10000 1078 110007806188 4128 1991 1996 10000 10000 1078 110007806188 4128 1991 1997 10000 10000 1078 110007806188 4128 1991 1998 10000 10000 1078 110007806188 4128 1991 1999 10000 10000 1078 110007806188 4128 1991 2000 10000 10000 1078 110007806188 4128 1991 2001 10000 10000 1078 110007806188 4128 1991 2002 10000 10000 1078 110007806188 4128 1991 2003 10000 10000 1078 110007806188 4128 1991 2004 10000 10000 1078 110007806188 4128 1991 2005 10000 10000 1078 110007806188 4128 1991 2006 10000 10000 1078 110007806188 4128 1991 2007 10000 10000 1078 110007806188 4128 1991 2008 10000 10000 1078 110007806188 4128 1991 2009 10000 10000 1078 110007806188 4128 1991 2010 10000 10000 1078 110007806188 4128 1991 2011 10000 10000 1078 110007806188 4128 1991 2012 10000 10000 1078 110007806188 4128 1991 2013 10000 10000 1078 110007806188 4128 1991 2014 10000 10000 1078 110007806188 4128 1991 2015 10000 10000 1078 110007806188 4128 1991 2016 10000 10000 1078 110007806188 4128 1991 2017 10000 10000 1078 110007806188 4128 1991 2018 10000 10000 1078 110007806188 4128 1991 2019 10000 10000 end
As trivial as it may seem, I can't come up with the code. Any help will be greatly appreciated. Thanks!
Comment