# Helper functions to create and append model
# Create model text file
model.create <- function(modelname,directory = getwd()){
mymod <- paste0(directory,"/",modelname,".txt")
sink(mymod)
sink()
}
# append model
model.append <- function(modelname, equation ,directory){
directory <- getwd()
mymod <- paste0(directory,"/",modelname,".txt")
write(equation, file = mymod, append = TRUE)
}
# simualte model
model.sim <- function(modelname,dat = dat , smpl = NA ,directory){
directory <- getwd()
mymod <- paste0(directory,"/",modelname,".txt")
if(!is.na(smpl)){
smpl <- paste(smpl, xts::last(dat$Date),"quarter")
}else{
smpl <- paste(dat$Date[1],xts::last(dat$Date),"quarter")
}
write(c("#3. Timeline",paste0("timeline ",smpl)), file = mymod, append = TRUE)
mymod <- tst.model(mymod, dataFile = dat, smpl = smpl)
mod <- simulate.tst(mymod)
fcst_start <- substr(smpl, start = 1, stop = 10)
fcst_end <- substr(smpl, start = 12, stop = 21)
fcast <- data.frame(mod$baseline[,mymod$endogenous[,1]],
Date = seq(dat$Date[1], as.Date(fcst_end), by = "quarter"))
mod <- mymod
mod <- list(mod = mymod,
fcast = fcast)
return(mod)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.