Git Product home page Git Product logo

Comments (4)

murao164jp avatar murao164jp commented on September 25, 2024 1

Thank you for your suggestions. They are very helpful. I will use these techniques for my R scripts.

Based on your suggestions, I made the following examples.

First method to extend the data of dummy variables in "bitmets"

It is based on the use of TSJOIN() and TIMESERIES().

bimodel$modelData <- within(bimodel$modelData,{
dum_Q1_part2 <- TIMESERIES(0, 1, 0, 0, 0, 1, 0, 0, 0,
START = c(2022, 4), FREQ = 'Q')
dum_Q1 <- TSJOIN(dum_Q1, dum_Q1_part2, ALLOWGAP = FALSE)

dum_Q2_part2 <- TIMESERIES(0, 0, 1, 0, 0, 0, 1, 0, 0,
START = c(2022, 4), FREQ = 'Q')
dum_Q2 <- TSJOIN(dum_Q2, dum_Q2_part2, ALLOWGAP = FALSE)

dum_Q3_part2 <- TIMESERIES(0, 0, 0, 1, 0, 0, 0, 1, 0,
START = c(2022, 4), FREQ = 'Q')
dum_Q3 <- TSJOIN(dum_Q3, dum_Q3_part2, ALLOWGAP = FALSE)
})

end of the first method

Second method

p2_start <- c(2022, 4)
p2_end <- c(2024, 4)
p2_length <- NUMPERIOD(p2_start, p2_end, 4) + 1
zeroTS_p2 <- TSERIES(rep(0, p2_length), START = p2_start, FREQ = 'Q')
dum_Q1_p2 <- zeroTS_p2
dum_Q2_p2 <- zeroTS_p2
dum_Q3_p2 <- zeroTS_p2

quarterToBeOne <- 1
dum_Q1_p2[which(GETDATE(dum_Q1_p2, format = '%q') == quarterToBeOne)] <- 1

quarterToBeOne <- 2
dum_Q2_p2[which(GETDATE(dum_Q2_p2, format = '%q') == quarterToBeOne)] <- 1

quarterToBeOne <- 3
dum_Q3_p2[which(GETDATE(dum_Q3_p2, format = '%q') == quarterToBeOne)] <- 1

TABIT(dum_Q1_p2, dum_Q2_p2, dum_Q3_p2,
TSRANGE = c(2022, 4, 2024, 4))

bimodel$modelData <- within(bimodel$modelData,{
dum_Q1 <- TSJOIN(dum_Q1, dum_Q1_p2, ALLOWGAP = FALSE)
dum_Q2 <- TSJOIN(dum_Q2, dum_Q2_p2, ALLOWGAP = FALSE)
dum_Q3 <- TSJOIN(dum_Q3, dum_Q3_p2, ALLOWGAP = FALSE)
})

end of the second method

Check the content of new data set

TABIT(bimodel$modelData$G,
bimodel$modelData$MrP,
bimodel$modelData$TAX,
bimodel$modelData$dum_Q1,
bimodel$modelData$dum_Q2,
bimodel$modelData$dum_Q3,
TSRANGE = c(2021, 1, 2024, 4))

end of the examples

Note (G, MrP, TAX) are exogenous qualitative variables.

The data of (G, MrP, TAX) is extended with the usual method, using TSEXTEND() function.

from bimets.

andrea-luciani avatar andrea-luciani commented on September 25, 2024

dear @murao164jp

TSEXTEND doen not change current values in a time series. This function extends a time series outside its definition time range.

Lines 423:428 in forecast_out_sample_ISLM.TXT: In data.frame data_obs_V2, and in the related list data_preBi_V2, exogenous variables are already defined up tp 2024-4, and have missing values.

Therefore, when you apply TSEXTEND in lines 446, you are actually chaning nothing: time series are already defined up to 2024-4, and exogenous variables will still have missing values in simulation TSRANGE. Thus, SIMULATE issues an error.

If you want to replace missing values with arbitrary values in your time series, you have to manually remove missing values, or you may want to take a look at the TSTRIM function: after the missing removal, then you can apply the TSEXTEND.

