Wednesday, August 15, 2012

A brief look at fe vs re


global num_reps = 100
* Set the number of repetitions

quietly forv i = 1(1)$num_reps {
* Loop through the simulation 100 times

gl noi
if `i'==1 gl noi noi
  * Only display regression results on the firt loop

clear
set obs 1000

gen id = _n

gen het = rnormal()
  label var het "Individual heterogeneity"
gen xauto = rnormal()
  label var xauto "Autocorrelation in x"
gen uauto = rnormal()
  label var uauto "Autocorrelatoin in u"

expand 5
  * Create 5 observations per individual

gen x = rnormal() + .5*xauto
  * Generate an x that is part auto correlated and part unique draws
 
gen y = 5*x + rnormal()*50 + uauto*25
  * Generate a y in which error is also autocorrelated by individual

bysort id: gen t=_n
  * Create a time variable

xtset id t
  * Assign panel data indicators

$noi xtreg y x, fe
  * Run a fixed effect regression
gl fe`i' =  _b[x]
  * Save the results in the global fe#
 

$noi xtreg y x, re
  * Run a random effect regression
gl re`i' =  _b[x]
  * Save the results in the global re#

noi di `i'
  * Display repetition number
}

* Clear the old memory
clear
set obs $num_reps

* Create empty variable holders.
gen re=.
gen fe=.

* Loop through the repetititions saving each to a variable
forv i=1(1)$num_reps {
  replace re = ${re`i'} if _n==`i'
  replace fe = ${fe`i'} if _n==`i'
}

sum re fe

1 comment:

  1. this is very interesting, but I'm not quite sure, what I should take from this. The differences are small, that it doesn't matter? Be aware of autocorrelation? RE leads to better results?

    ReplyDelete