Hello Everyone! I have a panel dataset that consists of about 100 exporting countries (id) and the products (product_cat) they exported over a period from 1995 to 2021 alongside the values of the exports (value). At the most disaggregated level, the panel has a total of over 5 million observations with each country exporting around 5000 products. What I hope to do is to have a final dataset wherein I KEEP observations that capture the products exported by every country in the panel from 1995 to 2018 and DROP the ones that are not exported by all countries in the same time period. With the given example below ( a quasi illustration of what my data currently looks like), I would like to keep product 10111 because it appears in both 2015 and 2016 and is exported by all sampled countries (4 5 and 6). However, I would like to drop 10519 because it only appears in the export baskets of country 4 and 5 but not 6. In the same vein, I would drop product 60310 because it does not appear for every recorded year. Is there a code that could do this without me manually telling Stata to drop category 60310 or the others mentioned. Any input would be appreciated and further clarity can be given. Thank you.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte id int year long(product_cat value) 4 2015 10111 1 4 2015 10519 45 4 2015 10600 9 4 2015 30110 568 4 2015 30410 1 4 2015 30490 786678 4 2015 30613 77 4 2015 30749 68 4 2015 40630 26 5 2015 10111 99 5 2015 10519 88 5 2015 10600 9 5 2015 30110 3 5 2015 30410 90 5 2015 30490 1 5 2015 30613 77 5 2015 30749 66 6 2015 10111 1677 6 2015 10519 2 6 2015 10600 9 6 2015 30110 456 6 2015 30613 77 6 2015 30749 68 6 2015 40630 657 6 2015 60310 2 4 2016 10111 1 4 2016 10600 9 4 2016 30110 568 4 2016 30410 1 4 2016 30490 786678 4 2016 30613 77 4 2016 30749 68 4 2016 40630 26 5 2016 10111 1 5 2016 10600 9 5 2016 30110 3 5 2016 30490 1 5 2016 30613 77 5 2016 30749 66 6 2016 10111 1 6 2016 10519 2 6 2016 10600 9 6 2016 30110 456 6 2016 30613 77 6 2016 40630 657 6 2016 60310 2 end label var id "Country ID " label var product_cat "HS6 digit product category" label var value "export value in USD "
Comment