0

I'm following some example.(https://www.eventstudytools.com/blog/dieselgate-example-data-preparation) Instead of pulling data from Yahoo, This is my firmData.

               code       date value
     KS233740Equity 05.12.2016  7225
     KS233740Equity 07.12.2016  7235
     KS233740Equity 06.12.2016  7355
     KS233740Equity 08.12.2016  7395
     KS233740Equity 02.12.2016  7430
     KS233160Equity 05.12.2016  7540
     KS233160Equity 07.12.2016  7605
     KS233740Equity 09.12.2016  7650
     KS233740Equity 01.12.2016  7665
     KS233740Equity 28.11.2016  7680
     KS233160Equity 06.12.2016  7705
     KS233740Equity 30.11.2016  7720
     KS233740Equity 24.11.2016  7750
     KS233740Equity 29.11.2016  7760
     KS233160Equity 08.12.2016  7770
     KS233160Equity 02.12.2016  7800
     KS233740Equity 25.11.2016  7830
     KS233740Equity 12.12.2016  7850
     KS233740Equity 25.01.2017  7855
     KS233740Equity 24.01.2017  7885

When I importing this,is.numeric(firmData$value)=true. But when I want to transfer it to csv file in specific manner, this seems to become non-numeric.

library(dplyr)
firmData %>% 
  dplyr::select(code, date, value) %>%
  dplyr::mutate(date = format(date, "%d.%m.%Y"))        # this is for this specific code
  readr::write_delim(path      = "02_firmDataPrice.csv", 
                     delim     = ";", col_names = F)


library(EventStudy)
key <- "573e58c665fcc08cc6e5a660beaad0cb"
est <- EventStudyAPI$new()
est$authentication(apiKey = key)
esaParams <- EventStudy::ARCApplicationInput$new()
esaParams$setResultFileType("csv")
esaParams$setBenchmarkModel("garch")

dataFiles <- c("request_file" = "01_requestFile.csv",
               "firm_data"    = "02_firmDataPrice.csv",
               "market_data"  = "03_marketDataPrice.csv")

EventStudy::checkFiles(dataFiles)

Then,

Error: Column firm is not of type Integer! inherits from numeric not character.

What could I do to use package "EventStudy" properly??

(market_data looks very similar to "firmData" and data "request" for making "01_requestFile.csv" is looking like below. There seems to be no problem with it as of yet.)

"1" "KS233740Equity" "indexData" "04.04.2018" "leverage" "-10" "10" "-11" "250"
"2" "KS233160Equity" "indexData" "04.04.2018" "leverage" "-10" "10" "-11" "250"
"3" "KS278240Equity" "indexData" "04.04.2018" "Other"    "-10" "10" "-11" "250"
Hannah Lee
  • 383
  • 2
  • 7
  • 19
  • Can you post the output of `dput(head(request, 10))` and of `dput(head(market_data, 10))` in the question, please? Also, see [How to convert a factor to integer\numeric without loss of information?](https://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-integer-numeric-without-loss-of-information). – Rui Barradas Apr 24 '18 at 11:16
  • @Rui Barradas, `dput(head(request, 5)) = structure(c("1", "2", "3", "KS233740Equity", "KS233160Equity", "KS278240Equity", "indexData", "indexData", "indexData", "04.04.2018", "04.04.2018", "04.04.2018", "leverage", "leverage", "Other", "-10", "-10", "-10", "10", "10", "10", "-11", "-11", "-11", "250", "250", "250"), .Dim = c(3L, 9L), .Dimnames = list(NULL, c("", "", "", "", "group", "", "", "", "")))` – Hannah Lee Apr 24 '18 at 12:09
  • `dput(head(market_data,5)) = structure(list(value = c(889.2, 882.36, 895.21, 903.64, 903.01 ), code = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "KOSDAQ150", class = "factor"), date = structure(c(1357084800, 1357171200, 1357257600, 1357516800, 1357603200), class = c("POSIXct", "POSIXt"), tzone = "UTC")), .Names = c("value", "code", "date"), row.names = c("2013-01-02", "2013-01-03", "2013-01-04", "2013-01-07", "2013-01-08"), class = "data.frame")` – Hannah Lee Apr 24 '18 at 12:10
  • [link] https://github.com/cran/EventStudy/blob/master/R/dataHandling.R – Hannah Lee Apr 24 '18 at 12:39

2 Answers2

0

I ended up using Eviews add-ins they provide, https://github.com/EventStudyTools/api-wrapper.r/

Hannah Lee
  • 383
  • 2
  • 7
  • 19
0

If all you need to do is to transform the numbers from class character to class numeric, try the following code.

First of all, you have characters because your dataset request is an object of class matrix and in R matrices can hold only one type of data. So coerce the matrix into a data.frame. Then lapply the function as.numeric to the appropriate columns.

request <- as.data.frame(request, stringsAsFactors = FALSE)
request[6:9] <- lapply(request[6:9], as.numeric)
request
#  V1             V2        V3         V4    group  V6 V7  V8  V9
#1  1 KS233740Equity indexData 04.04.2018 leverage -10 10 -11 250
#2  2 KS233160Equity indexData 04.04.2018 leverage -10 10 -11 250
#3  3 KS278240Equity indexData 04.04.2018    Other -10 10 -11 250

You can then inspect the data.frame with str:

str(request)
#'data.frame':   3 obs. of  9 variables:
# $ V1   : chr  "1" "2" "3"
# $ V2   : chr  "KS233740Equity" "KS233160Equity" "KS278240Equity"
# $ V3   : chr  "indexData" "indexData" "indexData"
# $ V4   : chr  "04.04.2018" "04.04.2018" "04.04.2018"
# $ group: chr  "leverage" "leverage" "Other"
# $ V6   : num  -10 -10 -10
# $ V7   : num  10 10 10
# $ V8   : num  -11 -11 -11
# $ V9   : num  250 250 250
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66