Skip to content

Commit

Permalink
ramp correction when frequency != 12
Browse files Browse the repository at this point in the history
  • Loading branch information
AQLT committed Mar 2, 2024
1 parent 69ef8fb commit 5e35c32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- possibility to export X-11 some components: `y_cmp`, `y_cmp_f`, `t_cmp`, `t_cmp_f`, `sa_cmp`, `s_cmp`, `s_cmp_f`, and `i_cmp`.

- correction when importing models containing ramp regressors when the frequency is not 12 (monthly).


# RJDemetra 0.2.5

Expand Down
12 changes: 10 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ identical_na <- function(x){
}


ramp <- function(start = 1990, end = 2020,
ramp <- function(start = 1900, end = 2100,
start_ramp, end_ramp, frequency = 12){
start <- format_ts_date(start, frequency)
end <- format_ts_date(end, frequency)
# start_ramp and end_ramp are defined in month and not in the frequency of the model
new_period <- rep(seq.int(from = 1, to = frequency), each = 12 / frequency)
if (length(start_ramp) == 2) {
start_ramp[2] <- new_period[start_ramp[2]]
}
if (length(end_ramp) == 2) {
end_ramp[2] <- new_period[end_ramp[2]]
}
start_ramp <- format_ts_date(start_ramp, frequency)
end_ramp <- format_ts_date(end_ramp, frequency)

Expand All @@ -20,7 +28,7 @@ ramp <- function(start = 1990, end = 2020,
if (missing(start) || missing(end)) {
# if start and end not specified by hand
start <- min(start_ramp - 1, start)
end <- min(end_ramp + 1, end)
end <- max(end_ramp + 1, end)
}

x <- ts(-1, start = start, end = end,
Expand Down

0 comments on commit 5e35c32

Please sign in to comment.