Announcement

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

  • coefplot: how to drop coefficients from one of the models but keep it in the others

    I created the below plot using this code

    coefplot (reg1_1, label(CZ and YQ FE)) ///
    (reg1_2, label(CZ, YQ and Occupation FE)) ///
    (reg1_3, label(CZ and Occupation-by-YQ FE)) ///
    (reg1_4, label(CZ, Occupation-by-YQ and Employer FE)), bylabel(Full Sample) ///
    ||(reg2_1, label(CZ and YQ FE)) ///
    (reg2_2, label(CZ, YQ and Occupation FE)) ///
    (reg2_3, label(CZ and Occupation-by-YQ FE)) ///
    (reg2_4, label(CZ, Occupation-by-YQ and Employer FE)), bylabel(By Occupational Wage Rank) ||, ///
    drop(_cons) xline(0) byopts(compact cols(1)) coeflabels(target_cvs_treat_post= "Treat*Post" treat_post_q1 = "Treat*Post*Q1 Wage Rank" treat_post_q2 = "Treat*Post*Q2 Wage Rank" treat_post_q3 = "Treat*Post*Q3 Wage Rank" treat_post_q4 = "Treat*Post*Q4 Wage Rank")



    Click image for larger version

Name:	Screenshot 2024-02-08 at 11.56.06 PM.png
Views:	4
Size:	671.7 KB
ID:	1742581

    The above subfigure is a model with only 1 regressor (target_cvs_treat_post with a label "Treat*Post" ) and the below one is another model with 4 regressors (treat_post_q1 = "Treat*Post*Q1 Wage Rank" treat_post_q2 = "Treat*Post*Q2 Wage Rank" treat_post_q3 = "Treat*Post*Q3 Wage Rank" treat_post_q4 = "Treat*Post*Q4 Wage Rank").

    What I want to do is to remove the 4 regressors of the 2nd model from the above figure, and remove the 1 regressor from the below figure. How can I achieve this??

    I want it to look something similar to this

    Click image for larger version

Name:	Screenshot 2024-02-09 at 12.00.51 AM.png
Views:	2
Size:	214.2 KB
ID:	1742583

    I tried to use the drop option as a modelopts by adding it as an option for the above plot only but it did not work.

    i.e., This does not work

    coefplot (reg1_1, label(CZ and YQ FE) drop(treat_post_q1 treat_post_q2 treat_post_q3 treat_post_q4)) ///
    (reg1_2, label(CZ, YQ and Occupation FE) drop(treat_post_q1 treat_post_q2 treat_post_q3 treat_post_q4)) ///
    (reg1_3, label(CZ and Occupation-by-YQ FE) drop(treat_post_q1 treat_post_q2 treat_post_q3 treat_post_q4)) ///
    (reg1_4, label(CZ, Occupation-by-YQ and Employer FE) drop(treat_post_q1 treat_post_q2 treat_post_q3 treat_post_q4)), bylabel(Full Sample) ///
    ||(reg2_1, label(CZ and YQ FE) drop(target_cvs_treat_post)) ///
    (reg2_2, label(CZ, YQ and Occupation FE) drop(target_cvs_treat_post)) ///
    (reg2_3, label(CZ and Occupation-by-YQ FE) drop(target_cvs_treat_post)) ///
    (reg2_4, label(CZ, Occupation-by-YQ and Employer FE) drop(target_cvs_treat_post)), bylabel(By Occupational Wage Rank) ||, ///
    drop(_cons) xline(0) byopts(compact cols(1)) coeflabels(target_cvs_treat_post= "Treat*Post" treat_post_q1 = "Treat*Post*Q1 Wage Rank" treat_post_q2 = "Treat*Post*Q2 Wage Rank" treat_post_q3 = "Treat*Post*Q3 Wage Rank" treat_post_q4 = "Treat*Post*Q4 Wage Rank")

    Please help!
    Attached Files

  • #2
    coefplot is from SSC as you are asked to explain (FAQ Advice #12). Don't use a -by()- option, this will constrain the axis to include all categories.


    Code:
    sysuse auto, clear
    *ssc install estout, replace
    eststo m1: regress mpg weight disp turn
    eststo m2: regress mpg weight disp turn gear
    coefplot (m1\m2),  drop(_cons) aseq
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.5 KB
ID:	1742627

    Comment


    • #3
      I think this will be a cleaner way of doing it. But what if I want to plot several specifications for m2?

      My goal is to present 2 models: a regression with only one regressor and another regression with 4 regressors. For each regression, I have 4 different fixed effects specifications. I want to show them all in one plot for robustness check. So, how can I include all four specifications in each subplot?

      Comment


      • #4
        You could use graph combine to achieve something similar to what you show in #1. I use the graph editor to delete the axis values shown after including the -xcommon- option of graph combine. These can be useful to ensure that the axes align, so check out the generated graph before the final line of the code. You may need to tweak some values in the example shown below.

        Code:
        sysuse auto, clear
        *ssc install estout, replace
        eststo m1: regress mpg turn if !foreign
        eststo m2: regress mpg weight disp turn gear if !foreign
        eststo m3: regress mpg weight disp turn if foreign
        eststo m4: regress mpg weight disp turn gear if foreign
        coefplot m1,  drop(_cons) saving(gr1, replace) xlab("") xsc(noline) ysc(noline) ylab(,noticks labelminlen(20) labgap(1)) ytitle({bf:Model 1}, orientation(vert))
        coefplot m2 m3 m4, nokey drop(_cons) saving(gr2, replace) ysc(noline) ylab(,noticks labelminlen(20) labgap(1)) ytitle({bf:Model 2}, orientation(vert))
        gr combine gr1.gph gr2.gph, xcommon col(1)
        gr_edit .plotregion1.graph1.xaxis1.reset_rule , tickset(major) ruletype(none)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.1 KB
ID:	1742792

        Comment


        • #5
          To show the legend as well, install grc1leg2.

          Code:
          net install grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")

          Code:
          sysuse auto, clear
          *ssc install estout, replace
          eststo m1: regress mpg turn if !foreign
          eststo m2: regress mpg weight disp turn gear if !foreign
          eststo m3: regress mpg weight disp turn if foreign
          eststo m4: regress mpg weight disp turn gear if foreign
          coefplot m1,  drop(_cons) saving(gr1, replace) xlab("") xsc(noline) ysc(noline) ///
          ylab(,noticks labelminlen(20) labgap(1)) ytitle({bf:Model 1}, orientation(vert))
          coefplot m2 m3 m4, drop(_cons) saving(gr2, replace) ysc(noline) ///
          ylab(,noticks labelminlen(20) labgap(1)) ytitle({bf:Model 2}, orientation(vert)) ///
          legend(order(2 "Whatever 1" 4 "Whatever 2" 6 "Whatever 3"))
          
          grc1leg2 gr1.gph gr2.gph, xcommon col(1) legendfrom(gr2.gph) pos(3)
          gr_edit .plotregion1.graph1.xaxis1.reset_rule , tickset(major) ruletype(none)
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.0 KB
ID:	1742794

          Comment

          Working...
          X