The Stata Command All Commands Concerning Fixed and Random Effect
The Stata Command All Commands Concerning Fixed and Random Effect
net/publication/342184332
The Stata command all commands concerning fixed and random effect
CITATIONS READS
0 3,090
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Mohamed Nachid Boussiala on 15 June 2020.
Before using xtreg you need to set Stata to handle panel data by using the command
In this case “industry” represents the entities or panels (i) and “Time” represents the time
variable (t).
/*we have a string variable “Industry” that Stata cannot identify; we have to generate a
corresponding numerical variable by typing*/
regress I F K
or this reg I F K
testparm F K
regress I F K D2 D3 D4 or
regress I F K D2-D4 or
reg I F K i.ind
testparm i.ind
xtrc I F K
/*The test included with the random-coefficients model also indicates that the assumption of
parameter constancy is not valid for these data. if we cannot accepte H0*/
regress I F K d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 or
regress I F K d2-d20 or
reg I F K i.Time
Now Stata gives the poolability test result after the regression with the factor variable i.Time:
testparm i.Time
/*(iii) Slope coefficients constant but intercept varies over companies and time.
regress I F K D2 D3 D4 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 or
In this case in Stata, we can do the poolability test in three ways. First we test the null of zero
testparm i.ind
testparm i.Time
testparm i.ind
testparm i.ind#c.F
testparm i.ind#c.K
/*(vi) All coefficients (intercept and slope) vary over companies and time.
xtreg I F K, fe
*We can have the estimates of the individual (cross section or panel) effects
predict IE, u
This will generate the individual effects (IE) that can be viewed in the Data Editor (Edit). Note
that we can give any name , instead of IE, for example, the command
predict pe, u
xtreg I F K, re
θ = 1 − sqrt((σ²v /(σ²v+T*σ²µ))*/
xtreg I F K, re theta
xtreg I F K, fe
estimates store fe
xtreg I F K, re
/*And do the Hausman test by typing ,,: statistics > postestimation >
manage estimaion > specification ,diagnostic and goodness of fit > hausman test*/
hausman fe
/*The test fails to reject the null, as the p-value (Prob>chi2) is greater than 5%. Note that the
Hausman test is a test of
===========================================================
/*The least square dummy variable model (LSDV) provides a good way to understand fixed
effects.
By adding the dummy for each country we are estimating the pure effect of x1 (by
regress I F K
(using areg)
“Although its output is less informative than regression with explicit dummy variables,
areg does have two advantages. It speeds up exploratory work, providing quick feedback about
whether a dummy variable approach is worthwhile.
Secondly, when the variable of interest has many values, creating dummies for each of
them could lead to too many variables or too large a model ….” (Hamilton, 2006, p.180)*/
areg I F K , absorb(ind)
areg I F K , absorb(Time)
/*To compare the previous methods type “estimates store [name]” after running each regression, at
the end use the command “estimates table…”:*/
xtreg I F K, fe
areg I F K, absorb(ind)
To see if time fixed effects are needed when running a FE model use the
command testparm. It is a joint test to see if the dummies for all years are equal
to 0, if they are then no time fixed effects are needed (type help testparm for
more details)*/
xtreg I F K i.Time, fe
testparm i.Time
The LM test helps you decide between a random effects regression and a simple
OLS regression.
The null hypothesis in the LM test is that variances across entities is zero. This is,
xtreg I F K , re
xttset0
Test: Var(u) = 0
Testing for cross-sectional dependence/contemporaneous correlation: using Breusch-Pagan LM
test of independence
According to Baltagi, cross-sectional dependence is a problem in macro panels with long time
series (over 20-30 years). This is not much of a problem in micro panels (few years and large
number of cases).
The null hypothesis in the B-P/LM test of independence is that residuals across entities are not
correlated. The command to run this test is xttest2 (Type xttest2 for more info. If not available try
installing it by typing ssc install xttest2):run it after xtreg I F K , fe */
xttest2
panels with long time series (over 20-30 years) than in micro panels.
Pasaran CD (cross-sectional dependence) test is used to test whether the residuals are
correlated across entities. Cross-sectional dependence can lead to bias in tests results (also
called contemporaneous correlation). The null hypothesis is that residuals are not correlated.
The command for the test is xtcsd, you have to install it typing ssc install xtcsd
Had cross-sectional dependence be present Hoechle suggests to use Driscoll and Kraay standard errors
using the command xtscc (install it by typing ssc install xtscc). */
A test for heteroskedasticiy is available for the fixed- effects model using the command
/*The null is homoskedasticity (or constant variance). If p-value< 0.05 we cannot accept the null and
conclude heteroskedasticity. Type help xttest3 for more details.
NOTE: Use the option ‘robust’ to obtain heteroskedasticity-robust standard errors (also known as
Huber/White or sandwich estimators).*/
/* Testing for serial correlation
Serial correlation tests apply to macro panels with long time series (over 20-30 years). Not a problem
in micro panels (with very few years). Serial correlation causes the standard errors of the coefficients
to be smaller than they actually are and higher R-squared .
A Lagram-Multiplier test for serial correlation is available using the command xtserial.
xtserial I F K
/* The null is no serial correlation. Above we cannot accept the null and conclude the
data have first-order autocorrelation. Type help xtserial for more details.*/
/* “ xtunitroot performs a variety of tests for unit roots (or stationarity) in panel datasets. The Levin-
Lin-Chu (2002), Harris-Tzavalis (1999), Breitung (2000; Breitung and Das 2005), Im-Pesaran-Shin
(2003), and Fisher-type (Choi 2001) tests have as the null hypothesis that all the panels contain a unit
root. The Hadri (2000) Lagrange multiplier (LM) test has as the null hypothesis that all the panels are
(trend) stationary. The top of the output for each test makes explicit the null and alternative
hypotheses. Options allow you to include panel-specific means (fixed effects) and time trends in the
model of the data-generating process” [Source: http://www.stata.com/help.cgi?xtunitroot or type help
xtunitroot]
Syntax
Levin-Lin-Chu test
Harris-Tzavalis test
Breitung test
Im-Pesaran-Shin test
=======================================================
Table 1: Selection of Stata commands and options that produce robust standard error estimates for
linear panel models.
SE estimates are
Command Option robust to dis Notes
turbances being
reg, xtreg robust heteroscedastic
heteroscedastic and
reg, xtreg cluster()
autocorrelated
autocorrelated with
xtregar
AR(1)1
heteroscedastic and
newey autocorrelated of type
MA(q)2
heteroscedastic,
contemporaneously N < T required for
cross-sectionally feasibility; tends to
xtgls panels(),corr ()
correlated, and produce optimistic SE
autocorrelated of type estimates
AR(1)
heteroscedastic,
contemporaneously
large-scale panel
cross-sectionally
xtpcse Correlation () regressions with xtpcse
correlated, and
take a lot of time
autocorrelated of type
AR(1)
heteroscedastic,
autocorrelated
xtscc
with MA(q), and cross-
sectionally dependent
1 AR(1) refers to first-order autoregression
2 MA(q) denotes autocorrelation of the moving average type with lag length q.