Dear Statalisters,
I hope you are all fine. I am currently using a file gathering data on employment by sector for a set of countries and years. Here's an example generated by the command -dataex-. I had to alter the data with random numbers for the sake of confidentiality:
I would like to ask Stata to keep only observations for employ with the most recent nonmissing observations in each sector number. In the case where observations are missing for all years (as in sector 4 in the example displayed above), then I would like Stata to keep the missing value for the most recent year. What I would like should look like something like this :
Could anyone help me on this request? Any advice would be greatly appreciated.
Regards,
Hugo
I hope you are all fine. I am currently using a file gathering data on employment by sector for a set of countries and years. Here's an example generated by the command -dataex-. I had to alter the data with random numbers for the sake of confidentiality:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 country int year str2 sector double employ "C1" 2015 " 1" 52 "C1" 2016 " 1" 56 "C1" 2017 " 1" . "C1" 2018 " 1" . "C1" 2015 " 2" 23 "C1" 2016 " 2" 28 "C1" 2017 " 2" 22 "C1" 2018 " 2" 54 "C1" 2019 " 2" 43 "C1" 2015 " 3" . "C1" 2016 " 3" . "C1" 2017 " 3" 65 "C1" 2018 " 3" 58 "C1" 2019 " 3" 26 "C1" 2015 " 4" . "C1" 2017 " 4" . "C1" 2018 " 4" . "C1" 2019 " 4" . "C1" 2015 " 5" 53 "C1" 2016 " 5" 55 end
I would like to ask Stata to keep only observations for employ with the most recent nonmissing observations in each sector number. In the case where observations are missing for all years (as in sector 4 in the example displayed above), then I would like Stata to keep the missing value for the most recent year. What I would like should look like something like this :
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 country int year str2 sector double employ "C1" 2016 " 1" 56 "C1" 2019 " 2" 43 "C1" 2019 " 3" 26 "C1" 2019 " 4" . "C1" 2016 " 5" 55 end
Regards,
Hugo
Comment