Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1/16/2018 RPubs - Panel Data Examples using R"

RPubs brought to you byby RStudio


Panel Data Examples using R" Matthew Hanauer Last updated 8 months ago
Sign in Register

summary(random)

Comments (–) Share Hide Toolbars


## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = y ~ x1, data = Panel, model = "random", index = c("country",
## "year"))
##
## Balanced Panel: n=7, T=10, N=70
##
## Effects:
## var std.dev share
## idiosyncratic 7.815e+18 2.796e+09 0.873
## individual 1.133e+18 1.065e+09 0.127
## theta: 0.3611
##
## Residuals :
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -8.94e+09 -1.51e+09 2.82e+08 0.00e+00 1.56e+09 6.63e+09
##
## Coefficients :
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 1037014284 790626206 1.3116 0.1941
## x1 1247001782 902145601 1.3823 0.1714
##
## Total Sum of Squares: 5.6595e+20
## Residual Sum of Squares: 5.5048e+20
## R-Squared: 0.02733
## Adj. R-Squared: 0.013026
## F-statistic: 1.91065 on 1 and 68 DF, p-value: 0.17141

How do we know when to use fixed or random effects? We can use the Hausman Test, where the null
hypothesis is that the model is random effects and the alternative is that fixed effects are better fit. In this
example, the p-value is above .05 so a random effects model is the better fit for this data.

phtest(random, fixed)

##
## Hausman Test
##
## data: y ~ x1
## chisq = 3.674, df = 1, p-value = 0.05527
## alternative hypothesis: one model is inconsistent

Another way to analyze longitudinal data is through Latent Growth Modeling (LGM). LGM models time as a
latent variable similar to a multi-level modeling approach. To analyze LGM in R we use the lavaan package. To
analyze LGM in lavaan we use an artificial data set provided by lavaan The first step is to define the model

https://rpubs.com/mhanauer/278903 1/1

You might also like