0


stata 代码实现熵值法计算 含常见问题解答

适用:面板数据均可

stata版本:无要求

例如,使用了一个10年的省级面板数据,含15个指标,现在来计算各地区的熵值法得分。其中,x1 x2 x3 x4 x6 x7 x8 x9 x11 x12 x13 x14 x15是正向指标;而x5 x10是负向指标。

1.定义面板,定义指标的正负。

  1. tsset id year
  2. global xlist1 "x1 x2 x3 x4 x6 x7 x8 x9 x11 x12 x13 x14 x15"
  3. global xlist2 "x5 x10"

2.标准化

①正向指标

  1. foreach x of global xlist1{
  2. egen min`x'=min (`x')
  3. egen max`x'=max (`x')
  4. gen standard`x'=(`x'-min`x')/(max`x'-min`x')
  5. }

②负向指标

  1. foreach x of global xlist2{
  2. egen min`x'=min (`x')
  3. egen max`x'=max (`x')
  4. gen standard`x'=(max`x'-`x')/(max`x'-min`x')
  5. }

3.计算第i年变量j的权重

①正向指标

  1. foreach x of global xlist1 {
  2. egen sum`x' =total(standard`x')
  3. gen w1`x'=standard`x' /sum`x'
  4. }

②负向指标

  1. foreach x of global xlist2 {
  2. egen sum`x' =total(standard`x')
  3. gen w1`x'=standard`x' /sum`x'
  4. }

4.信息熵与冗余度

①正向指标

  1. by id, sort: egen m1 =count (year)
  2. foreach x of global xlist1{
  3. **(归一化处理)
  4. gen w`x'=w1`x'+0.0000000001
  5. egen e1`x'=total (w`x' * log(w`x'))
  6. gen d`x'=1+1/log(m1)*e1`x'
  7. }

②负向指标

  1. by id, sort: egen m2 =count (year)
  2. foreach x of global xlist2{
  3. gen w`x'=w1`x'+0.0000000001
  4. egen e1`x'=total (w`x' * log(w`x'))
  5. gen d`x'=1+1/log(m2)*e1`x'
  6. }

5.计算权重(需要改的地方)

  1. gen sumd1 =dx1+dx2+dx3+dx4+dx5+dx6+dx7+dx8+dx9+dx10+dx11+dx12+dx13+dx14+dx15
  2. foreach x of global xlist1{
  3. gen w2`x'=d`x' /sumd1
  4. }
  5. foreach x of global xlist2{
  6. gen w2`x'=d`x' /sumd1
  7. }

需要更改的地方就是第一排,改成自己的指标。

6.计算总指数(需要改的地方)

  1. foreach x of global xlist1{
  2. gen score_`x'=standard`x' * w2`x'
  3. }
  4. foreach x of global xlist2{
  5. gen score_`x'=standard`x' * w2`x'
  6. }
  7. gen score=score_x1+score_x2+score_x3+score_x4+score_x5+score_x6+score_x7+score_x8+score_x9+score_x10+score_x11+score_x12+score_x13+score_x14+score_x15

需要更改的地方就是最后一排,改成自己的指标即可。

常见问题:

①运行完毕后,最后一列score即是熵值法最终得分。

②很多小伙伴关心的各个指标权重, w2`x'列就是权重。比如,w2x6就是x6这个指标的权重。

③该熵值严格意义来讲是截面熵值法,但也能用于面板。大家能找到的面板熵值法代码不建议用,面板熵值会让每个指标在不用地区不同年份都有不同的权重赋值,这样往往会导致结果趋势不理想。


本文转载自: https://blog.csdn.net/qq_39760686/article/details/140726598
版权归原作者 我是章汕呐 所有, 如有侵权,请联系我们删除。

“stata 代码实现熵值法计算 含常见问题解答”的评论:

还没有评论