Hello Everyone,

Hope you all are doing well.

I have this somewhat confusing query which I am trying to resolve but having a bit of a difficulty doing so.

I have a parent folder that contains 5 subfolders. Each subfolder has multiple files in it (.csv | .dta | .xlsx etc.)

I am looking to go into each subfolder and perform a 1:1 merge on specific files that have a particular pattern. Below is an example of one folder:

Array

The files I would like to merge are the ones that have the name "m1.dta" "m2.dta" "m3.dta" ... and so on (dta files like m2numbers.dta are not to be merged)

Each subfolder would contain a minimum of one of these .dta files and maximum number can vary as each dta file represents a call attempt.

I started writing a code but I can not figure out how to proceed forward. Code is below:

Code:
    cd "~/Downloads/Campaign/Calls Data"
    local subdirs : dir "." dirs "*"
    di `"`subdirs'"'

    foreach folder in `subdirs'{
        di "`folder'"
        fs "./`folder'/*.dta*"
        
        if ustrregexm(`r(files)', "m([1-9]).dta") local list = ustrregexs(0)
    
    }

Assistance will be appreciated.

Thank you.