IRIS-Solutions-Team / IRIS-Toolbox

[IrisToolbox] for Macroeconomic Modeling
Other
90 stars 41 forks source link

Alternative for resize function #344

Closed beremtz closed 1 year ago

beremtz commented 1 year ago

I am trying to run an old script (from 2015) and it contains the resize function to clip tseries object down to a specified date range. Was this function changed? If so is there another option?

This is the description of the function in the 2013 manual. Syntax X = resize(X,Range) Input arguments ˆ X [ tseries ] - Input tseries object whose date range will be clipped down. ˆ Range [ numeric ] - New date range to which the input tseries object will be resized; the range can be specied as a [startDate,endDate] vector where -Inf and Inf can be used for the dates. Output arguments ˆ X [ tseries ] - Output tseries object with its date range clipped down to Range

beremtz commented 1 year ago

dat = dbload('data_US.csv'); range = qq(1970,1):qq(2018,1);

% Settings for the loop startyr=2000; endyr=2017; % Set estimation sample and scale parameter (noise-to-signal) range1 = qq(1980,1):qq(startyr,4); scales_calib=[3.6 3.7 3.6 3.3 3.3 3.3 3.2 3.7 3.9 3.8 3.3 3.2 3.3 3.4 3.3 3.1 3.1 3.2];

iyr=1; for yy=startyr:endyr

% Set estimation range range1 = qq(1980,1):qq(yy,4); scale = scales_calib(iyr);

% Data constructs and transforms gdp_full = 100log(dat.GDP_US/dat.PGDP_US); dgdp_full = diff(gdp_full); cr_full = 100log(dat.CR_US/dat.CPI_US); dcr_full = diff(cr_full); ppr_full = 100*log(dat.RPP_US/dat.CPI_US); dppr_full =diff(ppr_full);

% Construct mean sequences mean_seq = [];

for j = range; range2 = range(1):j % uses initial observations from the full data sample mean_seq = [mean_seq; mean(resize(dcr_full,range2)) mean(resize(dppr_full,range2))];
end; end

data_US.csv

jaromir-benes commented 1 year ago

Hi - the function you're looking for is clip, see https://iris-solutions-team.github.io/iris-reference/DataManagement/%40Series/clip.html

You can alternatively use a more convenient approach here

x{range} (=curly braces) returns a time series limited to the range (with missing obs excluded) x(range) (=round parentheses) returns a plain numeric array

Either of these can be used in your mean function.

Best Jaromir

On Sun, Oct 16, 2022 at 2:04 PM beremtz @.***> wrote:

dat = dbload('data_US.csv'); range = qq(1970,1):qq(2018,1);

% Settings for the loop startyr=2000; endyr=2017; % Set estimation sample and scale parameter (noise-to-signal) range1 = qq(1980,1):qq(startyr,4); scales_calib=[3.6 3.7 3.6 3.3 3.3 3.3 3.2 3.7 3.9 3.8 3.3 3.2 3.3 3.4 3.3 3.1 3.1 3.2];

iyr=1; for yy=startyr:endyr

% Set estimation range range1 = qq(1980,1):qq(yy,4); scale = scales_calib(iyr);

% Data constructs and transforms gdp_full = 100

log(dat.GDP_US/dat.PGDP_US); dgdp_full = diff(gdp_full); cr_full = 100 log(dat.CR_US/dat.CPI_US); dcr_full = diff(cr_full); ppr_full = 100*log(dat.RPP_US/dat.CPI_US); dppr_full =diff(ppr_full);

% Construct mean sequences mean_seq = [];

for j = range; range2 = range(1):j % uses initial observations from the full data sample mean_seq = [mean_seq; mean(resize(dcr_full,range2)) mean(resize(dppr_full,range2))]; end; end

data_US.csv https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/files/9794385/data_US.csv

— Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/344#issuecomment-1279955914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKQREZCDVZRXMDDZDODWDPVORANCNFSM6AAAAAARGHD5ZE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

beremtz commented 1 year ago

Thank you, elegant solution!