-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFixed_Effects_Models.do
More file actions
135 lines (88 loc) · 4.73 KB
/
Fixed_Effects_Models.do
File metadata and controls
135 lines (88 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
* This do file uses various commands to run fixed effects models. The data used is extracted from World Development Indicators (2000-2021).
* Author: Ian He
* Date: Apr 22, 2023
*************************************************************************
clear all
global localdir "D:\research\Fixed Effects Model"
global dtadir "$localdir\Data"
global tabdir "$localdir\Table"
*************************************************************************
**# FE regressions
use "$dtadir\WDI21.dta", clear
* Use "xtreg, fe"
eststo xtreg1: xtreg ln_gdppc ln_trade ln_labor, fe robust
eststo xtreg2: xtreg ln_gdppc ln_trade ln_labor i.year, fe robust
estout xtreg*, keep(ln_trade ln_labor) ///
coll(none) cells(b(star fmt(3)) se(par fmt(3))) ///
starlevels(* .1 ** .05 *** .01) legend ///
stats(N r2_a, nostar labels("Observations" "Adjusted R-Square") fmt("%9.0fc" 3))
* Use "areg, absorb( )"
eststo areg1: areg ln_gdppc ln_trade ln_labor, absorb(country_code) cluster(country_code)
eststo areg2: areg ln_gdppc ln_trade ln_labor i.year, absorb(country_code) cluster(country_code)
estout xtreg1 areg1 xtreg2 areg2, keep(ln_trade ln_labor) ///
coll(none) cells(b(star fmt(3)) se(par fmt(3))) ///
starlevels(* .1 ** .05 *** .01) legend ///
stats(N r2_a, nostar labels("Observations" "Adjusted R-Square") fmt("%9.0fc" 3))
* Use "reghdfe, absorb( )"
eststo hdreg1: reghdfe ln_gdppc ln_trade ln_labor, absorb(country_code) cluster(country_code)
eststo hdreg2: reghdfe ln_gdppc ln_trade ln_labor, absorb(country_code year) cluster(country_code)
estout xtreg1 areg1 hdreg1 xtreg2 areg2 hdreg2, keep(ln_trade ln_labor) ///
coll(none) cells(b(star fmt(3)) se(par fmt(3))) ///
starlevels(* .1 ** .05 *** .01) legend ///
stats(N r2_a, nostar labels("Observations" "Adjusted R-Square") fmt("%9.0fc" 3))
* Export results to LaTeX
estout xtreg1 areg1 hdreg1 xtreg2 areg2 hdreg2 using "$tabdir\compare_reg_commands.tex", keep(ln_trade ln_labor) ///
sty(tex) label mlab(none) coll(none) ///
cells(b(star fmt(3)) se(par fmt(3))) ///
starlevels(* .1 ** .05 *** .01) ///
preh("\begin{tabular}{p{0.2\textwidth}p{0.1\textwidth}p{0.1\textwidth}p{0.1\textwidth}p{0.1\textwidth}p{0.1\textwidth}p{0.1\textwidth}}" "\hline \hline" ///
"& (1) & (2) & (3) & (4) & (5) & (6) \\" ///
"& xtreg & areg & reghdfe & xtreg & areg & reghdfe \\ \hline" ) ///
prefoot("\hline" ///
"Country FE & \checkmark & \checkmark & \checkmark & \checkmark & \checkmark & \checkmark \\ " ///
"Year FE & & & & \checkmark & \checkmark & \checkmark \\ ") ///
stats(N r2_a, nostar labels("Observations" "Adjusted R-Squared") fmt("%9.0fc" 3)) ///
postfoot("\hline\hline" "\end{tabular}") replace
*************************************************************************
**# Is time FE a good ingredient for our lunch?
use "$dtadir\WDI21.dta", clear
* Null: We don't need time FE.
* If `r(p)' is less than 0.05, reject the null and add time FE.
xtreg ln_gdppc ln_trade ln_labor i.year, fe robust
testparm i.year
*************************************************************************
**# Choose FE or RE?
* Here I don't use "robust" option because the "hausman" command cannot work with it (and all cluster-robust covariance estimators).
xtreg ln_gdppc ln_trade ln_labor, fe
estimates store fixed
xtreg ln_gdppc ln_trade ln_labor, re
estimates store random
* If `r(p)' is less than 0.05, use FE regression.
hausman fixed random, sigmaless
*************************************************************************
**# Choose RE or OLS?
* Null: We don't need a RE model.
* If `r(p)' is less than 0.05, reject the null and use the RE model.
xtreg ln_gdppc ln_trade ln_labor, re robust
xttest0
*************************************************************************
**# Test the correlation among countries (or individuals, in general)
* Null: No correlation.
* If `Pr' is less than 0.05, reject the null; the data are correlated across countries.
* ssc install xttest2, replace
xtreg ln_gdppc ln_trade ln_labor, fe robust
xttest2 // Breusch-Pagan Lagrange multiplier test
*************************************************************************
**# Hetero or Homo?
* Null: Homoskedasticity.
* If `r(p)' is less than 0.05, reject the null; there exists heteroskedasticity.
* ssc install xttest3, replace
xtreg ln_gdppc ln_trade ln_labor, fe robust
xttest3
*************************************************************************
**# Test the serial correlation
* Null: No serial correlation.
* If `r(p)' is less than 0.05, reject the null; there is serial correlation.
* net install xtserial.pkg, replace
xtreg ln_gdppc ln_trade ln_labor, fe robust
xtserial ln_gdppc ln_trade ln_labor