from bimets.

murao164jp avatar murao164jp commented on September 25, 2024

Thank you for your comment.

I tried several ideas after posting my question, and I found a way to solve it.

It uses the combination of TSJOIN()function, TSEXTEND()function, TIMESERIES()function. My example is shown in the below.


A way to extend the data of dummy variables in "bimets"

The use of TSJOIN(), TSEXTEND(), and TIMESERIES() for it.

bimodel$modelData <- within(bimodel$modelData,{
dum_Q1_part2 = TSEXTEND(TIMESERIES(0, 1, 0, 0, 0, 1, 0, 0, 0, START = c(2022, 4), FREQ='Q'),
BACKTO = c(2022, 4), UPTO = c(2024, 4))
dum_Q1 <- TSJOIN(dum_Q1, dum_Q1_part2, ALLOWGAP = FALSE)

dum_Q2_part2 = TSEXTEND(TIMESERIES(0, 0, 1, 0, 0, 0, 1, 0, 0, START = c(2022, 4), FREQ='Q'),
BACKTO = c(2022, 4), UPTO = c(2024, 4))
dum_Q2 <- TSJOIN(dum_Q2, dum_Q2_part2, ALLOWGAP = FALSE)

dum_Q3_part2 = TSEXTEND(TIMESERIES(0, 0, 0, 1, 0, 0, 0, 1, 0, START = c(2022, 4), FREQ='Q'),
BACKTO = c(2022, 4), UPTO = c(2024, 4))
dum_Q3 <- TSJOIN(dum_Q3, dum_Q3_part2, ALLOWGAP = FALSE)

}) # end of within()

end of dealing with "bimodel$modelData"


Currently I have two suggestions.

(1) Please write your version of the above idea in the manual of bimets.

(2) It is nice to have this kind of option in TSEXTEND()function.

Thank you again.

Hiroshi Murao

from bimets.

andrea-luciani avatar andrea-luciani commented on September 25, 2024

hi @murao164jp

you may want to remove the TSEXTEND in your code, it does not change the target time series. In the following code, similar to yours, ts1 and ts1ext are the same time series:

> ts1=(TIMESERIES(0, 1, 0, 0, 0, 1, 0, 0, 0, START = c(2022, 4), FREQ='Q'))
> ts1ext=TSEXTEND(ts1,BACKTO = c(2022, 4), UPTO = c(2024, 4))
> TABIT(ts1,ts1ext)

      Date, Prd., ts1            , ts1ext

   2022 Q4, 4   ,  0             ,  0
   2023 Q1, 1   ,  1             ,  1
   2023 Q2, 2   ,  0             ,  0
   2023 Q3, 3   ,  0             ,  0
   2023 Q4, 4   ,  0             ,  0
   2024 Q1, 1   ,  1             ,  1
   2024 Q2, 2   ,  0             ,  0
   2024 Q3, 3   ,  0             ,  0
   2024 Q4, 4   ,  0             ,  0

If you want to create a time series that is one in an arbitrary quarter, you may want to take a look at the following:

> start=c(2022,4)
> end=c(2024,4)
> length=NUMPERIOD(start,end,4)+1
> tsBase=TSERIES(rep(0,length),START=start,FREQ='Q')

#set this variable to selected quarter, 1..4
> quarterToBeOne=3

> dummyQuarter3=tsBase
> dummyQuarter3[which(GETDATE(dummyQuarter3,format='%q')==quarterToBeOne)]=1
> TABIT(dummyQuarter3)

      Date, Prd., dummyQuarter3

   2022 Q4, 4   ,  0
   2023 Q1, 1   ,  0
   2023 Q2, 2   ,  0
   2023 Q3, 3   ,  1
   2023 Q4, 4   ,  0
   2024 Q1, 1   ,  0
   2024 Q2, 2   ,  0
   2024 Q3, 3   ,  1
   2024 Q4, 4   ,  0

Hope this will help.

from bimets.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.