1function o = lag(o, p) % --*-- Unitary tests --*--
2
3% Returns a lagged time series
4%
5% INPUTS
6% - o [dseries]
7% - p [integer] Number of lags
8%
9% OUTPUTS
10% - o [dseries]
11%
12% EXAMPLE
13% Define a dseries object as follows:
14%
15% >> o = dseries(transpose(1:5))
16%
17% then o.lag(1) returns
18%
19%       | lag(Variable_1,1)
20%    1Y | NaN
21%    2Y | 1
22%    3Y | 2
23%    4Y | 3
24%    5Y | 4
25
26% Copyright (C) 2013-2017 Dynare Team
27%
28% This file is part of Dynare.
29%
30% Dynare is free software: you can redistribute it and/or modify
31% it under the terms of the GNU General Public License as published by
32% the Free Software Foundation, either version 3 of the License, or
33% (at your option) any later version.
34%
35% Dynare is distributed in the hope that it will be useful,
36% but WITHOUT ANY WARRANTY; without even the implied warranty of
37% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38% GNU General Public License for more details.
39%
40% You should have received a copy of the GNU General Public License
41% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
42
43% Set default number of lags
44if nargin<2
45    p = 1;
46end
47
48o = copy(o);
49o.lag_(p);
50
51%@test:1
52%$ try
53%$     data = transpose(0:1:50);
54%$     ts = dseries(data,'1950Q1');
55%$     a = ts.lag;
56%$     b = ts.lag.lag;
57%$     c = lag(ts,2);
58%$     t(1) = true;
59%$ catch
60%$     t(1) = false;
61%$ end
62%$
63%$ if t(1)
64%$     DATA = [NaN(1,ts.vobs); transpose(0:1:49)];
65%$     t(2) = dassert(a.data,DATA,1e-15);
66%$     DATA = [NaN(2,ts.vobs); transpose(0:1:48)];
67%$     t(3) = dassert(b.data,DATA,1e-15);
68%$     t(4) = dassert(b.data,c.data,1e-15);
69%$ end
70%$
71%$ T = all(t);
72%@eof:1