Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use of name() option with marginsplot undoing formatting specifications

    I am trying to use margins and marginsplot to convey some logistic regression results. Because of the number of categorical variables at which I want to convey results and because of the somewhat cumbersome way marginsplot labels multiple variables passed to xdimension() (e.g. "Cheap, Light", "Cheap, Heavy", "Expensive, Light", "Expensive, Heavy"), I chose to pass one of these variables to the graphdimension() option for marginsplot, to get separate plots I can then combine. But for some reason, when I use the name() option, to pass an explicit name stub for the separate graphs, marginsplot begins to ignore other formatting specifications. In particular, specifications for y axis labels and x axis label angles. Why does this happen?

    When reading the documentation for the name() option, I don't see anything suggesting use should affect graph content or display. Nor did I find any prior threads that answered this question directly.

    Please see the reproducible example below. I use Stata 17 on Windows 10. Though this same issue exists when I run the below code on Stata 15 and Stata 16 (still on Windows 10).

    Code:
    clear
    sysuse auto
    
    label values foreign
    
    sum price
    gen expensive = price >= r(mean)
    label define expensive 0 "Cheap" 1 "Expensive"
    label values expensive expensive
    
    sum weight
    gen heavy = weight >= r(mean)
    label define heavy 0 "Light" 1 "Heavy"
    label values heavy heavy
    
    sum mpg
    gen guzzler = mpg >= r(mean)
    label define guzzler 0 "Efficient" 1 "Inefficient"
    label values guzzler guzzler
    
    logit foreign i.expensive i.heavy i.guzzler
    margins, at(heavy = (0 1) expensive = (0 1) guzzler = (0 1))
    
    * When name() isn't used, y labels and x label angle are respected in each graph
    marginsplot, graphdimension(guzzler) bydimension(heavy) xdimension(expensive) noci recast(bar) ylabel(0(0.2)1) xlabel(,angle(45)) //name(something, replace)
    
    * When name() is used, y labels and x label angle are no longer respected in any graph
    marginsplot, graphdimension(guzzler) bydimension(heavy) xdimension(expensive) noci recast(bar) ylabel(0(0.2)1) xlabel(,angle(45)) name(something, replace)


  • #2
    To avoid this, you should place those options as suboptions within the plotopts() option of marginsplot. See below:

    Code:
    marginsplot,name(something, replace) graphdimension(guzzler) bydimension(heavy) xdimension(expensive) noci recast(bar) plotopts(ylabel(0(0.2)1) xlabel(,angle(45)))

    Comment


    • #3
      I completely missed plotopts(). That works perfectly. Many thanks, Ali.

      Comment

      Working...
      X