Skip to contents

Retrieves PolarCAP data for defined countries and years. Returns data in wide format. For tidy format, use melt.PolarCAP().

Usage

get.PolarCAP(
  countries = NA,
  years = NA,
  type = c("ideology", "affect"),
  value.only = FALSE,
  include.se = FALSE
)

Arguments

countries

a character vector of countries to be retrieved. See Details.

years

a numeric vector of years to be retrieved.

type

a character vector indicating which polarization estimates should be returned. Must be "ideology", "affect", or both.

value.only

a logical indicating whether get.PolarCAP() should return a data frame of results (FALSE, the default) or a single estimate as a scalar (TRUE).

include.se

a logical indicating whether standard errors should be returned. Defaults to FALSE.

Value

If value.only = FALSE, get.PolarCAP() returns a data frame with columns corresponding to country names, country ISO3 codes, years, polarization estimates for the polarization type(s) given in type, and associated standard errors (if include.se = TRUE). If value.only = TRUE, get.PolarCAP() returns a scalar polarization estimate for the polarization type given in type.

Details

Ideally, country names passed to countries would be ISO 3166-1 alpha-3 country codes (case-insensitive). However, get.PolarCAP() will accept country names in almost any language or format and attempt to convert them to ISO3 codes by calling to.ISO3(). get.PolarCAP() will alert the user to any country names still unrecognized after this conversion and return results only for those which are recognized.

Examples

get.PolarCAP("USA", c(2018, 2019), "ideology", include.se = TRUE)
#> # A tibble: 2 × 6
#>   country       country_code  year ideology ideology_se notes
#>   <chr>         <chr>        <dbl>    <dbl>       <dbl> <chr>
#> 1 United States USA           2018    0.682     0.00970 NA   
#> 2 United States USA           2019    0.761     0.0102  NA   
get.PolarCAP("USA", c(2018, 2019), c("ideology", "affect"), include.se = TRUE)
#> # A tibble: 2 × 8
#>   country       country_code  year ideology affect ideology_se affect_se notes
#>   <chr>         <chr>        <dbl>    <dbl>  <dbl>       <dbl>     <dbl> <chr>
#> 1 United States USA           2018    0.682  0.773     0.00970    0.0114 NA   
#> 2 United States USA           2019    0.761  0.728     0.0102     0.0118 NA   

countries <- rep(c("MEX", "USA"), each = 2)
years <- rep(c(2018, 2019), 2)
data <- as.data.frame(cbind(countries, years))

data$ideology1 <- apply(data, 1, function(x) get.PolarCAP(x[1], x[2], type = "ideology",
value.only = TRUE))
data
#>   countries years ideology1
#> 1       MEX  2018 0.6114545
#> 2       MEX  2019 0.6389439
#> 3       USA  2018 0.6819618
#> 4       USA  2019 0.7611854