Package 'cesR'

Title: Access the Canadian Election Study Datasets
Description: Makes accessing and loading the Canadian Election Study (<http://www.ces-eec.ca/>, <https://ces-eec.arts.ubc.ca/>, <https://search1.odesi.ca/#/>) surveys into the R workspace more efficient by downloading a requested survey and loading it as a data object. This removes the need to locate, download, load, and change working directories when working with the Canadian Election Study surveys.
Authors: Paul A. Hodgetts [aut, cre], Rohan Alexander [aut]
Maintainer: Paul A. Hodgetts <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-20 04:05:35 UTC
Source: https://github.com/hodgettsp/cesr

Help Index


Create a dataframe object for a CES survey.

Description

get_ces() creates a dataframe object for a requested Canadian Election Study survey using an associated survey code to call and download the survey dataset. On creation of the data object, prints out the associated citation for use with the requested dataset and a link to the original location of the data file.

Usage

get_ces(srvy, pos = 1)

Arguments

srvy

A CES survey code call. See Survey Code Calls below. srvy value must be a character string.

pos

Environment assignment. Defaults to 1, which is an assignment to the global environment.

Details

Datasets

Datasets are loaded using .dta, .sav, or .tab file types. See File Types below for a list of included CES datasets and their file type. To quickly convert a dataset's values to factor type use labelled::to_factor() on the dataset.

Survey Code Calls

  • ces2019_web calls 2019 CES online survey dataset.

  • ces2019_phone calls 2019 CES phone survey dataset.

  • ces2015_web calls 2015 CES online survey dataset.

  • ces2015_phone calls 2015 CES phone survey dataset.

  • ces2015_combo calls 2015 CES combined (online/phone) dataset.

  • ces2011 calls 2011 CES survey dataset.

  • ces2008 calls 2008 CES survey dataset.

  • ces2004 calls 2004 CES survey dataset.

  • ces0411 calls 2004-2011 CES survey dataset.

  • ces0406 calls 2004-2006 CES survey dataset.

  • ces2000 calls 2000 CES survey dataset.

  • ces1997 calls 1997 CES survey dataset.

  • ces1993 calls 1993 CES survey dataset.

  • ces1988 calls 1988 CES survey dataset.

  • ces1984 calls 1984 CES survey dataset.

  • ces1974 calls 1974 CES survey dataset.

  • ces7480 calls 1974-1980 CES survey dataset.

  • ces72_jnjl calls 1972 June-July CES survey dataset.

  • ces72_sep calls 1972 September CES survey dataset.

  • ces72_nov calls 1972 November CES survey dataset.

  • ces1968 calls 1968 CES survey dataset.

  • ces1965 calls 1965 CES survey dataset.

File Types

  • CES 2019 online survey. Loaded as a .dta file type.

  • CES 2019 phone survey. Loaded as a .tab file type.

  • CES 2015 online survey. Loaded as a .dta file type.

  • CES 2015 phone survey. Loaded as a .dta file type.

  • CES 2015 combined survey. Loaded as a .dta file type.

  • CES 2011 survey. Loaded as a .dta file type.

  • CES 2008 survey. Loaded as a .sav file type.

  • CES 2004 survey. Loaded as a .sav file type.

  • CES 2004-2011 surveys. Loaded as a .dta file type.

  • CES 2004-2006 surveys. Loaded as a .sav file type.

  • CES 2000 survey. Loaded as a .sav file type.

  • CES 1997 survey. Loaded as a. sav file type.

  • CES 1993 survey. Loaded as a .sav file type.

  • CES 1988 survey. Loaded as a .sav file type.

  • CES 1974 survey. Loaded as a .sav file type.

  • CES 1974-1980 surveys. Loaded as a .sav file type.

  • CES 1972 June-July surveys. Loaded as a .sav file type.

  • CES 1972 September survey. Loaded as a .sav file type.

  • CES 1972 November survey. Loaded as a .sav file type.

  • CES 1968 survey. Loaded as a .sav file type.

  • CES 1965 survey. Loaded as a .sav file type.

Incorrect/Repeated Code Calls

Incorrect (a non-existent survey code) will stop the function process and return an associated error message. Repeated code calls will load in the raw version of the requested table.

Extra Notes

Due to the naming of the columns in the 1965 and 1968 datasets it is recommended to download the associated codebook for the requested dataset.

Value

The called srvy at the designated environment position pos. Default environment position is set to be the global environment.

See Also

get_cescodes() function help.

Examples

## Not run: 
# call the 2019 CES online survey
get_ces("ces2019_web")

# convert variables to factor
labelled::to_factor(ces2019_web)

# preview dataset
head(ces2019_web)

## End(Not run)

Print a dataset of the CES survey codes and their associated calls.

Description

get_cescodes() prints out a data frame of the CES survey codes and the associated calls. Provides a quick way of looking up a CES survey code and the associated call.

Usage

get_cescodes(indx = 22)

Arguments

indx

A numeric value that determines the number of survey codes returned. Default is set to 22, or the total set of survey codes.

Details

Items under the Survey Code Calls and Index Code Calls can be copied and used with the get_ces() function.

Survey Codes

  • ces2019_web 2019 CES online survey dataset.

  • ces2019_phone 2019 CES phone survey dataset.

  • ces2015_web 2015 CES online survey dataset.

  • ces2015_phone 2015 CES phone survey dataset.

  • ces2015_combo 2015 CES combined (online/phone) dataset.

  • ces2011 2011 CES survey dataset.

  • ces2008 2008 CES survey dataset.

  • ces2004 2004 CES survey dataset.

  • ces0411 2004-2011 CES survey dataset.

  • ces0406 2004-2006 CES survey dataset.

  • ces2000 2000 CES survey dataset.

  • ces1997 1997 CES survey dataset.

  • ces1993 1993 CES survey dataset.

  • ces1988 1988 CES survey dataset.

  • ces1984 1984 CES survey dataset.

  • ces1974 1974 CES survey dataset.

  • ces7480 1974-1980 CES survey dataset.

  • ces72_jnjl 1972 June-July CES survey dataset.

  • ces72_sep 1972 September CES survey dataset.

  • ces72_nov 1972 November CES survey dataset.

  • ces1968 1968 CES survey dataset.

  • ces1965 1965 CES survey dataset.

Survey Code Calls

  • "ces2019_web" calls 2019 CES online survey dataset.

  • "ces2019_phone" calls 2019 CES phone survey dataset.

  • "ces2015_web" calls 2015 CES online survey dataset.

  • "ces2015_phone" calls 2015 CES phone survey dataset.

  • "ces2015_combo" calls 2015 CES combined (online/phone) dataset.

  • "ces2011" calls 2011 CES survey dataset.

  • "ces2008" calls 2008 CES survey dataset.

  • "ces2004" calls 2004 CES survey dataset.

  • "ces0411" calls 2004-2011 CES survey dataset.

  • "ces0406" calls 2004-2006 CES survey dataset.

  • "ces2000" calls 2000 CES survey dataset.

  • "ces1997" calls 1997 CES survey dataset.

  • "ces1993" calls 1993 CES survey dataset.

  • "ces1988" calls 1988 CES survey dataset.

  • "ces1984" calls 1984 CES survey dataset.

  • "ces1974" calls 1974 CES survey dataset.

  • "ces7480" calls 1974-1980 CES survey dataset.

  • "ces72_jnjl" calls 1972 June-July CES survey dataset.

  • "ces72_sep" calls 1972 September CES survey dataset.

  • "ces72_nov" calls 1972 November CES survey dataset.

  • "ces1968" calls 1968 CES survey dataset.

  • "ces1965" calls 1965 CES survey dataset.

Value

A printout of a designated number of Canadian Election Study survey codes and associated character codes used for the get_ces() function.

See Also

get_ces() function help.

Examples

# print out CES code calls
get_cescodes()

# call 1984 CES survey
get_ces("ces1984")

Creates a non-exhaustive dataframe of 21 variables with renamed columns.

Description

get_decon() creates a non-exhaustive dataset under the name decon consisting of 21 variables with renamed columns from the demographics, ideology, and economy sections of the 2019 CES online survey.

Usage

get_decon(pos = 1)

Arguments

pos

Environment assignment. Defaults to 1, which is an assignment to the global environment.

decon Variables

citizenship

Canadian citizenship status

yob

year of birth

gender

identified gender of the respondent

province_territory

Province or Territory of current residence

education

highest level of education completed

vote_likely

likelihood of voting on election day

vote_likely_ifable

likelihood to vote in first election for which respondent is eligible

votechoice

party most likely to vote for

votechoice_text

party most likely to vote for - text answers

votechoice_couldvote

party most likely to vote for if eligible to vote

votechoice_couldvote_text

party most likely to vote for if eligible to vote - text answers

votechoice_unlikely

party least likely to vote for

votechoice_unlikely_text

party least likely to vote for - text answers

votechoice_unlikely_couldvote

party least likely to vote for if eligible to vote

votechoice_unlikely_couldvote_text

party least likely to vote for if eligible to vote - text answers

vote_advancevote_choice

party voted for in the advanced ballot

vote_advancevote_choice_text

party voted for in the advanced ballot - text

vote_partylean

party toward which the respondent leans

vote_partylean_text

party toward which the respondent leans - text answers

vote_partylean_couldvote

party toward which the respondent leans if eligible

vote_partylean_couldvote_text

party toward which the respondent leans if eligible - text answers

votechoice_secondchoice

second choice party of respondent

votechoice_secondchoice_text

second choice party of respondent - text answers

votechoice_couldvote_secondchoice

second choice party of respondent if eligible

votechoice_couldvote_secondchoice_text

second choice party of respondent if eligible - text answers

votechoice_partynotvote_1

party respondent would note vote for - first ranking

votechoice_partynotvote_2

party respondent would note vote for - second ranking

votechoice_partynotvote_3

party respondent would note vote for - third ranking

votechoice_partynotvote_4

party respondent would note vote for - fourth ranking

votechoice_partynotvote_5

party respondent would note vote for - fifth ranking

votechoice_partynotvote_6

party respondent would note vote for - sixth ranking

votechoice_partynotvote_7

party respondent would note vote for - seventh ranking

votechoice_partynotvote_8

party respondent would note vote for - eighth ranking

votechoice_partynotvote_9

party respondent would note vote for - ninth ranking

votechoice_partynotvote_text

party respondent would note vote for - text answers

lr_scale

united column of lr_bef and lr_aft values; whether the respondent identifies on the political spectrum

lr_scale_bef

where the respondent identifies on the political spectrum; asked before party identification questions

lr_scale_aft

where the respondent identifies on the political spectrum; asked after party identification questions

religion

religion of respondent

sexuality_selected

sexual identity

sexuality_text

sexual identity; written answers

language_eng

language learned as child and still understand; selected response English

language_fr

language learned as a child and still understand; selected response French

language_abgl

language learned as a child and still understand; specified Aboriginal language

employment

employment status

income

total household income, before taxes, for the year 2018

income_cat

selected household income category

marital

marital status

econ_retro

response to question, 'over the past year, has Canada's economy:'

econ_fed

response to question, 'have the policies of the federal government made Canada's economy...'

econ_self

response to question, have the policies of the federal government made your financial situation...'

Details

NAs have not been removed. The politically left/right question variables (lr_bef and lr_aft) have also been joined into one column under the name lr_scale. All variables have been converted to factor type using labelled::to_factor and are listed below.

Value

The designed dataframe as a 'tbl_df' object under the name decon.

See Also

For further details, see https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/DUS88V Stephenson, Laura B; Harell, Allison; Rubenson, Daniel; Loewen, Peter John, 2020, "2019 Canadian Election Study - Online Survey", doi:10.7910/DVN/DUS88V, Harvard Dataverse, V1

Examples

## Not run: 
# call decon dataset
get_decon()

# preview decon
head(decon)

## End(Not run)

Create a preview dataframe object of a CES survey.

Description

get_preview() creates a truncated dataframe for a requested Canadian Election Study survey using an associated code to call and download the survey dataset.

Usage

get_preview(srvy, obs = 6, pos = 1)

Arguments

srvy

A CES survey code call. See Survey Code Calls below. srvy value must be a character string.

obs

A numerical value that determines the number of observations returned. If a value for obs is not given, then default value is 6 observations. Variable must be given as a numerical value.

pos

Environment assignment. Defaults to 1, which is an assignment to the global environment.

Details

Datasets

Datasets are loaded using either .dta or .sav file types and converted to factor type using the to_factor() function from the labelled package.

Survey Code Calls

get_preview() uses the same survey code calls as the get_ces() function. These survey code calls are listed below.

  • ces2019_web calls 2019 CES online survey dataset.

  • ces2019_phone calls 2019 CES phone survey dataset.

  • ces2015_web calls 2015 CES online survey dataset.

  • ces2015_phone calls 2015 CES phone survey dataset.

  • ces2015_combo calls 2015 CES combined (online/phone) dataset.

  • ces2011 calls 2011 CES survey dataset.

  • ces2008 calls 2008 CES survey dataset.

  • ces2004 calls 2004 CES survey dataset.

  • ces0411 calls 2004-2011 CES survey dataset.

  • ces0406 calls 2004-2006 CES survey dataset.

  • ces2000 calls 2000 CES survey dataset.

  • ces1997 calls 1997 CES survey dataset.

  • ces1993 calls 1993 CES survey dataset.

  • ces1988 calls 1988 CES survey dataset.

  • ces1984 calls 1984 CES survey dataset.

  • ces1974 calls 1974 CES survey dataset.

  • ces7480 calls 1974-1980 CES survey dataset.

  • ces72_jnjl calls 1972 June-July CES survey dataset.

  • ces72_sep calls 1972 September CES survey dataset.

  • ces72_nov calls 1972 November CES survey dataset.

  • ces1968 calls 1968 CES survey dataset.

  • ces1965 calls 1965 CES survey dataset.

Incorrect/Repeated Code Calls

Incorrect (a non-existent survey code) will stop the function process and return associated error messages. Repeated code calls will load in an unaltered version of the requested table.

Extra Notes

Due to the naming of the columns in the 1965 and 1968 datasets it is recommended to download the associated codebook for the requested dataset.

Value

The truncated version of the requested survey dataset srvy with the set number of observations obs to the designated environment pos.

See Also

get_ces() function help. get_cescodes() function help.

Examples

## Not run: 
# print out CES call codes
get_cescodes()

# call the 1993 CES dataset
get_ces("ces1993")

# preview the first 10 observations of the dataset
get_preview("ces1993", 10)

## End(Not run)

Prints out the survey question column label for a given column in a given dataset.

Description

get_question() prints out the survey question associated with a given column in a given dataset name.

Usage

get_question(do, q)

Arguments

do

a CES survey data object (given as a character string)

q

a column name in a CES survey data object (given as a character string)

Details

The order of the parameters for get_question are data object then column name. Both parameters must be character strings and cannot be reversed. To return the associated survey question, the get_question function relies on the var_label function from the labelled package.

Value

The associated question q in a loaded dataset do.

See Also

get_ces() function help. get_cescodes() help.

Examples

# print out CES code calls
get_cescodes()

# call CES survey
get_ces("ces1988")

# request the survey question for column a6
get_question("ces1988", "a6")