Hello everyone,
Using STATA16, I have a dataset with 20 variables dx1 to dx20. I want to keep only observations with T40xxxx, T41xxxx, T42xxxx, and T43xxxx. When I use "keep" command for the first variable (dx1) I missed the other variables.
keep if inlist(substr(dx1, 1, 3), "T40", "T41", "T42", "T43")
Another way that I tried is to generate new var that helped me to gen a new var contains observation with T40xxxx, T41xxxx, T42xxxx, and T43xxxx.
gen DX1= dx1 if inlist(substr(dx1, 1, 3), "T40", "T41", "T42", "T43")
This way takes a lot of time. I am wondering how I can keep only observations in each variable (dx1 to dx20) that contain T40xxxx, T41xxxx, T42xxxx, and T43xxxx. Is there any other way for doing this, for example, writing a loop for :
gen DX1= dx1 if inlist(substr(dx1, 1, 3), "T40", "T41", "T42", "T43")
Thank you in advance for your advice.
Best
Array
0 Response to select specific observation among several variables
Post a Comment