4

I am using coefplot in stata to plot coefficients. I am combining two graphs together and would like to use different xscale. The webpage suggests to use this option:

  byopts(xrescale)

However, this option does not allow user-specified xscale. For instance, I would like to specify one subgraph with xscale( -0.1, 0.5) and another subgraph with xscale(-0.1, 0.1). The following code does not achieve my goals.

    coefplot (est1,label(Grade 5)) (est2,label(Grade 6))  ///
              , bylabel("Chinese") xscale(r(-0.1,0.5))  ||    /// 
             (est3,label(Grade 5)) (est4,label(Grade 6)) ///
             ,bylabel("Math")     xscale(r(-0.1,0.1))    ||, /// 
              keep(1.female)  ///
              yscale(off)  graphregion(fcolor(white)) xscale(r(0,1) 
              titleg(0.1)) ///
              xline(0, lwidth(vthin) lcolor(red)) ciopts(recast(rcap)) 
              byopts(xrescale)
Yan Song
  • 2,285
  • 4
  • 18
  • 27

1 Answers1

3

It is hard to know what's going wrong since we don't have your data, or complete or valid code, or even the actual graph that does not achieve your goals.

Here's reproducible example showing custom x-axis ranges in each subplot:

sysuse auto, clear
eststo m1: reg price c.mpg
eststo m2: reg price c.weight
eststo m3: reg price i.foreign
coefplot (m1, xscale(range(-350 -50))) || (m2, xscale(range(1 3))) || (m3, xscale(range(-1200 2000))) ///
, drop(_cons) byopts(xrescale cols(3))

The graph looks like this:

enter image description here

Possible diagnoses:

  1. range() never narrows the scale of an axis or causes data to be omitted from the plot, so coefplot could be not listening to you if the ranges are not consistent with what is being plotted. Impossible to tell without seeing the model output.
  2. You don't have the most recent version of coefplot, and this was something that was fixed. With user-written commands, this is always worth checking when you run into a problem.
dimitriy
  • 9,077
  • 2
  • 25
  • 50