library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
#> ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
#> ✓ tibble 3.0.3 ✓ dplyr 1.0.2
#> ✓ tidyr 1.1.2 ✓ stringr 1.4.0
#> ✓ readr 1.3.1 ✓ forcats 0.5.0
#> ── Conflicts ────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
library(stevemisc)
#>
#> Attaching package: 'stevemisc'
#> The following object is masked from 'package:dplyr':
#>
#> tbl_dfThe first function I added to stevemisc is the sbtscs() function for creating peace years (“spells”) in binary time-series cross-sectional (BTSCS) data. This function liberally copies Dave Armstrong’s btscs() function from his DAMisc package, but provides some tidy syntax underneath to 1) speed up computation and 2) avoid errors that come when a lot of cross-sectional units don’t have an event onset. I first introduced this function in 2017.
Its use is simple. I’ll show it by reference to the usa_mids data in stevemisc. The usa_mids data set is a non-directed dyad-year data set for all U.S. threats, displays, or uses of force (MIDs) against a state system member from 1816 to 2010. The data have 14,586 rows and six columns.
usa_mids
#> # A tibble: 14,586 x 6
#> dyad ccode1 ccode2 year midongoing midonset
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1002020 2 20 1920 0 0
#> 2 1002020 2 20 1921 0 0
#> 3 1002020 2 20 1922 0 0
#> 4 1002020 2 20 1923 0 0
#> 5 1002020 2 20 1924 0 0
#> 6 1002020 2 20 1925 0 0
#> 7 1002020 2 20 1926 0 0
#> 8 1002020 2 20 1927 0 0
#> 9 1002020 2 20 1928 0 0
#> 10 1002020 2 20 1929 0 0
#> # … with 14,576 more rowsObserve that the six columns have a unique dyad identifier (dyad), a unique country code identifier for the United States (ccode1, which is always 2), a unique country code for the other side of the dyad (ccode2), an identifier for the time unit of interest (here: year for dyad-year data), a column for whether there is an active MID in the dyad-year (midongoing), and a column for whether there is a unique MID onset (midonset) in the dyad-year.
A user interested in creating peace-years consistent with Beck, Katz, and Tucker (1998) would simply need to use the sbtscs() function in stevemisc. In order, specify the data (usa_mids), the column pertaining to the event (midongoing), the time unit (year), and the unique identifier for the cross-sectional unit (dyad). The output that the user gets is the full data, plus a spell column attached at the end. For convenience, the output will not be a tibble, but it’s also not hard to add that as a pipe command at the end of the sbtscs() function.
usa_mids <- sbtscs(usa_mids, midongoing, year, dyad) %>% as_tibble()
usa_mids
#> # A tibble: 14,586 x 7
#> dyad ccode1 ccode2 year midongoing midonset spell
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1002020 2 20 1920 0 0 0
#> 2 1002020 2 20 1921 0 0 1
#> 3 1002020 2 20 1922 0 0 2
#> 4 1002020 2 20 1923 0 0 3
#> 5 1002020 2 20 1924 0 0 4
#> 6 1002020 2 20 1925 0 0 5
#> 7 1002020 2 20 1926 0 0 6
#> 8 1002020 2 20 1927 0 0 7
#> 9 1002020 2 20 1928 0 0 8
#> 10 1002020 2 20 1929 0 0 9
#> # … with 14,576 more rowsHere’s what it would look like for the United States and, say, Tuvalu. I select this dyad because I know it’s relatively new. Tuvalu only joins the Correlates of War state system data in 2000. Observe that every peace year must start with 0.
| dyad | ccode1 | ccode2 | year | midongoing | midonset | spell |
|---|---|---|---|---|---|---|
| 1002947 | 2 | 947 | 2000 | 0 | 0 | 0 |
| 1002947 | 2 | 947 | 2001 | 0 | 0 | 1 |
| 1002947 | 2 | 947 | 2002 | 0 | 0 | 2 |
| 1002947 | 2 | 947 | 2003 | 0 | 0 | 3 |
| 1002947 | 2 | 947 | 2004 | 0 | 0 | 4 |
| 1002947 | 2 | 947 | 2005 | 0 | 0 | 5 |
| 1002947 | 2 | 947 | 2006 | 0 | 0 | 6 |
| 1002947 | 2 | 947 | 2007 | 0 | 0 | 7 |
| 1002947 | 2 | 947 | 2008 | 0 | 0 | 8 |
| 1002947 | 2 | 947 | 2009 | 0 | 0 | 9 |
| 1002947 | 2 | 947 | 2010 | 0 | 0 | 10 |
Here’s what it would look like for a trickier case: the United State and Haiti. Scholars of international conflict, U.S. foreign policy history, and “dollar diplomacy” will know this is a peculiar case in the data. Namely, the United States occupied Haiti from 1916 to 1933, at least as that’s represented in these data. The military occupation drops Haiti from the international system for those years.
| dyad | ccode1 | ccode2 | year | midongoing | midonset | spell |
|---|---|---|---|---|---|---|
| 1002041 | 2 | 41 | 1859 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1860 | 0 | 0 | 1 |
| 1002041 | 2 | 41 | 1861 | 0 | 0 | 2 |
| 1002041 | 2 | 41 | 1862 | 0 | 0 | 3 |
| 1002041 | 2 | 41 | 1863 | 0 | 0 | 4 |
| 1002041 | 2 | 41 | 1864 | 0 | 0 | 5 |
| 1002041 | 2 | 41 | 1865 | 0 | 0 | 6 |
| 1002041 | 2 | 41 | 1866 | 0 | 0 | 7 |
| 1002041 | 2 | 41 | 1867 | 0 | 0 | 8 |
| 1002041 | 2 | 41 | 1868 | 0 | 0 | 9 |
| 1002041 | 2 | 41 | 1869 | 1 | 1 | 10 |
| 1002041 | 2 | 41 | 1870 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1871 | 0 | 0 | 1 |
| 1002041 | 2 | 41 | 1872 | 0 | 0 | 2 |
| 1002041 | 2 | 41 | 1873 | 0 | 0 | 3 |
| 1002041 | 2 | 41 | 1874 | 0 | 0 | 4 |
| 1002041 | 2 | 41 | 1875 | 0 | 0 | 5 |
| 1002041 | 2 | 41 | 1876 | 0 | 0 | 6 |
| 1002041 | 2 | 41 | 1877 | 0 | 0 | 7 |
| 1002041 | 2 | 41 | 1878 | 0 | 0 | 8 |
| 1002041 | 2 | 41 | 1879 | 0 | 0 | 9 |
| 1002041 | 2 | 41 | 1880 | 0 | 0 | 10 |
| 1002041 | 2 | 41 | 1881 | 0 | 0 | 11 |
| 1002041 | 2 | 41 | 1882 | 1 | 1 | 12 |
| 1002041 | 2 | 41 | 1883 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1884 | 0 | 0 | 1 |
| 1002041 | 2 | 41 | 1885 | 0 | 0 | 2 |
| 1002041 | 2 | 41 | 1886 | 0 | 0 | 3 |
| 1002041 | 2 | 41 | 1887 | 0 | 0 | 4 |
| 1002041 | 2 | 41 | 1888 | 1 | 1 | 5 |
| 1002041 | 2 | 41 | 1889 | 1 | 1 | 0 |
| 1002041 | 2 | 41 | 1890 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1891 | 1 | 1 | 1 |
| 1002041 | 2 | 41 | 1892 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1893 | 0 | 0 | 1 |
| 1002041 | 2 | 41 | 1894 | 0 | 0 | 2 |
| 1002041 | 2 | 41 | 1895 | 0 | 0 | 3 |
| 1002041 | 2 | 41 | 1896 | 0 | 0 | 4 |
| 1002041 | 2 | 41 | 1897 | 0 | 0 | 5 |
| 1002041 | 2 | 41 | 1898 | 0 | 0 | 6 |
| 1002041 | 2 | 41 | 1899 | 0 | 0 | 7 |
| 1002041 | 2 | 41 | 1900 | 0 | 0 | 8 |
| 1002041 | 2 | 41 | 1901 | 0 | 0 | 9 |
| 1002041 | 2 | 41 | 1902 | 0 | 0 | 10 |
| 1002041 | 2 | 41 | 1903 | 0 | 0 | 11 |
| 1002041 | 2 | 41 | 1904 | 0 | 0 | 12 |
| 1002041 | 2 | 41 | 1905 | 0 | 0 | 13 |
| 1002041 | 2 | 41 | 1906 | 0 | 0 | 14 |
| 1002041 | 2 | 41 | 1907 | 0 | 0 | 15 |
| 1002041 | 2 | 41 | 1908 | 0 | 0 | 16 |
| 1002041 | 2 | 41 | 1909 | 0 | 0 | 17 |
| 1002041 | 2 | 41 | 1910 | 0 | 0 | 18 |
| 1002041 | 2 | 41 | 1911 | 1 | 1 | 19 |
| 1002041 | 2 | 41 | 1912 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1913 | 0 | 0 | 1 |
| 1002041 | 2 | 41 | 1914 | 1 | 1 | 2 |
| 1002041 | 2 | 41 | 1915 | 1 | 0 | 0 |
| 1002041 | 2 | 41 | 1934 | 0 | 0 | 0 |
| 1002041 | 2 | 41 | 1935 | 0 | 0 | 1 |
| 1002041 | 2 | 41 | 1936 | 0 | 0 | 2 |
| 1002041 | 2 | 41 | 1937 | 0 | 0 | 3 |
| 1002041 | 2 | 41 | 1938 | 0 | 0 | 4 |
| 1002041 | 2 | 41 | 1939 | 0 | 0 | 5 |
| 1002041 | 2 | 41 | 1940 | 0 | 0 | 6 |
Here, the sbtscs() function is doing what it’s supposed to be doing. It starts the peace spell at 0 (because at least there was no MID between the United States and Haiti in the first year of the dyad). It stops at 10 because, at the 10th-year spell, the data record a MID between the United States and Haiti.1 Despite 10 years of peace, there was a conflict. Upon the first peace year afterward (i.e. year with no MID ongoing), the counter starts again at 0.
Look ahead to the 1880s, especially 1888 and 1889. Therein, the United States and Haiti had two unique dispute onsets in simultaneous years. The first, in 1888, was a U.S. show of force against the Haitian government after a U.S. ship was impounded during a period of civil unrest. The second, in 1889, followed when Benjamin Harrison dispatched an American fleet to Port-au-Prince to intimidate Haiti into leasing Môle Saint-Nicolas to the United States so that naval base could be established there.
This means the five-year peace spell was snapped in 1888 for that first case. The counter starts again at 0 for 1889, but there was a new dispute that year as well. Thus, the spell count starts again at 0 for 1890 and proceeds from there.
There is the more difficult case of what happens when there is a break in the cross-sectional unit’s history. These have emerged in various places in the CoW state system data. Germany occupied several countries during World War II. The U.S. occupied all of Cuba, Dominican Republic, and Haiti for a stretch spanning the late 19th century and early 20th century. Paraguay was occupied for six years following the Paraguayan War as well. These are just some examples.
Where that happens, as it does here, the sbtscs() by way of Dave Armstrong’s btscs() function appropriately acknowledges that temporal gap and starts the spells anew when the cross-sectional unit re-emerges in the data.
You can use this package to calculate peace years and spells, which should be handy for those of you that do a lot of BTSCS models and need to adjust for temporal dependence. This is prominent in the conflict context. sbtscs() is analogous to the btscs function in Stata. Much of the underlying code comes from Dave Armstrong’s port of it. I just offered some tidy-friendly syntax to speed up computation, as I demonstrate here.
Armstrong, Dave. 2020. “DAMisc: Dave Armstrong’s Miscellaneous Functions”. URL: https://cran.r-project.org/web/packages/DAMisc/index.html
Beck, Nathaniel, Jonathan N. Katz, and Richard Tucker. 1998. “Taking Time Seriously: Time-Series-Cross-Section Analysis with a Binary Dependent Variable.” American Journal of Political Science 42(4): 1260–1288.
Gibler, Douglas M., Steven V. Miller, and Erin K. Little. 2016. “An Analysis of the Militarized Interstate Dispute (MID) Dataset, 1816-2001.” International Studies Quarterly 60(4): 719-730.
Miller, Steven V. 2017. “Quickly Create Peace Years for BTSCS Models with sbtscs in stevemisc”. URL: http://svmiller.com/blog/2017/06/quickly-create-peace-years-for-btscs-models-with-stevemisc/
If you were curious, this was a show of force by the United States in which the U.S. dispatched ships to Port-au-Prince after Haiti publicly announced its intention to have its own analogue to a Monroe Doctrine.↩︎