0
$\begingroup$

I want to find an effect of X on Y. However, my Y and X are both have trends and seasonality. The first picture is my X and the second Y. The logic and academic results show that X should positively influence Y. However, when I will do regression I will have a negative coefficient (mainly due to opposing trends). Additionally< i have several different regressors which will help in the model. What can I do to find this effect. I guess the detrending should be done, but by which means? I heard that rolling window regression can help.

enter image description here

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Depending on the nature/origin of your data, a simple first way of detrending would be to use a log-linear model for your time-series. For instance, for $Y$ the model would be

$log Y_t = y_t = \alpha + gt + \epsilon_t$.

where $\alpha+gt$ is your trend component and $\epsilon_t$ the cyclical component. (Note that $t$ indexes time). Below is an example with data from the FED.

If you would take log-differences ($\Delta y_t = y_t - y_{t-1}$) you get something equivalent to a growth rate with a constant trend growth $g$ and the change in the cyclical component ($\Delta \epsilon_t$).

Important caveat with this approach is that there might appear to be a mean-reverting cyclical component, which is not there. Instead you could also use a Hodrick-Prescott filter. Depending on the software you use there is also decompose in R which can help remove the trend and seasonal component.

I am sure others can add more useful suggestions as well.

Example GDP data US.

library(Quandl)
gdp <- Quandl("FRED/GDPC1",order="asc")          #data
gdp <- ts(gdp$Value,start=c(1947,1),frequency=4) #time-series: quarterly
gdp<-log(gdp)                                    #log-transform
gdp.dt<-ts(residuals(lm(gdp~index(gdp))), start=c(1947,1),frequency=4) #detrend
plot(gdp.dt)
$\endgroup$
2
  • $\begingroup$ Thank you for your help. This approach helps to detrend time series data in Y. Should I also use natural logarithm for my Xs, which have trend? Additionally, interpretation of the coeffcients will be changed using logarithms. I want to get coefficents what say in absolute terms that if X changes by 1 unit, Y changes by .. units, because some time my Y(not aggregated number as in the plot) is null. So it makes confusing in terms of interpretation using logarithms. I know that trend variable can be used as X2, but are there any other solutions to my problem_ $\endgroup$
    – Gera Kuiv
    May 29, 2020 at 15:29
  • $\begingroup$ Yes if there is a trend it is best to remove it, otherwise you end up with spurious regression (e.g.). For the coefficients you can take the exponential function to transform them back I believe. But I am not 100% certain. $\endgroup$ May 29, 2020 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.