Colleagues,
I have an elaborate graphic command that I use to derive charts. I'm currently trying to add two extra lines to the syntax that would save the graphs in desired folder but somehow the graph save and graph export commands do not appear to work.
I have an elaborate graphic command that I use to derive charts. I'm currently trying to add two extra lines to the syntax that would save the graphs in desired folder but somehow the graph save and graph export commands do not appear to work.
Code:
{/*---------------- Chart -------------------------*/
/* Set colour scheme */
set scheme Burd11
* Make snapshot for the backup.
snapshot save, label("Backup before chart")
local recsnap = r(snapshot)
*Start doing the chart.
local timevar hsr9_
local varlabel "Text"
local yaxtitle "Unit"
local xaxtitle "Year or something like that"
reshape long `timevar', i(observation) j(time) string
* Change syntax for the time variable.
gen date = yearly(time, "Y")
format %tyCCYY date
* generate group for the time series.
generate group = abcgroup== "Case ABC"
* Define label for the variable.
label define groups 0 "Rest" 1 "Case ABC"
label values group groups
* Define time series data.
capture : xtset group date
collapse (mean) `timevar', by(group date)
xtset group date
* Draw time series graph.
label variable `timevar' "`varlabel'"
local charttitle : var label `timevar'
xtline `timevar', overlay ///
plot1(lwidth(medthick) lpattern(shortdash)) ///
plot2(lwidth(medthick) lpattern(solid)) ///
title("`charttitle'", size(medsmall) position(12) margin(vsmall)) ///
subtitle("{it: Text}", ///
size(small) position(12)) ///
caption("{it: Data Source: source.}", ///
size(vsmall)) ///
legend( rows(1) size(vsmall) position(6) rowgap(.5) ///
region(fcolor(ltbluishgray) lcolor(navy))) ///
ytitle("`yaxtitle'", size(vsmall)) ///
xtitle("`xaxtitle'", size(vsmall)) ///
ylabel(, labsize(vsmall) ) ///
xlabel(#8, labsize(vsmall) ) ///
name(timechart_`timevar', replace)
* Restore snapshot.
snapshot restore `recsnap'
* Save graph.
graph save timechart_`timevar' ///
"C:\_path_\Graphs\Stata\timechart_`timevar'.gph", ///
replace
* Export graph.
graph save timechart_`timevar' ///
"C:\_path_\Graphs\Exports\timechart_`timevar'.png", ///
replace
/*------------------------------------------------------------------*/}
Comment