I am running a regression model with some heteroskedasticity and serial correlation and I am trying to solve both without changing my model specification.
First, I have generated an OLS model and realized both problems, heteroskedasticity and serial correlation. So, I tried to run a feasible generalized least square (FGLS) model with plm's pggls
command to solve both problems at the same time, but this command seems to only solve heteroskedasticity and not serial correlation.
My code is as follows:
base<-pdata.frame(base, index = c("ID","time"), drop = FALSE)
Reg<-pggls(sells~ prices + income + stock+
period1 + period2+ period3, model = c("pooling"),
data=base)
This command seems to correct heteroskedasticity, but it certainly does not correct for serial correlation as I created a simple proof. Below I generated a regression between the residuals and the lagged residuals of the regression model:
res = Reg$res
n = length(res)
mod = lm(res[-n] ~ res[-1])
summary(mod)
The res[-1]
coefficient is mod is significative. So it has not solved the serial correlation.
Does somebody know how to add some option to the pggls
command to solve this?, or does somebody know a better command for solving both problems? It does not necessarily need to be a panel data command as I only have 1 individual.
As long as you said you don't need a panel structure you could correct the standard errors directly, which is the more used appraoch in econometrics literature. In fact, GLS estimation is a bit old fashioned today...
You could do:
library(sandwich)
library(lmtest)
reg <-lm(sells ~ prices + income + stock + period1 + period2+ period3, data = base)
coeftest(reg, vcov = vcovHAC(reg))
Just for completness, if you'd like to produce a clustered robust estimation like Stata does, you cloud try Tarzan's cl
function from here.