I have a panel data situation and I'm interested in taking lags and differences and using Mathematica to simplify the algebra of the result. Currently I'm working with a model like this:
y[t_] := y[t] = b[0] + b[1] x[t] + b[2] x[t - 1] + \[Eta][t]
which serves my needs if I want to take a d difference (y[t]-y[t-d]) or a multiple m of a d difference (y[t]-m*y[t-d]).
However, if I change the model slightly where y[t] now includes a lag of itself,
y[t_] := y[t] = b[0] + b[1] x[t] + b[2] x[t - 1] + b[3] y[t-1] + \[Eta][t]
then this no longer works. It tries to recursively plug in all the y lags and I get the recursion limit error. I don't want it to recursively substitute at all. I would like the output it gives me of y[t]-y[t-1] to contain y[t-1] and y[t-1-d].
I'm planning on taking multiple differences, so whatever the solution I would still need to do things like ExpandAll and Collect.
I'm quite new to Mathematica, so I apologize in advance for obvious mistakes. If there are any comments on any part of my code/approach, please share them!
y[t]; unless there are other considerations, using something likey[t_]:=y[t]=...(ie memoization) is probably not necessary; one way to evaluate something like egy[t]-m*y[t-d]is to use ReplaceAll with Rule; – user42582 Oct 25 '18 at 13:15y[t] - m y[t - d]defineyrl[t_] := b[0] + b[1] x[t] + b[2] x[t - 1] + b[3] y[t - 1] + η[t](instead of usingy[t_]:=...) and then evaluatey[t] - m y[t - d] /. y[t_] :> yrl[t]; you should be able to collect terms in the later expression – user42582 Oct 25 '18 at 18:33