Sitemap

Combining lists in STATA

Oct 15, 2026

--

Just a quick one: today I learned that you can easily add or substract lists from each other in STATA. Say you want a list of all numeric variables, apart from a couple. This is how you would do it:

Get Lana Bojanić’s stories in your inbox

Join Medium for free to get updates from this writer.

*First list, all numeric vars
ds, not(type string)
local not_string `r(varlist)'
di "`not_string'"

*Second list, the numeric variables we want to exclude
local num_exc idnum year age
di "`num_exc'"

*Final list, simply substract!
local final_list: list not_string - num_exc
di "`final_list'"

Simple! While working on this I listened to:

--

--

Lana Bojanić
Lana Bojanić

Written by Lana Bojanić

Mental health researcher based in Manchester, UK. I like to share Stata and R tips. Send photos of your cats.