Can someone explain why posting to a temporary frame doesn't work in the code below whereas posting to a permanent frame works? The code is just a reproducible example where I am grabbing the first line of multiple .csv files, along with the file name, and making a dataset of those.
Code:
version 16.1
mkdir temp_stata
cd temp_stata
clear
input str10 v1
"one"
"two"
"three"
"four"
end
export delimited using "myfile1.csv"
clear
input str10 v1
"five"
"six"
end
export delimited using "myfile2.csv"
*** this works
frame create results str100 v1 str100 f
frames dir
frame change default
local myfiles : dir . files "*.csv"
foreach f of local myfiles {
display "`f'"
quietly import delimited "`f'", varnames(1) clear
quietly keep in 1
frame post results (v1[1]) ("`f'")
}
frame change results
compress
list
*** this doesn't
/*
tempname results
frame create `results' str100 v1 str100 f
frames dir
frame change default
local myfiles : dir . files "*.csv"
foreach f of local myfiles {
display "`f'"
quietly import delimited "`f'", varnames(1) clear
quietly keep in 1
frame post `results' (v1[1]) ("`f'")
}
frame change `results'
compress
list
*/

Comment