To estimate fixed effects in R, we can use the lm()
function with the factor()
function to create dummy variables for each of the fixed effects. Here's an example:
main.r420 chars12 lines
In this example, we estimate a fixed effects model for the Grunfeld
data set, which is a panel data set with observations for 10 firms over a 20-year period. The variable inv
represents investment, value
represents market value of the firm, and capital
represents physical capital. We create dummy variables for each of the 10 firms using the factor()
function and include them as fixed effects in the model. We can also use the plm()
function from the plm
package to estimate fixed effects, which requires specifying the panel index and the model type.
gistlibby LogSnag