I am trying to do several pooling OLS regressions on a "changing" panel data set. The Gasoline data in the plm package will suit well as an example

library(plm)
data("Gasoline", package = "plm")
head(Gasoline)

  country year lgaspcar  lincomep  lrpmg      lcarpcap
1 AUSTRIA 1960 4.173244 -6.474277 -0.3345476 -9.766840
2 AUSTRIA 1961 4.100989 -6.426006 -0.3513276 -9.608622
3 AUSTRIA 1962 4.073177 -6.407308 -0.3795177 -9.457257
4 AUSTRIA 1963 4.059509 -6.370679 -0.4142514 -9.343155
5 AUSTRIA 1964 4.037689 -6.322247 -0.4453354 -9.237739
6 AUSTRIA 1965 4.033983 -6.294668 -0.4970607 -9.123903

The data spans 1960 to 1978, and I would like to perform pooling OLS on the panel data for the previous years for the years 1961 to 1978. That is, the first regression is only a cross section of the 1960 data, the second regression is a panel regression of the year 1960 and 1961, the third regression is the panel regression on the data for the years 1960, 1961, and 1962, etc.

I know how to do a single pooling OLS regression (please disregard whether the specific regression makes sense - It's only an example):

plm(lgaspcar ~ lcarpcap + lincomep, data = Gasoline, model='pooling')

I am looking for a smart way to do this panel regression on a changing data set. Is there some way to limit the years of the data set in the call to plm?

有帮助吗?

解决方案

Well, you can put it in a loop, but I can't see a way of optimizing that as each regression has to be done anew.

plm.results = lapply(1961:1978,
                     function(y) plm(lgaspcar ~ lcarpcap + lincomep,
                                 data = subset(Gasoline, year <= y),
                                 model='pooling'))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top