library(plm)
data("Grunfeld", package = "plm")
<- Grunfeld df
Panel Data
Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
1. Load in data “Grunfeld”
In “Grunfeld”, the time component is “year” whereas the entity component is “firm”.
The data is balanced because “year” increases by 1 unit every year, while the firms staty the same.
2. OLS Regression and Coefficients Estimation
A OLS regression is run on “value” with respect to “inv” (gross investment) and “capital” (stock of plant and equipment).
The coefficients are statistically significant with the p-value for “investment” being lower than 0.001, “Investment” appears to be reasonable as it as a coefficient of 5.7598. while the p-value for “capital” is 0.00371 which indicates a modest level of statistical importance.
The p-value for “capital” is 0.00371 which indicates a modest level of statistical importance. In addition, “capital” seems unconventional with a modest -0.6153 coefficient, suggesting each unit increase in “Capital” decreases “Value” by 0.6153. There appears to be irregularities that is causing this issue potentially “omitted variable bias”.
<- lm(df$value ~ df$inv + df$capital)
OLS_model
summary(OLS_model)
Call:
lm(formula = df$value ~ df$inv + df$capital)
Residuals:
Min 1Q Median 3Q Max
-2010.54 -339.50 -184.08 76.66 2707.84
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 410.8156 64.1419 6.405 1.08e-09 ***
df$inv 5.7598 0.2909 19.803 < 2e-16 ***
df$capital -0.6153 0.2095 -2.937 0.00371 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 666.5 on 197 degrees of freedom
Multiple R-squared: 0.7455, Adjusted R-squared: 0.7429
F-statistic: 288.5 on 2 and 197 DF, p-value: < 2.2e-16
3. Fixed Effect
\[ df$value = 410.8156 + 2.5694 * inv - 0.5885* capital + ε \]
Now our coefficients change again, and the statistical importance increases as well. The coefficient for “value” increases to 2.5694 while the coefficient for “capital” increases to -0.5885. This is because: by running a model that controls firm and time, we are able to reduce the effect of those two variables.
library(lfe)
Loading required package: Matrix
Attaching package: 'lfe'
The following object is masked from 'package:plm':
sargan
<- felm(df$value ~ df$inv + df$capital | df$firm + df$year, data = df)
fixed_effects_model_lfe
summary(fixed_effects_model_lfe)
Call:
felm(formula = df$value ~ df$inv + df$capital | df$firm + df$year, data = df)
Residuals:
Min 1Q Median 3Q Max
-760.84 -105.29 4.94 129.14 1042.21
Coefficients:
Estimate Std. Error t value Pr(>|t|)
df$inv 2.5694 0.3002 8.560 6.65e-15 ***
df$capital -0.5885 0.1605 -3.666 0.000329 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 241.7 on 169 degrees of freedom
Multiple R-squared(full model): 0.9713 Adjusted R-squared: 0.9662
Multiple R-squared(proj model): 0.3601 Adjusted R-squared: 0.2465
F-statistic(full model):190.6 on 30 and 169 DF, p-value: < 2.2e-16
F-statistic(proj model): 47.54 on 2 and 169 DF, p-value: < 2.2e-16
By running a plm() model that also controls “time” and “firm”, we saw the coefficients remain the same as the felm() model.
library(plm)
<- pdata.frame(df)
df
<- plm(df$value ~ df$inv+ df$capital, data = df, model = "within", effect = "twoways")
fixed_effects_model_plm summary(fixed_effects_model_plm)
Twoways effects Within Model
Call:
plm(formula = df$value ~ df$inv + df$capital, data = df, effect = "twoways",
model = "within")
Balanced Panel: n = 10, T = 20, N = 200
Residuals:
Min. 1st Qu. Median 3rd Qu. Max.
-760.8351 -105.2869 4.9391 129.1363 1042.2079
Coefficients:
Estimate Std. Error t-value Pr(>|t|)
df$inv 2.56940 0.30015 8.5604 6.653e-15 ***
df$capital -0.58847 0.16051 -3.6664 0.0003292 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Total Sum of Squares: 15422000
Residual Sum of Squares: 9869100
R-Squared: 0.36006
Adj. R-Squared: 0.24646
F-statistic: 47.543 on 2 and 169 DF, p-value: < 2.22e-16