Dear statalisters,
I am currently looking for a way to open several gph in a row and exporting them to a format readable on any computer -- no matter which STATA version my recipient is using. Since I have a lot of gph and they are all located in the same folder, I thought using the filelist- command and advices on Statalist from Robert Picard but I failed to do so. I keep getting the same no observations issue since the filelist is not working. Am I missing something ?
Here is my attempt
ssc install filelist
filelist , dir(.) pattern(*.gph) norecur
* extract the identifier code
gen shortname = regexs(1)
isid shortname
* save a copy so that we can load each observation in the loop below
tempfile files
save "`files'"
local obs = _N
* create a directory to put the Stata dta if it does not already exist
cap mkdir pdf
* loop over each file and do whatever's needed
forvalues i=1/`obs' {
use "`files'" in `i', clear
local source = shortname
local f = dirname + "/" + filename
graph use "`f'"
gen source = "`source'"
graph export "pdf/`source'.pdf", as(pdf) name("`file'") replace
}
I am currently looking for a way to open several gph in a row and exporting them to a format readable on any computer -- no matter which STATA version my recipient is using. Since I have a lot of gph and they are all located in the same folder, I thought using the filelist- command and advices on Statalist from Robert Picard but I failed to do so. I keep getting the same no observations issue since the filelist is not working. Am I missing something ?
Here is my attempt
ssc install filelist
filelist , dir(.) pattern(*.gph) norecur
* extract the identifier code
gen shortname = regexs(1)
isid shortname
* save a copy so that we can load each observation in the loop below
tempfile files
save "`files'"
local obs = _N
* create a directory to put the Stata dta if it does not already exist
cap mkdir pdf
* loop over each file and do whatever's needed
forvalues i=1/`obs' {
use "`files'" in `i', clear
local source = shortname
local f = dirname + "/" + filename
graph use "`f'"
gen source = "`source'"
graph export "pdf/`source'.pdf", as(pdf) name("`file'") replace
}
Comment