I am plotting a graph, the code is below
Btw, x,w,z are continues variables
I got the following plot

The keys in the legend are numbers, I was wondering whether I can use code to change them.
For example, when w= -.9960929 (i.e. $Lw), the key in the legend automatically changes to "low w"
I know the -order- command in -legend- can change the keys manually (as below), but it's not elegant. Is it possible to let Stata itself change the keys?
Btw, x,w,z are continues variables
Code:
/* determined high and low values for x */
sum x
global Hx=r(mean)+r(sd)
global Lx=r(mean)-r(sd)
/* determined high and low values for w */
sum w
global Hw=r(mean)+r(sd)
global Lw=r(mean)-r(sd)
/* determine high and low values for z */
sum z
global Hz=r(mean)+r(sd)
global Lz=r(mean)-r(sd)
margins, at(x=($Hx $Lx) w=($Hw $Lw) z=($Hz $Lz)) vsquish
marginsplot, recast(line) noci ///
xtitle("A") ///
ytitle("B") ///
xlabel($Hx "High x" $Lx "Low x", nogrid labsize(2.5)) ///
legend(position(6) col(2))
The keys in the legend are numbers, I was wondering whether I can use code to change them.
For example, when w= -.9960929 (i.e. $Lw), the key in the legend automatically changes to "low w"
I know the -order- command in -legend- can change the keys manually (as below), but it's not elegant. Is it possible to let Stata itself change the keys?
Code:
legend(position(6) col(2) ///
order(1 "Low w, Low z" ///
2 "Low w, High z" ///
3 "High w, Low z" ///
4 "High w, High z"))
