The dataset contains panel data on investment behavior for a group of firms. It tracks 10 firms over 20 years and includes variables such as investment, firm value, and capital stock. It is commonly used to study how firms make investment decisions over time.
library(plm)
# built-in panel dataset
data("Grunfeld", package = "plm")
# declare panel structure
pdat <- pdata.frame(Grunfeld, index = c("firm", "year"))
# summary info
info <- pdim(pdat)
# output
cat("Balanced panel:", info$balanced, "\n")
## Balanced panel: TRUE
cat("Entity variable: firm\n")
## Entity variable: firm
cat("Time variable: year\n")
## Time variable: year
cat("Number of entities:", info$nT$n, "\n")
## Number of entities: 10
cat("Number of time periods:", info$nT$T, "\n")
## Number of time periods: 20
The dataset is a balanced panel, meaning each firm has data for every year in the sample. The entity variable is firm and the time variable is year. There are 10 firms observed over 20 time periods, giving a complete panel structure.
# pooled OLS regression
ols_model <- lm(inv ~ value + capital, data = Grunfeld)
# estimating equation
cat("Estimating equation:\n")
## Estimating equation:
cat("inv_it = beta0 + beta1*value_it + beta2*capital_it + u_it\n\n")
## inv_it = beta0 + beta1*value_it + beta2*capital_it + u_it
# regression results
summary(ols_model)
##
## Call:
## lm(formula = inv ~ value + capital, data = Grunfeld)
##
## Residuals:
## Min 1Q Median 3Q Max
## -291.68 -30.01 5.30 34.83 369.45
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -42.714369 9.511676 -4.491 1.21e-05 ***
## value 0.115562 0.005836 19.803 < 2e-16 ***
## capital 0.230678 0.025476 9.055 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 94.41 on 197 degrees of freedom
## Multiple R-squared: 0.8124, Adjusted R-squared: 0.8105
## F-statistic: 426.6 on 2 and 197 DF, p-value: < 2.2e-16
The estimated equation is \(inv_{it} = -42.71 + 0.116\,value_{it} + 0.231\,capital_{it} + u_{it}\). Both value and capital have positive coefficients, which makes economic sense because firms with higher market value and more capital tend to invest more. Both coefficients are also highly statistically significant, since their p values are below 0.01. The magnitudes suggest that a one unit increase in value is associated with about a 0.116 increase in investment, while a one unit increase in capital is associated with about a 0.231 increase in investment. There could still be omitted variable bias because pooled OLS does not control for unobserved firm characteristics or time-specific shocks. Adding fixed effects could help reduce this bias by controlling for factors that are constant within firms over time.
# fixed effects models
# 1) entity fixed effects using plm (within estimator)
fe_firm <- plm(inv ~ value + capital, data = pdat, model = "within", effect = "individual")
# 2) same entity fixed effects using LSDV with firm dummies
fe_firm_lsdv <- lm(inv ~ value + capital + factor(firm), data = Grunfeld)
# 3) two-way fixed effects: firm and year fixed effects
fe_twoway <- plm(inv ~ value + capital, data = pdat, model = "within", effect = "twoways")
# estimating equations
cat("Entity fixed effects equation:\n")
## Entity fixed effects equation:
cat("inv_it = beta1*value_it + beta2*capital_it + alpha_i + u_it\n\n")
## inv_it = beta1*value_it + beta2*capital_it + alpha_i + u_it
cat("Two-way fixed effects equation:\n")
## Two-way fixed effects equation:
cat("inv_it = beta1*value_it + beta2*capital_it + alpha_i + gamma_t + u_it\n\n")
## inv_it = beta1*value_it + beta2*capital_it + alpha_i + gamma_t + u_it
cat("Pooled OLS coefficients:\n")
## Pooled OLS coefficients:
print(coef(ols_model))
## (Intercept) value capital
## -42.7143694 0.1155622 0.2306785
cat("\n")
cat("Entity FE coefficients (within):\n")
## Entity FE coefficients (within):
print(coef(fe_firm))
## value capital
## 0.1101238 0.3100653
cat("\n")
cat("Entity FE coefficients (LSDV with firm dummies):\n")
## Entity FE coefficients (LSDV with firm dummies):
print(coef(fe_firm_lsdv)[c("value","capital")])
## value capital
## 0.1101238 0.3100653
cat("\n")
cat("Two-way FE coefficients:\n")
## Two-way FE coefficients:
print(coef(fe_twoway))
## value capital
## 0.1177159 0.3579163
cat("\n")
cat("Entity FE model summary:\n")
## Entity FE model summary:
summary(fe_firm)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = inv ~ value + capital, data = pdat, effect = "individual",
## model = "within")
##
## Balanced Panel: n = 10, T = 20, N = 200
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -184.00857 -17.64316 0.56337 19.19222 250.70974
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## value 0.110124 0.011857 9.2879 < 2.2e-16 ***
## capital 0.310065 0.017355 17.8666 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 2244400
## Residual Sum of Squares: 523480
## R-Squared: 0.76676
## Adj. R-Squared: 0.75311
## F-statistic: 309.014 on 2 and 188 DF, p-value: < 2.22e-16
cat("\n\nTwo-way FE model summary:\n")
##
##
## Two-way FE model summary:
summary(fe_twoway)
## Twoways effects Within Model
##
## Call:
## plm(formula = inv ~ value + capital, data = pdat, effect = "twoways",
## model = "within")
##
## Balanced Panel: n = 10, T = 20, N = 200
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -162.6094 -19.4710 -1.2669 19.1277 211.8420
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## value 0.117716 0.013751 8.5604 6.653e-15 ***
## capital 0.357916 0.022719 15.7540 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 1615600
## Residual Sum of Squares: 452150
## R-Squared: 0.72015
## Adj. R-Squared: 0.67047
## F-statistic: 217.442 on 2 and 169 DF, p-value: < 2.22e-16
The fixed effects estimates do change compared with pooled OLS. In pooled OLS, the coefficients are 0.116 for value and 0.231 for capital, while in the firm fixed effects model they become 0.110 and 0.310. In the two way fixed effects model they become 0.118 and 0.358. This happens because fixed effects control for unobserved factors that may be correlated with the regressors, so the estimates are based on within firm changes over time rather than just overall differences across firms.
In the firm fixed effects specification, the fixed effects control for time invariant characteristics of each firm, such as management style, industry position, or other permanent differences across firms. In the two way fixed effects model, the specification controls for both firm fixed effects and year fixed effects. That means it controls for both time invariant firm characteristics and common time varying shocks that affect all firms in a given year.
The coefficients from the two alternative ways of estimating firm fixed effects are the same. The within estimator and the LSDV model with firm dummies both give 0.110 for value and 0.310 for capital. This shows that they are just different ways of estimating the same firm fixed effects model, so they produce the same slope coefficients apart from possible rounding differences.