-1

I installed countrycode and called it in Rstudio. Here is my code:

countrycode("ccode", "cown", "iso3c" warn = TRUE nomatch = NA)

I get an error message saying:

Error: unexpected symbol in "countrycode("ccode", "cown", "iso3c", warn=TRUE nomatch"

where ccode is the name of the variable I am trying to convert, cown indicates that ccode is in the numeric form of the correlates of war code, and iso3c is the code I am trying to transform it into.

What am I doing wrong? I think I'm following the example in the countrycode pdf exactly. When I search my dataframe I can't find the iso3c variable that I assume should be created. There is no new response variable with another name either.

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • missing a comma after `TRUE` – hrbrmstr Jul 23 '18 at 10:35
  • Thanks :) that helped but shouldn't this produce an iso3c variable in the dataset? I don't see it. – Patricia Chang Jul 23 '18 at 22:37
  • Also, is it a problem that the observations in my dataset are events (rebel activity) that can occur several times in a single country? That is, its not organized by country, but rather by event. I use the cow code as the sourcevar for my origin, but do I need to be using custom_match? The cran pdf doesn't explain this very much. Would the custom_match=sourcevar? Thanks, I'ma newbie in R – Patricia Chang Jul 23 '18 at 22:52

1 Answers1

0

If ccode is a vector containing strings/characters with CoW codes in it, then you should pass sourcevar = ccode not sourcevar = "ccode".

library(countrycode)
ccode <- c(2, 220, 255, 111)
countrycode(ccode, "cown", "iso3c", warn = TRUE, nomatch = NA)

You can pass an individual string/character to sourcevar though if you want...

countrycode("2", "cown", "iso3c", warn = TRUE, nomatch = NA)
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56