Dear Statalisters,

say I have the following variable names:
Code:
child_id_kp child_id_ka child_id_ng month_gh month_ka month_ng
My broader goal is to combine information from those variables with the same prefix. More specifically, in the case of the example above, I want to create two variables
Code:
gen child_id = .
gen month = .
and afterwards iterate over all variables with the corresponding prefix to fill up the missings.
For this to work, I need Stata to
  1. identify prefixes that occur multiple times
  2. store all variables with the corresponding prefix in a local
I don't have any idea about 1. Regarding 2., I want to end up with
Code:
local child_id child_id_kp child_id_ka child_id_ng
local month month_gh month_ka month_ng
Any hint is greatly appreciated!