Add a Table to your Graph using Macros and Loops

You can add a summary table or guide on the side of your graph using local macros and looping with a forvalues{} loop.

To generate this graph in Stata, use the following commands:

sysuse auto, clear
 
forvalues i = 1/20 {
    
local sidetable `" `sidetable' " `=make[`i']' " "'
}
 
forvalues i = 1/20 {
    
local sidecap `" `sidecap' " $`price[`i']'" "'
}
 
sysuse auto, clear
twoway (scatter mpg rep78) , note("{bf: MAKE }" "-----------------" , size(medsmall) color(green) position(2) margin(small) justification(left)) caption(" {bf: Price }" "---------" , size(medsmall) color(midgreen) position(2) margin(vsmall) justification(right))