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


          • #6
            Kindly provide the command for linear Oaxaca Blinder explained and unexplained and covariates plot in STATA.

            Comment


            • #7
              Originally posted by Kumar Vijay View Post
              Kindly provide the command for linear Oaxaca Blinder explained and unexplained and covariates plot in STATA.
              I think coefplot could work. Do you have an example to show us?

              Comment


              • #8
                graph Oaxaca-blinder.gph using this commond coefplot, drop(overall:group*) xline(0) recast(bar) barwidth(.7) base(0) citop ciopts(recast(rcap)), i had able to find attached this graph kindly provide the code for above mentioned plot for different quantilesas my covariates are many.
                Thank you for your consideration

                Comment


                • #9
                  What command are you using to get the OB estimates? If it is identical to #1, follow #2 and #4. If it is different, type

                  Code:
                  help command name
                  where you replace command name with the actual command name. There, you can look at examples using e.g., one of Stata's datasets or an open access dataset. Then you can recreate a reproducible example using that dataset. I am willing to help, but I cannot do so on the basis of the information that you have provided.
                  Last edited by Andrew Musau; 12 Mar 2025, 05:18.

                  Comment

                  Working...
                  X