Announcement

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

  • Visualization of RIF oaxaca blinder decomposition

    Hello stata-Community,

    I run an RIF Oaxaca Blinder decomposition at deciles. I would now like to create a graph to visualize the explained and unexplained part of my two explainatory variables.

    stata forum oaxaca graph.png

    I manage to do it for a singe decile, but I don't manage to combine all deciles in one graph.

    This is my code for the first decile with stata example data.

    Can someone help me?



    Code:
    *Example data
    sysuse nlsw88
    
    *make race a binal variable
    drop if race ==3
    
    *CALCULATE RIF-variables
    *create deciles and get decile values
    xtile decile = wage, nq(10)
    pctile P10 = wage, nquantiles(10)
    tab decile
    list P10 if P10 !=., noobs
    
    *generate quantil variables
    forvalues d = 1/9 {
        gen DEC`d'0 = 0
        replace DEC`d'0 = 1 if decile <= `d'
    } 
    
    *generate RIF-variables
    forvalues d = 1/9 {
        egen rif_`d'0 = rifvar(wage), q(`d'0) kernel(gaussian)
    } 
    
    
    oaxaca rif_10 married grade south occupation , by(race) detail weight(1)
    mat list e(b)
    
    coefplot (., keep(explained: married south )),  bylabel("Explained") || ///
    (., keep(unexplained:*)),  bylabel("Unexplained") || , ///
    drop(*: grade occupation _cons) recast(bar) barwidth(0.5) citop ciopts(recast(rcap) color(black)) ///
    byopts(cols(1)) xline(0, lpattern(dash)) xlabel(, grid glstyle(minor_grid) glpattern(dash))

  • #2
    oaxaca and coefplot are from SSC, as you are asked to explain (FAQ Advice #12). Thanks for the data example. Displaying 9 \(\times\) 2 = 18 coefficients in one graph might be a bit much, but here's an approach using the first 4.

    Code:
    *Example data
    sysuse nlsw88, clear
    
    *make race a binal variable
    drop if race ==3
    
    *CALCULATE RIF-variables
    *create deciles and get decile values
    xtile decile = wage, nq(10)
    pctile P10 = wage, nquantiles(10)
    tab decile
    list P10 if P10 !=., noobs
    
    *generate quantil variables
    forvalues d = 1/9 {
        gen DEC`d'0 = 0
        replace DEC`d'0 = 1 if decile <= `d'
    } 
    
    *generate RIF-variables
    forvalues d = 1/9 {
        egen rif_`d'0 = rifvar(wage), q(`d'0) kernel(gaussian)
    } 
    
    estimates clear
    forval d=1/4{
        eststo Decile`d': oaxaca rif_`d'0 married grade south occupation , by(race) detail weight(1)
    }
    
    coefplot  (Decile*, aseq keep(explained: married south)),  bylabel("Explained") || ///
    (Decile*, aseq keep(unexplained:married south)),  bylabel("Unexplained") || , ///
     recast(bar) barwidth(0.5) citop ciopts(recast(rcap) color(black))  ///
    byopts(cols(1)) xline(0, lpattern(dash)) xlabel(, grid glstyle(minor_grid) glpattern(dash))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	68.7 KB
ID:	1769632

    Comment


    • #3
      Wow, thank you so much!! it works perfecty for my code!

      Can I ask one more question? I would like to give the bars for "married" a different color than "south", I don't manage to change the color separately for the two variables.

      Comment


      • #4
        You'll need to differentiate the plots, something like this:

        Code:
        *Example data
        sysuse nlsw88, clear
        
        *make race a binal variable
        drop if race ==3
        
        *CALCULATE RIF-variables
        *create deciles and get decile values
        xtile decile = wage, nq(10)
        pctile P10 = wage, nquantiles(10)
        tab decile
        list P10 if P10 !=., noobs
        
        *generate quantil variables
        forvalues d = 1/9 {
            gen DEC`d'0 = 0
            replace DEC`d'0 = 1 if decile <= `d'
        }
        
        *generate RIF-variables
        forvalues d = 1/9 {
            egen rif_`d'0 = rifvar(wage), q(`d'0) kernel(gaussian)
        }
        
        estimates clear
        forval d=1/4{
            eststo Decile`d': oaxaca rif_`d'0 married grade south occupation , by(race) detail weight(1)
        }
        
        *Example data
        sysuse nlsw88, clear
        
        *make race a binal variable
        drop if race ==3
        
        *CALCULATE RIF-variables
        *create deciles and get decile values
        xtile decile = wage, nq(10)
        pctile P10 = wage, nquantiles(10)
        tab decile
        list P10 if P10 !=., noobs
        
        *generate quantil variables
        forvalues d = 1/9 {
            gen DEC`d'0 = 0
            replace DEC`d'0 = 1 if decile <= `d'
        }
        
        *generate RIF-variables
        forvalues d = 1/9 {
            egen rif_`d'0 = rifvar(wage), q(`d'0) kernel(gaussian)
        }
        
        estimates clear
        forval d=1/4{
            eststo Decile`d': oaxaca rif_`d'0 married grade south occupation , by(race) detail weight(1)
        }
        
        coefplot  (Decile*, aseq keep(explained: married))(Decile*, aseq keep(explained: south)),  bylabel("Explained") || ///
        (Decile*, aseq keep(unexplained:married)) (Decile*, aseq keep(unexplained:south)),  bylabel("Unexplained") || , ///
         recast(bar) barwidth(0.5) citop ciopts(recast(rcap) color(black)) p1(bcolor(red)) p2(bcolor(blue)) ///
        byopts(cols(1)) xline(0, lpattern(dash)) xlabel(, grid glstyle(minor_grid) glpattern(dash)) nokey
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	72.2 KB
ID:	1769668

        Comment


        • #5
          amazing! Thank you so much!

          Comment

          Working...
          X