Dear Stata Users,

I run the following code to generate a table:

Code:
 unab stubs : *_X
local stubs : subinstr local stubs "_X" "", all
local nstubs : word count `stubs'
local I = 2 * `nstubs' 

matrix results = J(`I', 6, .)

local i = 1
gen touse = 0 
local rownames 
quietly foreach s of local stubs {
    replace touse = !missing(`s'_X, `s'_Y) 
    foreach v in `s'_X `s'_Y {
        su `v' if touse, detail 
        mat results[`i', 1] = r(N)
        mat results[`i', 2] = r(mean) 
        mat results[`i', 3] = r(sd) 
        mat results[`i', 4] = r(p50) 
        mat results[`i', 5] = r(min) 
        mat results[`i', 6] = r(max) 
        local names `names' `v' 
        local ++i
    }
} 

mat rownames results = `names'
mat colnames results = n mean SD median min max 
mat li results, format("%6.0g")


** and I get the following table with results:


           n    mean      SD  median     min     max

APNA_X     0       .       .       .       .       .
APNA_Y     0       .       .       .       .       .
Flags_X    0       .       .       .       .       .
Flags_Y    0       .       .       .       .       .
T3_X      391   3.892   1.408    4.04     .19    7.56
T3_Y      391   3.879   1.399    4.03      .2    7.46
MoK_X     361   85.28   7.814    85.8    55.4   105.4
MoK_Y     361   86.05   7.886    86.4    55.6   107.1
LyS_X     361   35.22   9.231      35    18.7    63.1
LyS_Y     361   35.41   9.273    35.4    18.5    62.9
In some of my datasets, I don't always have the same var names ending with "_X" or "_Y". Is it possible to specify which variables I want to include in my table using the code above? If possible, where in the code should I specify it and how should I write it? For example, I only want to include T3, MoK, and LyS and skip APNA and Flags.

Hope I am clear enough.

Thank you in advance!
Amanda