0% found this document useful (0 votes)
334 views

RPubs - Panel Data Examples Using R&Quot

This document provides an example of using R to analyze panel data using random effects models. It summarizes the output of a random effects model fit to panel data with countries and years as indexes. It also discusses using the Hausman test to determine if a random or fixed effects model is a better fit, showing the test results for this data indicate a random effects model is better. Finally, it briefly mentions another approach for longitudinal data is latent growth modeling using the lavaan package.

Uploaded by

jcgutz3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
334 views

RPubs - Panel Data Examples Using R&Quot

This document provides an example of using R to analyze panel data using random effects models. It summarizes the output of a random effects model fit to panel data with countries and years as indexes. It also discusses using the Hausman test to determine if a random or fixed effects model is a better fit, showing the test results for this data indicate a random effects model is better. Finally, it briefly mentions another approach for longitudinal data is latent growth modeling using the lavaan package.

Uploaded by

jcgutz3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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