Announcement

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

  • Adding a variable to the variable's axis of a coefficients plot made with "coefplot"

    Hello everybody.

    Does anyone know how I can add the name of the variable corresponding to the omitted interaction (the interaction between a dummy variable and the reference category of a categorical variable) to the variable's axis of a coefficients plot made with command "coefplot"? In variable axis of the graph, I´m showing 5 variables (-3, -2, -1, 1 and 2). Each variable corresponds to the interaction between a dummy variable and a category (period) of a time variable. Because period 0 is the reference category, interaction between the dummy and period 0 is omitted. However, I need period 0 to be shown in the variable axis of the graph. Because there is no coefficient to period 0, “coefplot” don’t show me the variable. However, I need it.

    Code:
    coefplot (Homicidio_total), ///
    yline (0) ///
    vertical ///
    keep (1.tratamiento#1.mes2 1.tratamiento#2.mes2 1.tratamiento#3.mes2 1.tratamiento#4.mes2 1.tratamiento#5.mes2) ///
    coeflabels (1.tratamiento#1.mes2 = "-3" 1.tratamiento#2.mes2 = "-2" 1.tratamiento#3.mes2 = "-1" 1.tratamiento#4.mes2 = "1" 1.tratamiento#5.mes2 = "2") ///
    xtitle(Months) ///
    msymbol(o) ///
    levels(99 95)
    I need the graph that has a 0 in the x axis, but I currently have the grpah that doesn't have a 0 in the x axis (I need a 0 between -1 and 1).


    Attached Files

  • #2
    coefplot is from SSC, authored by Ben Jann. You are asked to specify the source of user-written commands, see the FAQs. You have the baselevels option in coefplot to include the base level in the plot

    Code:
    coefplot, baselevels
    You also have the addplot option to include additional plots as well as the possibility of extracting the regression results from r(table) and putting these into a matrix, then plotting as shown in #4 of this link. Having said all that, the base coefficient has a value of zero and no confidence interval. Including it in the plot serves no useful purpose and you could just add a note at the bottom of the graph stating "the base category is month=0".

    Comment


    • #3
      Thank you very much Andrew. I was able to do what I wanted thanks to your advise. Now, I'm just wondering how to eliminate the dot corresponding to month 0. Is there a way to eliminate this dot only, or at least, a way to reduce its size? I tried the following 2 options but they didn't work:

      Code:
      msize (small small small tiny small small)
      
      msize (2.3 2.3 2.3 1 2.3 2.3)
      The full code of my graph is the following:

      Code:
      reg Homicidio_total i.tratamiento##i.mes2 i.hora i.fecha, vce(cluster fecha)
      
      coefplot, ///
      baselevel ///
      drop (*tratamiento 0.tratamiento#0.mes2 1.mes2 2.mes2 3.mes2 4.mes2 5.mes2 _cons *hora_entera *fecha) ///
      order (1.tratamiento#1.mes2 1.tratamiento#2.mes2 1.tratamiento#3.mes2) ///
      coeflabels (0.mes2 = "0" 1.tratamiento#1.mes2 = "-3" 1.tratamiento#2.mes2 = "-2" 1.tratamiento#3.mes2 = "-1" 1.tratamiento#4.mes2 = "1" 1.tratamiento#5.mes2 = "2") ///
      xtitle(Mes, size (vsmall)) ///
      vertical ///
      xline (4, lpattern(dash)) ///
      yline (0) ///
      msymbol(o) ///
      levels(99 95 90) ///
      ciopts(lwidth(*1 *2 *3)) ///
      legend(title ("Niveles de confianza", size (vsmall)) order(1 "99%" 2 "95%" 3 "90%") row (1) size (vsmall)) ///
      ylabel(,labsize(vsmall)) ///
      xlabel(,labsize(vsmall)) ///
      msize (2.3) ///
      legend(symys(*.5) symxs(*.5) size(3) region(c(none)) bm(tiny))
      This is the graph:
      Attached Files

      Comment


      • #4
        You do not provide a data example, but here is one way. The idea is to turn the coefficient of the base category from zero to missing. You will not be able to do this directly in the stored coefficients' matrix -e(b)-, but as stated in #2, coefplot allows you to use a matrix as the input.

        Code:
        sysuse auto
        regress mpg i.rep78
        *PUT REGRESSION RESULTS IN A MATRIX
        mat r= r(table)
        *WE JUST NEED THE FIRST 6 ROWS IN THIS INSTANCE.
         mat R= r[1..6,1..6]
        *SAME PLOT AS RUNNING COEFPLOT AFTER REGRESSION
        coefplot matrix(R), drop(_cons) se(2) baselevels
        *BASE LEVEL 1b.rep78. TURN COEFFICIENT FROM 0 TO MISSING
        mat list R
         mat R[1,1]=.
        *PROCEED
        coefplot matrix(R), drop(_cons) se(2) baselevels

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.9 KB
ID:	1469748
        Last edited by Andrew Musau; 10 Nov 2018, 07:41.

        Comment


        • #5
          Hi Andrew, thank you very much again. I was finally able to make the graph I wanted. I just had to add coefplot option "omitted" to your code.
          Code:
          *Regression
          reg yvar i.tratamiento##i.mes2 i.hora i.fecha, vce(cluster fecha)
          
          *Matrix
          mat resultados = r(table)
          mat grafico = resultados[1..6, 15..20]
          mat grafico[1,1]=.        
              
          *Graph
          coefplot matrix(grafico), ///
          se(2) ///
          baselevels ///
          omitted ///
          order (1.tratamiento#1.mes2 1.tratamiento#2.mes2 1.tratamiento#3.mes2) ///
          coeflabels (1.tratamiento#0.mes2 = "0" 1.tratamiento#1.mes2 = "-3" 1.tratamiento#2.mes2 = "-2" 1.tratamiento#3.mes2 = "-1" 1.tratamiento#4.mes2 = "1" 1.tratamiento#5.mes2 = "2") ///
          xtitle(Meses, size (vsmall)) ///
          vertical ///
          xline (4, lpattern(dash) lcolor(black)) ///
          yline (0, lwidth (medthin)) ///
          msymbol(o) ///
          levels(99 95 90) ///
          ciopts(lwidth(*1 *2 *3)) ///
          legend(title ("Niveles de confianza", size (vsmall)) order(1 "99%" 2 "95%" 3 "90%") row (1) size (vsmall)) ///
          ylabel(,labsize(vsmall)) ///
          xlabel(,labsize(vsmall)) ///
          msize (2.3) ///
          legend(symys(*.5) symxs(*.5) size(3) region(c(none)) bm(tiny))
          Attached Files

          Comment

          Working...
          X