add_capital_distance() allows you to add capital-to-capital distance to a dyad-year or state-year data frame. The capitals are coded in the capitals data frame, along with their latitudes and longitudes. The distance variable that emerges capdist is calculated using the "Vincenty" method (i.e. "as the crow flies") and is expressed in kilometers.

add_capital_distance(data)

Arguments

data

a dyad-year data frame (either "directed" or "non-directed") or state-year data frame

Value

add_capital_distance() takes a dyad-year or state-year data frame and adds the capital-to-capital distance between the first state and the second state (in dyad-year data) or the minimum capital-to-capital distance for a given state in a given year. A minor note about this function: cases of capital transition are recorded in the capitals data but, in the conversion to capital-years (and eventual merging into a dyad-year data frame), the Jan. 1 capital is used for calculating distances.

Details

The function leans on attributes of the data that are provided by the create_dyadyear() or create_stateyear() function. Make sure that function (or data created by that function) appear at the top of the proverbial pipe.

Author

Steven V. Miller

Examples

# \donttest{ # just call `library(tidyverse)` at the top of the your script library(magrittr) cow_ddy %>% add_capital_distance()
#> # A tibble: 2,063,670 x 4 #> ccode1 ccode2 year capdist #> <dbl> <dbl> <int> <dbl> #> 1 2 20 1920 735. #> 2 2 20 1921 735. #> 3 2 20 1922 735. #> 4 2 20 1923 735. #> 5 2 20 1924 735. #> 6 2 20 1925 735. #> 7 2 20 1926 735. #> 8 2 20 1927 735. #> 9 2 20 1928 735. #> 10 2 20 1929 735. #> # … with 2,063,660 more rows
create_stateyears() %>% add_capital_distance()
#> Joining, by = c("ccode", "year")
#> # A tibble: 16,731 x 4 #> ccode statenme year mincapdist #> <dbl> <chr> <int> <dbl> #> 1 2 United States of America 1816 5742. #> 2 2 United States of America 1817 5742. #> 3 2 United States of America 1818 5742. #> 4 2 United States of America 1819 5742. #> 5 2 United States of America 1820 5742. #> 6 2 United States of America 1821 5742. #> 7 2 United States of America 1822 5744. #> 8 2 United States of America 1823 5744. #> 9 2 United States of America 1824 5744. #> 10 2 United States of America 1825 5744. #> # … with 16,721 more rows
# }