A simple way to export a few local macro values into small csv files is through writing a text file with commas and renaming it to csv at the end. With your example you could try:
sysuse auto
file open TABLES using "ranges.txt", write replace //create temporary text file
file write TABLES "p1, p99" _n // columns headers
summ price,de
file write TABLES (r(p1)) "," (r(p99)) _n // write locals separated by commas into the text file
file close TABLES
copy ranges.txt ranges.csv, replace //change extension to csv
rm ranges.txt //remove text file
If you want to repeat the process for every level of rep78
:
sysuse auto
levelsof rep78, local(levels)
file open TABLES using "ranges.txt", write replace //create temporary text file
file write TABLES "level of rep78, p1, p99" _n // columns headers
foreach i of local levels {
summ price if rep78==`i',de
file write TABLES "`i', `r(p1)' , `r(p99)'"_n
}
file close TABLES
copy ranges.txt ranges.csv, replace //change extension to csv
rm ranges.txt //remove text file