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
Related Posts with select specific observation among several variables
Gompertz mortalityDear Statalisters, I am working on mortality dataset. Each row represents the number of people born…
Working with groups_Find new element in year t+1 compared to year tDear everyone, I have a dataset as follows. Basically, in each year, each agency delivers services …
Ologit, Paralell Regression Assumption and weightsHi, it's the first time i write here, hope the question is not too emantary, I'm trying to replicat…
Propensity Score Matching - Multilevel DataHi all, For my Dissertation I am calculating a multilevel regression with data from a cross-nationa…
Long string variableDear all, I am trying to import a csv file (separated by commas) in which one variable contains ver…
Subscribe to:
Post Comments (Atom)
0 Response to select specific observation among several variables
Post a Comment