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 48% Check second input argument 49if p<0 50 error('dseries:WrongInputArguments','Second input argument must be non negative! Use lead method instead.') 51end 52 53% Check that p is an integer 54if ~isint(p) 55 error('dseries:WrongInputArguments','Second input argument must be an integer!') 56end 57 58% Return without changing anything if p==0 59if ~p 60 return 61end 62 63% Update data member 64o.data = [NaN(p, vobs(o)); o.data(1:end-p,:)]; 65 66for i=1:vobs(o) 67 if isempty(o.ops) 68 o.ops(i) = {sprintf('lag(%s, %s)', o.name{i}, int2str(p))}; 69 else 70 if isempty(o.ops{i}) 71 o.ops(i) = {sprintf('lag(%s)', int2str(p))}; 72 else 73 o.ops(i) = {sprintf('lag(%s, %s)', o.ops{i}, int2str(p))}; 74 end 75 end 76end 77 78%@test:1 79%$ try 80%$ data = transpose(0:1:50); 81%$ ts = dseries(data,'1950Q1'); 82%$ ts.lag_(); 83%$ t(1) = 1; 84%$ catch 85%$ t(1) = 0; 86%$ end 87%$ 88%$ if t(1) 89%$ DATA = [NaN(1,ts.vobs); transpose(0:1:49)]; 90%$ t(2) = dassert(ts.data,DATA,1e-15); 91%$ end 92%$ 93%$ T = all(t); 94%@eof:1 95 96%@test:2 97%$ try 98%$ data = transpose(0:1:50); 99%$ ts = dseries(data,'1950Q1'); 100%$ ts.lag_(0); 101%$ t(1) = 1; 102%$ catch 103%$ t(1) = 0; 104%$ end 105%$ 106%$ if t(1) 107%$ t(2) = dassert(ts.data,data,1e-15); 108%$ t(3) = isempty(ts.ops{1}); 109%$ end 110%$ 111%$ T = all(t); 112%@eof:2