Hello!
I am working with a big panel dataset so here is a peek generated using randomtag:
The "countrycode" of interest is COL (for country Colombia) and I want to:
1. Keep observations for "countrycode" if "countrycode" equals COL, LCN, and either HIC, or UMC or LMC or LIC. To make this decision, I want to generate a command that keeps the "countrycode" value that matches COL's "incomegrpcode" (in this case "UMC"). So, I will keep "countrycode" for COL, LCN, and UMC. (I have 30 other files for other 30 countries which is why I want to automatize this selection process).
2. Lastly, I want to keep the observations for variables "year" and "value" but only if "countrycode" is COL. Note that I do not want to delete other observations for LCN and UMC. I tried:
-keep value if countrycode == "COL"-
but the syntax is wrong.
This is my first week on statalist so appreciate the help and patience!
I am working with a big panel dataset so here is a peek generated using randomtag:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 countrycode str20 indicatorcode int year str3 incomegrpcode double value int lastyear double lastvalue "COL" "SE.TER.GRAD.FE.SI.ZS" 2002 "UMC" 36.78437 2018 33.40987014770508 "LIC" "SL.EMP.VULN.MA.ZS" 2004 "" 11.470940657134927 2019 10.029830932617188 "LIC" "SL.EMP.VULN.MA.ZS" 2014 "" 10.21737611206278 2019 10.029830932617188 "LMC" "SL.EMP.VULN.MA.ZS" 2016 "" 9.993775550015 2019 10.029830932617188 "HIC" "SL.UEM.NEET.FE.ZS" 2004 "" 13.25578375763103 2020 13.660029411315918 "HIC" "SL.EMP.VULN.FE.ZS" 2007 "" 34.93653748381432 2019 33.77582931518555 "LCN" "SL.EMP.VULN.MA.ZS" 2016 "" 32.627529254827486 2019 33.37175750732422 "LCN" "SL.UEM.NEET.FE.ZS" 2009 "" 27.604067393450375 2020 29.49407386779785 "UMC" "SL.EMP.VULN.MA.ZS" 2016 "" 37.18845687356563 2019 35.69723892211914 "UMC" "SP.ADO.TFRT" 2014 "" 30.77510272630119 2020 29.038925170898438 end
1. Keep observations for "countrycode" if "countrycode" equals COL, LCN, and either HIC, or UMC or LMC or LIC. To make this decision, I want to generate a command that keeps the "countrycode" value that matches COL's "incomegrpcode" (in this case "UMC"). So, I will keep "countrycode" for COL, LCN, and UMC. (I have 30 other files for other 30 countries which is why I want to automatize this selection process).
2. Lastly, I want to keep the observations for variables "year" and "value" but only if "countrycode" is COL. Note that I do not want to delete other observations for LCN and UMC. I tried:
-keep value if countrycode == "COL"-
but the syntax is wrong.
This is my first week on statalist so appreciate the help and patience!
Comment