Hi, I'm very new to Stata and I've searched and tried answers for this question for three hours. I'm using Stata16. I have covid related data (daily cumulative/new cases/deaths data) of each country and I would like to set row's name to be according country's name. To examine on each country's data, I firstly split the data set to 195 dta files:
levelsof location, local(level1)
foreach x of local level1 {
preserve
keep if location=="`x'"
save file`x',replace
restore
}


Then I repeat a regression on each country's data using foreach, resulting in a matrix of R^2
Array
I've renamed columns. However, I don't know how to rename around 200 rows easily.

I have two ideas. I firstly tried to use levelsof to extract location names from original covid related dataset and set it to be the rows' names:
frame owid: levelsof location, local(rownames)
matrix rownames R2 = `rownames'

However, it seems that the dataset is another frame, the list of locations cannot be row names? The row names were not changed.

Then, I tried to rename each row in iteration:
local myfilelist: dir . files "*.dta"
local rownames
foreach filename of local myfilelist {
use `filename', clear
local rownames `rownames' `filename'
}
matrix rownames R2 = `rownames'

But I got error message: fileafghanistan: operator invalid

I'm sorry if I am not clear in questioning. I previously used other softwares and Stata is quite new for me. I will appreciate if you can give some advice on codes.

Thank you for your time and help!