I 'm trying to perform a pooled regression by using different subsets with the same time interval (5years) but within different years. I'm having troubles with the syntax of my code, i seem to do something wrong with the definition of the subset.
> head(Grunfeld)
firm year inv value capital
1 1 1935 317.6 3078.5 2.8
2 1 1936 391.8 4661.7 52.6
3 1 1937 410.6 5387.1 156.9
4 1 1938 257.7 2792.2 209.2
5 1 1939 330.8 4313.2 203.4
6 1 1940 461.2 4643.9 207.2
library(plm)
data("Grunfeld", package="plm")
#regression
myregression <- list()
Grunfeld_sub <- data.frame()
count <- 1
#loop
for(t in 1940:1950){
Grunfeld_sub[t] <- subset(Grunfeld, year<=t & year>=t-5)
myregression[[count]] <- lm(inv~value + capital, Grunfeld_sub(t))
count<- count+1
}
what am i doing wrong with the syntax? how do I define the subsample correctly?
another problem is that if i want to use the plm package and convert my data.frame (Grunfeld) with the plm.data function, i wont be able to use subset anymore as i somewhat can not use it with factorvariables (the time variable would become a factor variable) is there a possible solution regarding this matter? Thank you for your help.
Grunfeld_sub(t)should rather beGrunfeld_sub[t]