-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavefig.ado
41 lines (34 loc) · 1.18 KB
/
savefig.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
capture program drop savefig
program define savefig
// ====================================================================================
/* This program saves Stata graph using graph export into multiple file formats.
Example usage:
savefig, path(savepath) format(png pdf) override(width(1000))
MWE:
sysuse auto, clear
hist price
savefig, path(myfig)
*/
// ====================================================================================
syntax, PATH_filestem(string) [FORMATs(string) OVERRIDE_args(string)]
if "`formats'" == "" {
local formats "pdf png"
}
foreach fsuffix in `formats' {
local filename "`path_filestem'.`fsuffix'"
if "`fsuffix'"=="pdf" {
graph export "`filename'", as(`fsuffix') replace
}
else {
cap graph export "`filename'", as(`fsuffix') replace `override_args'
if _rc==198 {
dis "Override ption not allowed - ignoring override option"
graph export "`filename'", as(`fsuffix') replace
}
}
dis as result "Graph saved as `filename'"
}
end
// sysuse auto, clear
// hist price
// savefig, path(test)