본문 바로가기
코딩/뭔가 만들어 보기

[Python] 2015~2020년 대한민국 근로소득 불평등도는 어떻게 변했을까?(지니계수, 로렌츠곡선)

by Say_Young 2022. 12. 11.
1. 시작

국세청에서는 매년 백분위별 근로소득 자료를 공개한다. 최근에 블라인드에서 연봉 1억 넘는 사람들이 정말 많아졌다는 글을 본 것 같았는데, 그렇게 고소득자가 많아졌다면 실제로 불평등도가 높아졌는지 숫자로 확인해 보고 싶었다. 

 

2. 작업방법

스프레드시트 형태로 된 연도별 근로소득 자료를 다운로드 받아서, 파이썬의 Pandas를 이용하여 가공한 후 Matplotblib을 통해 그래프를 그린다. 세전 수입 금액 기준으로 만들었다. 

 

3.  지니계수 복습

경제학 시간에 배웠던 지니계수와 로렌츠곡선을 복습할 시간이다. 

 

통계청에  설명자료가 있다. 

 

https://kostat.go.kr/understand/info/info_lge/1/detail_lang.action?bmode=detail_lang&pageNo=2&keyWord=9&cd=SL4242&sTt= 

 

사전식보기>통계용어및지표>통계이해

통계용어및지표 home 통계용어및지표 사전식보기 사전식보기 지니계수[Gini coefficient] 정의 전체 인구의 소득불평등도를 나타내는 지표로, 로렌츠(Lorenz)곡선과 완전균등선(대각선)이 이루는 면적

kostat.go.kr

지니계수

지니계수는 1에 가까울수록 불평등, 0에 가까울수록 평등이다. 

 

공식을 보자 

 

지니계수 공식
위키피디아 설명

수학공식을 보다 보니 속이 메스껍고 멀미가 밀려온다. 

위키피디아를 믿고 우선 결과를 만들어 내자. 

 

def gini(arr):
    sorted_arr = arr.copy()
    sorted_arr.sort()
    n = arr.size
    coef_ = 2 / n
    const_ = (n + 1) / n
    weighted_sum = sum([(i+1)*yi for i, yi in enumerate(sorted_arr)])
    return coef_*weighted_sum/(sorted_arr.sum()) - const_

 

4. 지니계수 분석 결과

지니계수 분석 결과

어랍쇼? 시간이 갈수록 불평등해지고 있을 것 같다는 예상과는 다르게 지니계수는 감소하고 있다. 

 

5. 로렌츠커브 그리기

숫자로 나오는 지니계수 말고, 그래프로 볼 수 있는 로렌츠커브도 한번 보자.

 

fig = plt.figure(figsize=(20,20)) ## 캔버스 생성
fig.set_facecolor('white') ## 캔버스 색상 설정
ax = fig.add_subplot() ## 그림 뼈대(프레임) 생성
ax.plot([0,1], [0,1], color='k') ## line plot of equality

x1.sort()
x1_lorenz = x1.cumsum() / x1.sum()
x1_lorenz = np.insert(x1_lorenz, 0, 0) 
## scatter plot of Lorenz curve
ax.plot(np.arange(x1_lorenz.size)/(x1_lorenz.size-1), x1_lorenz, 
           marker='x', color='darkgreen', label ="2015")

x6.sort()
x6_lorenz = x6.cumsum() / x6.sum()
x6_lorenz = np.insert(x6_lorenz, 0, 0) 
## scatter plot of Lorenz curve
ax.plot(np.arange(x6_lorenz.size)/(x6_lorenz.size-1), x6_lorenz, 
           marker='x', color='black', label ="2020")

ax.legend() ## 범례

plt.show()

2015 vs 2020 로렌츠커브

2015년에 비해 2020년에 조금 더 평평해진 것을 확인할 수 있다. 

하지만 로렌츠커브는 각 연도별 분배도를 보여줄 뿐, 이러한 변화의 원인을 보여줄 만한 단서를 찾기는 어렵다. 다른 방법을 통해 조금 더 자세히 보자. 

 

6. 소득 분위별 소득 총량 변화 확인하기
first_quartile_2015 = sum(x1[0:20]/10000)
second_quartile_2015 = sum(x1[20:40]/10000)
third_quartile_2015 = sum(x1[40:60]/10000)
fourth_quartile_2015 = sum(x1[60:80]/10000)
fifth_quartile_2015 = sum(x1[80:100]/10000)

series2015 = [first_quartile_2015,
              second_quartile_2015,
              third_quartile_2015,
              fourth_quartile_2015,
              fifth_quartile_2015]

first_quartile_2020 = sum(x6[0:20]/10000)
second_quartile_2020 = sum(x6[20:40]/10000)
third_quartile_2020 = sum(x6[40:60]/10000)
fourth_quartile_2020 = sum(x6[60:80]/10000)
fifth_quartile_2020 = sum(x6[80:100]/10000)

series2020 = [first_quartile_2020,
              second_quartile_2020,
              third_quartile_2020,
              fourth_quartile_2020,
              fifth_quartile_2020]

X = ["1st","2nd","3rd","4th","5th"]


plt.plot(X, series2015, label='2015년')
plt.plot(X, series2020, label='2020년')

current_values = plt.gca().get_yticks()
plt.gca().set_yticklabels(['{:,.0f} 조'.format(x) for x in current_values])
plt.legend()

plt.show

소득 분위별 소득 총량 변화를 통해 유추해 보자면, 저소득층의 근로소득이 크게 늘었다기보다는 고소득층(5분위)의 소득 증가 비율이 2~3분위의 소득 증가 비율에 비해 크게 높지 않았기에 상대적으로 불평등도는 완화된 것으로 지표가 나오지 않았다 싶다.

댓글