Import municipal census data for one or more elections
at the municipal level (from 1982 onwards). This function
downloads and processes raw municipal data files for specified
elections. No CERA data is included as municipalities (note that
CERA ballots will be included in the summaries (see
import_poll_station_data()
and
import_candidacies_data()
)
Source
Some definitions of variables were extracted from https://www.ige.gal.
Arguments
- type_elec
Type elections for which data is available. It should be one of the following values: "referendum", "congress", "senate", "local", "cabildo" (Canarian council) or "EU".
- year
A vector or single value representing the years of the elections to be considered. Please, check in
dates_elections_spain
that elections of the specified type are available for the provided year.- date
A vector or single value representing the dates of the elections to be considered. If date was provided, it should be in format %Y-%m-%d (e.g., '2000-01-01'). Defaults to
NULL
. If no date was provided,year
should be provided as numerical variable. Please, check indates_elections_spain
that elections of the specified type are available.- verbose
Flag to indicate whether detailed messages should be printed during execution. Defaults to
TRUE
.
Value
A tibble with rows corresponding to municipalities for each election, including the following variables:
- id_elec
election's id constructed from the election code
cod_elec
and datedate_elec
.- cod_elec
code representing the type of election:
"01"
(referendum),"02"
(congress),"03"
(senate),"04"
(local elections),"06"
(cabildo - Canarian council - elections),"07"
(European Parliament elections).- type_elec
type of election.
- date_elec
date of the election.
- id_INE_mun
municipality ID constructed from the ccaa-prov-mun codes provided by INE.
- cod_INE_ccaa, ccaa
codes and names for regions (ccaa) to which the municipalities belong.
- cod_INE_prov, prov
codes and names for the provinces to which the municipalities belong.
- cod_INE_mun, mun
code, and name for municipalities.
- cod_mun_jud_district, cod_mun_prov_council
codes for the judicial district and provincial council.
- n_poll_stations
number of polling stations in each municipality.
- pop_res_mun
population census of residents (CER + CERA) at municipality level.
- census_INE_mun
population eligible to vote at municipality level.
- census_counting_mun
population eligible to vote after claims at municipality level.
- census_CERE_mun
census of foreign nationals, relevant only for EU elections at municipality level.
Details
This function fetches municipal-level data for the
specified elections by downloading the corresponding files from
{pollspaindata}
package and processing them into a tidy format.
It automatically handles the download, loading, and merging
of data across multiple election periods as specified by the user.
Author
Javier Alvarez-Liebana, David Pereiro Pol, Mafalda Gonzalez Gonzalez, Irene Bosque Gala and Mikaela De Smedt.
Examples
## Correct examples
# Fetch municipal census for congress elections in a single date
mun_census <-
import_mun_census_data(type_elec = "congress", year = 2023)
#> Import census data
#> [x] Checking if parameters are allowed...
#> [x] Importing census mun data ...
# Fetch municipal census for congress elections in multiple dates
mun_census <-
import_mun_census_data(type_elec = "congress",
year = c(2016, 2023), date = "2019-04-28")
#> Import census data
#> [x] Checking if parameters are allowed...
#> [x] Importing census mun data ...
# ----
# Incorrect examples
# ----
if (FALSE) { # \dontrun{
# Wrong examples
# Invalid election type: "national" is not a valid election type
import_mun_census_data(type_elec = "national", year = 2019)
# Invalid verbose argument: verbose should be a logical variable
import_mun_census_data(type_elec = "congress", year = 2023,
verbose = "yes")
# Invalid election: no congress elections are available in 5-2019.
# Please check dataset dates_elections_spain
import_mun_census_data(type_elec = "congress", date = "2019-05-01")
#' # Invalid election: no congress elections are available in 2018.
# Please check dataset dates_elections_spain
import_mun_census_data(type_elec = "congress", year = 2018)
# Invalid date format: date should be in %Y-%m-%d format
import_mun_census_data(type_elec = "congress", date = "26-06-2016")
} # }