Skip to content

Latest commit

 

History

History
87 lines (54 loc) · 2.09 KB

1.1Panel data.md

File metadata and controls

87 lines (54 loc) · 2.09 KB

1.Panel data

1.1 Linear regression models

In general, panel data included two perspectives: the cross-sectional level and the time series level, including more information than traditional linear regression models. Thus, some researchers proposed fixed effect and random effect models to deal with unobserved heterogeneity problems, with relative to the pooled ols model.

Stata code


**pooled ols with robust error
reg y x1 x2 x3, vce(cluster id)
estimates store ols

**Fixed Effects
xtreg y x1 x2 x3,fe robust

**FE with time fixed effects
xtreg y x1 x2 x3 i.year, fe robust
estimates store fe

**Random Effects
xtreg y x1 x2 x3, re robust theta
**theta is the parameter for the LSDV method or
xtreg y x1 x2 x3, re mle

**statistical test methods

*OLS or RE H0: ui=0
xttest0

*RE or FE
hausman fe re, constant sigmamore or sigmaless

*Time Effects
testparm _Iyear*

*The fixed effect models could not estimate variables that kept unchanged over time, such as gender, education degree. The approximate solution was to add the intersection between the time variable and the unchanged variables.
*heteroskedasticity:xttest3 robust; autocorrelated:xttest2 cluster;cross-sectional correlation: xtserial xtscc y x, fe or fe

*format the output
esttab ols fe using C:\Users\LAYZ\Desktop, replace b(%12.3f) sec(%12.3f) star(0.1,0.05,0.01)

R code


library(plm)
mydata<-read.csv("file path")
ols<-lm(y~x1+x2+x3,data=mydata)

FE<-lm(y~x1+x2+x3+factor(year)+factor(individual_id)-1,data=mydata)
#or FE<-plm(y~x1+x2+x3,index=c("year","individual_id),model="within")

#testing for fixed effects
pFtest(FE,ols)

RE<-plm(y~x1+x2+x3,index=c("year","individual_id"),model="random")

#FE or RE
phtest(FE.RE)

Python code


updating


Reference

Panel Data Analysis Fixed and Random Effects using Stata

Getting Started in Fixed/Random Effects Models using R

Introduction to Econometrics with R