0

Consider the following toy example using the community-contributed Stata command coefplot:

sysuse auto

reg weight i.foreign
eststo, title("Weight"): margins, eydx(foreign) post

reg price i.foreign
eststo, title("Price"): margins, eydx(foreign) post

coefplot est1 est2, horizontal

Is it possible to get the titles (or even the variable labels) in the legend, instead of the estimate names (i.e. Weight and Price instead of est1 and est2)?

I know how to do it by hand, but I can't figure out how to do this automatically with many models.

dimitriy
  • 9,077
  • 2
  • 25
  • 50

1 Answers1

2

Using estimates store instead of eststo does the trick:

clear
sysuse auto

reg weight i.foreign
margins, eydx(foreign) post
estimates store weight

reg price i.foreign
margins, eydx(foreign) post
estimates store price

coefplot weight price, horizontal

Similarly, using a list and a for loop:

local list_of_names weight price

foreach item of local list_of_names {
    reg `item' i.foreign
    margins, eydx(foreign) post
    estimates store `item'      
}

coefplot `list_of_names', horizontal

You can of course use two different lists for variable names and 'labels'.

  • This works only when the model titles are single words with no punctuation, though this suffices for my purposes. – dimitriy Apr 15 '18 at 20:02
  • Yes, it is not perfect but you could go around that using camelCase. Underscores also seem to work. –  Apr 15 '18 at 20:08