Search code examples
statacoefplot

Getting coefplot to use estimate titles or outcome labels


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.


Solution

  • 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'.