본문 바로가기

계량경제학/인과추론의 데이터과학

Two-way Fixed Effects

https://theeffectbook.net/ch-FixedEffects.html

 

Chapter 16 - Fixed Effects | The Effect

Chapter 16 - Fixed Effects | The Effect is a textbook that covers the basics and concepts of research design, especially as applied to causal inference from observational data.

theeffectbook.net

위 글을 참고하여 작성한 글입니다 


Two-way Fixed Effects (TWFE)

개인의 효과가 시간이 지남에 따라서 달라지는 것을 관측할 때 개인에 대한 고정효과, 시간에 대한 고정효과를 모두 포함하는 것 

+) TWFE는 무조건 개인과 시간에 대한 fixed effect만 포함할 수 있는건 당연히 아님! (individual, country에 대한 효과 등) 

import linearmodels as lm
from causaldata import gapminder
gm = gapminder.load_pandas().data

gm['logGDPpercap'] = gm['gdpPercap'].apply('log')

# Set our individual and time (index) for our data
gm = gm.set_index(['country','year'])

mod = lm.PanelOLS.from_formula(
"""lifeExp ~ logGDPpercap + 
             EntityEffects + 
             TimeEffects""",gm)

twfe = mod.fit()
print(twfe)

 

결과 해석 

  • country를 EntityEffects으로, year을 TimeEffects으로 fixed effect를 고려함
  • -> logGDPpercap의 coefficient = 1.4499 

Random Effects

fixed effect

  • 관찰을 토대로 βi를 추론함
  • 단점: βi 별 관찰 수가 적다면 βi를 추론하는 것이 noisy 함 

 

random effect

  • βi는 알고있는 어떤 distribution에서 나왔다고 가정함. (ex. 정규분포 등) 
  • The random effects assumption is that the individual-pecific effects are uncorrelated with the independent variables. -> 현실적으로 적용하기 어려움
  • ex) GDP가 기대수명에 미치는 영향 연구에서 random effect를 사용하여 X와 Y의 관계를 추정하려고 할 때, 기대수명을 결정하는 GDP를 제외한 모든 요인은 GDP와 관련이 없어야 함! 
  • 변수들이 randomized assign 된 RCT에서는 적용 가능함 

Clustered Standard Errors

regression model에서는 error term이 서로 independent 하다는 가정을 만족해야 함 

fixed effect model에서는 error term의 independent 가정이 만족하기 어려움 

error term은 εit으로, 동일한 개인에 대해서 받음 -> 개인 또는 그룹 안에서 상관관계가 생길 수 있음 

-> clustered standard error 사용해야 함 

 

clustered standard errors를 사용하기 위한 조건

  1. treatment effect heterogeneity: 치료 효과가 개인마다 서로 달라야 함 
  2. fixed effect group이 모집단의 non-random sampling 이거나, treatment variable이 clustered으로 할당되어야 함