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 {
  2.         local sidetable `" `sidetable' " `=make[`i']' " "'
  3. }

. forvalues i = 1/20 {
  2.         local sidecap `" `sidecap' " $`price[`i']'" "'
  3. }

  . 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))