I tried to use Stata command grc1leg2 in Stata 15 to combine several graphs. I have three ways. Two work, but one doesn't. I wondered how to make method 2 works as it will help automate my code (in method 1 and 3, I need to change the code if I have more graphs to combine, but in method 2, if I succeed, I don't have to do that.)
Method 1 (works): the most simple way
Code:
grc1leg2 lnrevenue.gph lnvariety.gph lndestination.gph lnprice.gph qpct.gph , ///
leg(qpct.gph) xtitle(qpct.gph ) xtob1 lsize(small) graphregion(color(white)) title("Placebo",size(medium))Code:
global sum ""
global vars "lnrevenue lnvariety lndestination lnprice qpct "
foreach file of global vars{
local n "`file'.gph"
disp "`n'"
global sum "$sum" " "`n'""
}
disp "$sum"
*Stata returns: lnrevenue.gph lnvariety.gph lndestination.gph lnprice.gph qpct.gph
grc1leg2 "$sum", ///
leg(qpct.gph) xtitle(qpct.gph ) xtob1 lsize(small) graphregion(color(white)) title("Placebo",size(medium))invalid syntax
r(198);
Method 3 (works): separate the global variables
Code:
global vars "lnrevenue lnvariety lndestination lnprice qpct "
local i=1
foreach file of global vars{
global n`i' "`file'.gph"
*disp "$n`i'"
local i=`i'+1
}
grc1leg2 "$n1" "$n2" "$n3" "$n4" "$n5" , ///
leg(qpct.gph) xtitle(qpct.gph ) xtob1 lsize(small) graphregion(color(white)) title("Placebo",size(medium))Thank you very much!
Best,
K
0 Response to space, global variable and combine graphs
Post a Comment