*--------
  *-4.1.4.4  R2 的分解: 解释变量对 R2 的贡献度  (Self-reading)
  
    help shapley2 
        
        *-Israeli, O., 2007
        * A Shapley-based decomposition of the R-Square of a linear regression. 
        * Journal of Economic Inequality, 5(2):199-212.
          shellout "$path\Refs\OLS_Shapley_R2.pdf"  //pp.202
        *-目的: 对 R2 进行分解, 分析每个变量对 R2 的贡献;
        
        *-示例:
          sysuse auto, clear
          pwcorr price weight length   //相关系数
          reg price weight length 
          shapley2, stat(r2) 
        
    *-原理: 如何得到 R2_weight = 0.22559 ?        
         *-weight 对 R2 的边际贡献有两种衡量方法:
            *-m1: R2(y c x1 x2) - R2(y c x2) = R2_m1
            rename (price weight length) (y x1 x2)
            qui reg y x1 x2
            local R2_all = e(r2)
            qui reg y x2
            local R2_x2 = e(r2)
            local R2_m1_x1 = `R2_all'-`R2_x2'
        
            *-m2: R2(y c x1) - R2(y c) = R2_m2
            qui reg y x1
            local R2_x1 = e(r2)
            qui reg y 
            local R2_0  = e(r2)
            local R2_m2_x1 = `R2_x1'-`R2_0'
        
          *-Sharpley value = (R1_m1+R2_m2)/2
            local R2_x1_Sharp = (`R2_m1_x1'+`R2_m2_x1')/2
            dis "Shapley value of weight = " in g %6.5f `R2_x1_Sharp'
        
        *-多变量情形
          sysuse nlsw88, clear
          reg wage age hours tenure married
          shapley2, stat(r2)
        
        *-分组分析
          tab race, gen(dum)
          reg wage age hours tenure married dum2 dum3
          shapley2, stat(r2) group(age hours tenure married, dum2 dum3)