Announcement

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

  • Addplot: overlay a twoway graph on coefplot

    Hello, I need to overlay a simple line plot on the top of a coefplot graph (obtained by combining two regressions using reghdfe). In theory, the two should have the same values on the x-axis. In practice, they don't, because I manually renamed the interactions in coefplot with years.

    This is my code:

    eststo mig1: reghdfe asinh_mig_ss high_rei##ib2000.year if year <2006, absorb (district#year country#year district#country ) cluster(district)
    eststo mig2: reghdfe asinh_mig_podes high_rei##ib2005.year, absorb (district#year country#year district#country ) cluster(district)

    coefplot (mig1, mcolor(maroon) symbol(X) ciopts(recast(rcap) color(maroon)) keep(1.high_rei#2000.year 1.high_rei#*.year) drop(1.high_rei#2005.year 1.high_rei#2008.year 1.high_rei#2011.year 1.high_rei#2014.year ) omitted baselevels ///
    rename( 1.high_rei#2000.year = 2000 ///
    1.high_rei#2001.year = 2001 ///
    1.high_rei#2002.year = 2002 ///
    1.high_rei#2003.year = 2003 ///
    1.high_rei#2004.year = 2004)) ///
    (mig2, keep(1.high_rei#2005.year 1.high_rei#2008.year 1.high_rei#2011.year 1.high_rei#2014.year ) omitted baselevels ///
    rename(1.high_rei#2005.year = 2005 ///
    1.high_rei#2008.year = 2008 ///
    1.high_rei#2011.year = 2011 ///
    1.high_rei#2014.year = 2014) mcolor(black) ciopts(recast(rcap) color(black)) ), ///
    label yline(0) levels(95) vertical ylabel(, angle(horizontal)) graphregion(color(white)) bgcolor(white) offset(0)


    addplot: line REI_med_1 year if tag1, sort xaxis(2)

    The best I obtained is this graph, using "addplot" with xaxis(2)
    Click image for larger version

Name:	plot_stata.png
Views:	1
Size:	23.8 KB
ID:	1697875



    Does anyone have a solution? I thought about using marginsplot, but I would not know how given the multiple nested groups.

  • #2
    coefplot and estout are community-contributed from SSC, as you are asked to explain (FAQ Advice #12). There is an -addplot()- option of twoway that is suppored by coefplot (as opposed to the addplot command).

    Comment


    • #3
      Thank you Andrew. Even adding addplot(line REI_med_1 year if tag, sort xaxis(2)) at the end of the coefplot command does not solve the isse

      Comment


      • #4
        You need to create a reproducible example.

        Comment

        Working...
        X