0
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ hey mike_s welcome! If I understand correctly you're trying to do algebraic manipulations on the structural form of y[t]; unless there are other considerations, using something like y[t_]:=y[t]=... (ie memoization) is probably not necessary; one way to evaluate something like eg y[t]-m*y[t-d] is to use ReplaceAll with Rule; $\endgroup$ – user42582 Oct 25 '18 at 13:15
  • $\begingroup$ Thank you for the response! Can you give an example of how I would use ReplaceAll with Rule and then collect terms? $\endgroup$ – mike_s Oct 25 '18 at 17:09
  • $\begingroup$ in order to calc y[t] - m y[t - d] define yrl[t_] := b[0] + b[1] x[t] + b[2] x[t - 1] + b[3] y[t - 1] + η[t] (instead of using y[t_]:=...) and then evaluate y[t] - m y[t - d] /. y[t_] :> yrl[t]; you should be able to collect terms in the later expression $\endgroup$ – user42582 Oct 25 '18 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.