I want to regress my dependent variable on my independent variables in R. First for the level of the variables: lm(y~x+z+u)
. Now since my variables are non-stationary I have to take the first difference of each variable. My question is, is it right to do the following: lm(diff(y)~diff(x)+diff(z)+diff(u))
?
My question arises because I read the question and the corresponding answer from this thread: How do I interpret my regression with first differenced variables? What baffled me was the answer from Charlie. Is taking the difference from each variable the same as subtracting $y_{t-1}$ from each side of the model in levels? I.e. is subtracting $y_{t-1}$ from lm(y~x+z+u)
equal to lm(diff(y)~diff(x)+diff(z)+diff(u))
?
I already posted this question on Stack Overflow, but since it has nothing to do with programming/coding I deleted it an reposted it on this forum.
lm(diff(y)~-1+x[-1]+z[-1]+u[-1]+offset(1*tail(y,-1)))
) is equivalent to running a regression of the form $\Delta y_t=\beta_1 x_t+\beta_2 z_t+\beta_3 \Delta u_t-1 \cdot y_{t−1}+\varepsilon_t$. You may look up functionsdiff
,tail
andoffset
separately in R help files.[-1]
andtail(y,-1)
are used to effectively create non-lagged and lagged variables. $\endgroup$