Я пытаюсь связать несколько переменных, которые я создал ранее.Тем не менее, даты начала и окончания временного ряда не равны среди переменных.Я пытаюсь сделать это следующим образом:
data.start <- c(1960,1)
data.end <- c(2018,2)
data.out <- window(cbind(gdp.log.ger, interest.ger, inflation, inflation.exp.ger),start = data.start,
end = data.end)
write.table(data.out,file = 'InputData/rstar.data.ge.csv', sep = ',',
col.names = c("gdp.log","inflation","inflation.expectations", "interest"),
quote = FALSE, na = '.', row.names = FALSE)
Полученная ошибка:
Error in window.default(cbind(gdp.log.ger, interest.ger, inflation, inflation.exp.ger), :
'start' cannot be after 'end'
In addition: Warning messages:
1: In cbind(gdp.log.ger, interest.ger, inflation, inflation.exp.ger) :
number of rows of result is not a multiple of vector length (arg 1)
2: In window.default(cbind(gdp.log.ger, interest.ger, inflation, inflation.exp.ger), :
'end' value not changed
Возможно, это связано с тем, что даты начала и окончания не совпадаютсреди разных временных рядов?Обратите внимание, что для date.start
и date.end
установлены самые ранние и самые последние наблюдения.
PS.Чтобы воспроизвести проблему:
#------------------------------------------------------------------------------#
# File: prepare.rstar.data.ger.R
#
# Description: This file prepares the data for Germany to use in the
# HLW methodology.
#------------------------------------------------------------------------------#
setwd("/Users/seanbagcik/Dropbox/Master Thesis (2017 - 2018)/R-Code") #set working directory
rm(list = ls()) # clear workspace
if (!require("tis")) {install.packages("tis"); library('tis')} # Load time series library
if (!require("seasonal")) {install.packages("seasonal"); library('seasonal')}
Sys.setenv(X13_PATH = "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/x13binary/bin")
# library('forecast') # for seasonal adjustment
# install.packages("forecast");
#------------------------------------------------------------------------------#
# Import raw data: GDP
#------------------------------------------------------------------------------#
gdp.start <- c(1991,1) # type "double"
gdp.end <- c(2017,4)
gdp.raw <- "rawData/germany_gdp.csv"
gdp.table <- read.table(gdp.raw, skip = 1, header = F, sep = ',', stringsAsFactors = F)
gdp.ger <- ts(gdp.table[,2], start = gdp.start, frequency = 4) # time-series representation
#------------------------------------------------------------------------------#
# Import raw data: inflation
#------------------------------------------------------------------------------#
inflation.start <- c(1960,1)
inflation.end <- c(2018,1)
inflation.raw <- "rawData/germany_inflation.csv"
inflation.table <- read.table(inflation.raw, skip = 1, header = F, sep = ',', stringsAsFactors = F)
inflation.ger <- ts(inflation.table[,2], start = inflation.start, frequency = 4)
inflation.seasadj.ger <- final(seas(as.ts(naWindow(inflation.ger),freq=4))) # seasonal adjustment
inflation.seasadj.ger <- as.tis(cpi,start=inflation.start,tif='quarterly')
# Measure inflation expectations: 4-quarter moving average of past inflation:
inflation.exp.ger <- (inflation.seasadj + Lag(inflation.seasadj, k=1) + Lag(inflation.seasadj, k=2) +
Lag(inflation.seasadj, k=3))/4
#------------------------------------------------------------------------------#
# inflation.fit <- auto.arima(inflation, ic = 'aic') # fit ARIMA model
# plot(forecast(inflation.fit,h=20)) # forecasting
# inflation.seasadj <- seasadj(decompose(inflation.fit, 'multiplicative'))
# inflation.ge <- 400*log(cpi/Lag(cpi, k=1)) # create annual inflation series
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Import raw data: short-term nominal interest rate
#------------------------------------------------------------------------------#
interest.start <- c(1960,2)
interest.end <- c(2018,2)
interest.raw <- 'rawData/germany_interest.csv'
interest.table <- read.table(interest.raw, skip = 1, header = F, sep = ',', stringsAsFactors = F)
interest.m <- ts(interest.table[,2], start = interest.start, frequency = 12) # monthly time-series
interest <- convert(interest.m, tif ="quarterly", observed ="averaged") # monthly to quaterly frequency
interest <- final(seas(as.ts(naWindow(interest),freq=4))) # seasonal adjustment
interest <- as.tis(interest,start=interest.start,tif='quarterly')
interest.ger <- 100*((1+interest/36000)^365 -1) # 365-day annualized basis
#------------------------------------------------------------------------------#
# Prepare Data
#------------------------------------------------------------------------------#
# Take log of real GDP
gdp.log.ger <- log(gdp.ger)
#------------------------------------------------------------------------------#
# Output Data
#------------------------------------------------------------------------------#
data.start <- c(1960,1)
data.end <- c(2018,2)
data.out <- window(cbind(gdp.log.ger, inflation.seasadj.ger, inflation.exp.ger, interest.ger),
start = data.start, end = data.end)
write.table(data.out,file = 'InputData/rstar.data.ge.csv', sep = ',',
col.names = c("gdp.log","inflation","inflation.expectations", "interest"),
quote = FALSE, na = '.', row.names = FALSE)
С наборами данных: R-Data