The effect of legislation on sex ratio at birth
This is an example of using EventStudies on long-form data from social sciences. Specifically, we're going to be using data which
# Load the packages:
using TSFrames # time series package - EventStudies only accepts this, since it has a defined index type
using EventStudies # event study package
using DataFrames # data manipulation
using CairoMakie # plottingLoad the data.
data = EventStudies.load_data("bigdata.csv")<div><div style = "float: left;"><span>16992×11 DataFrame</span></div><div style = "float: right;"><span style = "font-style: italic;">16982 rows omitted</span></div><div style = "clear: both;"></div></div><div class = "data-frame" style = "overflow-x: scroll;"><table class = "data-frame" style = "margin-bottom: 6px;"><thead><tr class = "header"><th class = "rowNumber" style = "font-weight: bold; text-align: right;">Row</th><th style = "text-align: left;">country</th><th style = "text-align: left;">iso_code</th><th style = "text-align: left;">year</th><th style = "text-align: left;">totpop</th><th style = "text-align: left;">sex_rat</th><th style = "text-align: left;">birthrate</th><th style = "text-align: left;">intyear</th><th style = "text-align: left;">year_es</th><th style = "text-align: left;">intyear_es</th><th style = "text-align: left;">agrigdp_rat</th><th style = "text-align: left;">gender_inequality_index</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "String" style = "text-align: left;">String</th><th title = "InlineStrings.String3" style = "text-align: left;">String3</th><th title = "Dates.Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Union{Missing, Dates.Date}" style = "text-align: left;">Date</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Union{Missing, Int64}" style = "text-align: left;">Int64?</th><th title = "Union{Missing, Float64}" style = "text-align: left;">Float64?</th><th title = "Union{Missing, Float64}" style = "text-align: left;">Float64?</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">Burundi</td><td style = "text-align: left;">BDI</td><td style = "text-align: left;">1950-01-01</td><td style = "text-align: right;">2229.32</td><td style = "text-align: right;">102.5</td><td style = "text-align: right;">51.334</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">1950</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">Burundi</td><td style = "text-align: left;">BDI</td><td style = "text-align: left;">1951-01-01</td><td style = "text-align: right;">2278.9</td><td style = "text-align: right;">102.5</td><td style = "text-align: right;">50.678</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">1951</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">Burundi</td><td style = "text-align: left;">BDI</td><td style = "text-align: left;">1952-01-01</td><td style = "text-align: right;">2327.59</td><td style = "text-align: right;">102.5</td><td style = "text-align: right;">49.933</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">1952</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">4</td><td style = "text-align: left;">Burundi</td><td style = "text-align: left;">BDI</td><td style = "text-align: left;">1953-01-01</td><td style = "text-align: right;">2375.48</td><td style = "text-align: right;">102.5</td><td style = "text-align: right;">49.448</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">1953</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">5</td><td style = "text-align: left;">Burundi</td><td style = "text-align: left;">BDI</td><td style = "text-align: left;">1954-01-01</td><td style = "text-align: right;">2422.72</td><td style = "text-align: right;">102.5</td><td style = "text-align: right;">48.883</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">1954</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td><td style = "text-align: right;">⋮</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">16988</td><td style = "text-align: left;">Wallis and Futuna Islands</td><td style = "text-align: left;">WLF</td><td style = "text-align: left;">2017-01-01</td><td style = "text-align: right;">12.002</td><td style = "text-align: right;">104.8</td><td style = "text-align: right;">12.713</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">2017</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">16989</td><td style = "text-align: left;">Wallis and Futuna Islands</td><td style = "text-align: left;">WLF</td><td style = "text-align: left;">2018-01-01</td><td style = "text-align: right;">11.87</td><td style = "text-align: right;">104.8</td><td style = "text-align: right;">12.381</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">2018</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">16990</td><td style = "text-align: left;">Wallis and Futuna Islands</td><td style = "text-align: left;">WLF</td><td style = "text-align: left;">2019-01-01</td><td style = "text-align: right;">11.761</td><td style = "text-align: right;">104.8</td><td style = "text-align: right;">12.189</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">2019</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">16991</td><td style = "text-align: left;">Wallis and Futuna Islands</td><td style = "text-align: left;">WLF</td><td style = "text-align: left;">2020-01-01</td><td style = "text-align: right;">11.667</td><td style = "text-align: right;">104.8</td><td style = "text-align: right;">11.997</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">2020</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">16992</td><td style = "text-align: left;">Wallis and Futuna Islands</td><td style = "text-align: left;">WLF</td><td style = "text-align: left;">2021-01-01</td><td style = "text-align: right;">11.642</td><td style = "text-align: right;">104.8</td><td style = "text-align: right;">11.816</td><td style = "font-style: italic; text-align: left;">missing</td><td style = "text-align: right;">2021</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td><td style = "font-style: italic; text-align: right;">missing</td></tr></tbody></table></div>This data is in "long" format, so we need to convert it to "wide" format.
We do this by grouping by country,
country_data = groupby(data, :country)GroupedDataFrame with 236 groups based on key: country
| Row | country | iso_code | year | totpop | sex_rat | birthrate | intyear | year_es | intyear_es | agrigdp_rat | gender_inequality_index |
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | String3 | Date | Float64 | Float64 | Float64 | Date | Int64 | Int64? | Float64? | Float64? | |
| 1 | Burundi | BDI | 1950-01-01 | 2229.32 | 102.5 | 51.334 | missing | 1950 | missing | missing | missing |
| 2 | Burundi | BDI | 1951-01-01 | 2278.9 | 102.5 | 50.678 | missing | 1951 | missing | missing | missing |
| 3 | Burundi | BDI | 1952-01-01 | 2327.59 | 102.5 | 49.933 | missing | 1952 | missing | missing | missing |
| 4 | Burundi | BDI | 1953-01-01 | 2375.48 | 102.5 | 49.448 | missing | 1953 | missing | missing | missing |
| 5 | Burundi | BDI | 1954-01-01 | 2422.72 | 102.5 | 48.883 | missing | 1954 | missing | missing | missing |
| 6 | Burundi | BDI | 1955-01-01 | 2470.79 | 102.5 | 48.399 | missing | 1955 | missing | missing | missing |
| 7 | Burundi | BDI | 1956-01-01 | 2519.59 | 102.5 | 47.885 | missing | 1956 | missing | missing | missing |
| 8 | Burundi | BDI | 1957-01-01 | 2568.92 | 102.5 | 47.398 | missing | 1957 | missing | missing | missing |
| 9 | Burundi | BDI | 1958-01-01 | 2618.76 | 102.5 | 47.013 | missing | 1958 | missing | missing | missing |
| 10 | Burundi | BDI | 1959-01-01 | 2667.55 | 102.5 | 46.736 | missing | 1959 | missing | missing | missing |
| 11 | Burundi | BDI | 1960-01-01 | 2719.73 | 102.5 | 46.501 | missing | 1960 | missing | missing | missing |
| 12 | Burundi | BDI | 1961-01-01 | 2773.52 | 102.5 | 46.265 | missing | 1961 | missing | missing | missing |
| 13 | Burundi | BDI | 1962-01-01 | 2858.42 | 102.5 | 46.522 | missing | 1962 | missing | missing | missing |
| 14 | Burundi | BDI | 1963-01-01 | 2916.37 | 102.5 | 46.368 | missing | 1963 | missing | missing | missing |
| 15 | Burundi | BDI | 1964-01-01 | 2979.89 | 102.5 | 46.25 | missing | 1964 | missing | missing | missing |
| 16 | Burundi | BDI | 1965-01-01 | 3086.55 | 102.5 | 46.896 | missing | 1965 | missing | missing | missing |
| 17 | Burundi | BDI | 1966-01-01 | 3149.72 | 102.5 | 46.85 | missing | 1966 | missing | missing | missing |
| 18 | Burundi | BDI | 1967-01-01 | 3237.04 | 102.5 | 47.124 | missing | 1967 | missing | missing | missing |
| 19 | Burundi | BDI | 1968-01-01 | 3311.95 | 102.4 | 47.192 | missing | 1968 | missing | missing | missing |
| 20 | Burundi | BDI | 1969-01-01 | 3392.85 | 102.4 | 47.45 | missing | 1969 | missing | missing | missing |
| 21 | Burundi | BDI | 1970-01-01 | 3456.01 | 102.4 | 47.339 | missing | 1970 | missing | 65.3314 | missing |
| 22 | Burundi | BDI | 1971-01-01 | 3539.66 | 102.4 | 47.455 | missing | 1971 | missing | 64.7618 | missing |
| 23 | Burundi | BDI | 1972-01-01 | 3624.48 | 102.4 | 47.633 | missing | 1972 | missing | 60.7731 | missing |
| 24 | Burundi | BDI | 1973-01-01 | 3533.91 | 102.4 | 46.325 | missing | 1973 | missing | 63.3136 | missing |
| 25 | Burundi | BDI | 1974-01-01 | 3608.99 | 102.4 | 46.718 | missing | 1974 | missing | 61.0342 | missing |
| 26 | Burundi | BDI | 1975-01-01 | 3711.07 | 102.4 | 47.371 | missing | 1975 | missing | 61.3036 | missing |
| 27 | Burundi | BDI | 1976-01-01 | 3787.39 | 102.4 | 47.499 | missing | 1976 | missing | 59.4755 | missing |
| 28 | Burundi | BDI | 1977-01-01 | 3874.39 | 102.4 | 47.728 | missing | 1977 | missing | 55.5802 | missing |
| 29 | Burundi | BDI | 1978-01-01 | 3980.47 | 102.5 | 48.16 | missing | 1978 | missing | 53.964 | missing |
| 30 | Burundi | BDI | 1979-01-01 | 4098.35 | 102.4 | 48.865 | missing | 1979 | missing | 53.8322 | missing |
| 31 | Burundi | BDI | 1980-01-01 | 4176.53 | 102.5 | 48.896 | missing | 1980 | missing | 57.5719 | missing |
| 32 | Burundi | BDI | 1981-01-01 | 4449.14 | 102.5 | 50.47 | missing | 1981 | missing | 58.1426 | missing |
| 33 | Burundi | BDI | 1982-01-01 | 4532.34 | 102.4 | 49.673 | missing | 1982 | missing | 52.6127 | missing |
| 34 | Burundi | BDI | 1983-01-01 | 4672.2 | 102.4 | 49.495 | missing | 1983 | missing | 53.4822 | missing |
| 35 | Burundi | BDI | 1984-01-01 | 4780.81 | 102.4 | 48.763 | missing | 1984 | missing | 54.6599 | missing |
| 36 | Burundi | BDI | 1985-01-01 | 4903.72 | 102.5 | 48.338 | missing | 1985 | missing | 55.952 | missing |
| 37 | Burundi | BDI | 1986-01-01 | 4992.32 | 102.5 | 47.762 | missing | 1986 | missing | 52.5196 | missing |
| 38 | Burundi | BDI | 1987-01-01 | 5091.09 | 102.5 | 47.474 | missing | 1987 | missing | 50.5564 | missing |
| 39 | Burundi | BDI | 1988-01-01 | 5224.45 | 102.5 | 47.248 | missing | 1988 | missing | 48.2156 | missing |
| 40 | Burundi | BDI | 1989-01-01 | 5319.23 | 102.4 | 46.912 | missing | 1989 | missing | 47.1221 | missing |
| 41 | Burundi | BDI | 1990-01-01 | 5428.16 | 102.4 | 46.545 | missing | 1990 | missing | 51.0569 | missing |
| 42 | Burundi | BDI | 1991-01-01 | 5539.42 | 102.4 | 46.128 | missing | 1991 | missing | 48.5979 | missing |
| 43 | Burundi | BDI | 1992-01-01 | 5650.23 | 102.4 | 45.702 | missing | 1992 | missing | 48.0045 | missing |
| 44 | Burundi | BDI | 1993-01-01 | 5835.94 | 102.3 | 46.026 | missing | 1993 | missing | 47.1698 | missing |
| 45 | Burundi | BDI | 1994-01-01 | 5274.51 | 102.3 | 39.132 | missing | 1994 | missing | 40.7323 | missing |
| 46 | Burundi | BDI | 1995-01-01 | 5898.31 | 102.3 | 44.504 | missing | 1995 | missing | 42.0227 | missing |
| 47 | Burundi | BDI | 1996-01-01 | 5967.25 | 102.3 | 43.858 | missing | 1996 | missing | 53.3809 | missing |
| 48 | Burundi | BDI | 1997-01-01 | 5893.76 | 102.2 | 41.867 | missing | 1997 | missing | 42.4219 | missing |
| 49 | Burundi | BDI | 1998-01-01 | 5953.97 | 102.3 | 41.346 | missing | 1998 | missing | 44.5387 | 0.623 |
| 50 | Burundi | BDI | 1999-01-01 | 6116.72 | 102.3 | 42.005 | missing | 1999 | missing | 47.6353 | 0.655 |
| 51 | Burundi | BDI | 2000-01-01 | 6243.65 | 102.3 | 42.473 | missing | 2000 | missing | 44.107 | 0.616 |
| 52 | Burundi | BDI | 2001-01-01 | 6371.67 | 102.3 | 42.882 | missing | 2001 | missing | 43.8431 | 0.612 |
| 53 | Burundi | BDI | 2002-01-01 | 6559.78 | 102.2 | 43.807 | missing | 2002 | missing | 43.3336 | 0.611 |
| 54 | Burundi | BDI | 2003-01-01 | 6738.09 | 102.2 | 44.485 | missing | 2003 | missing | 42.8413 | 0.597 |
| 55 | Burundi | BDI | 2004-01-01 | 6983.6 | 102.1 | 45.297 | missing | 2004 | missing | 41.9026 | 0.593 |
| 56 | Burundi | BDI | 2005-01-01 | 7257.39 | 102.1 | 46.03 | missing | 2005 | missing | 40.8481 | 0.562 |
| 57 | Burundi | BDI | 2006-01-01 | 7520.36 | 102.1 | 46.38 | missing | 2006 | missing | 40.6377 | 0.557 |
| 58 | Burundi | BDI | 2007-01-01 | 7796.02 | 102.2 | 46.525 | missing | 2007 | missing | 34.9342 | 0.552 |
| 59 | Burundi | BDI | 2008-01-01 | 8093.2 | 102.1 | 46.562 | missing | 2008 | missing | 38.0048 | 0.547 |
| 60 | Burundi | BDI | 2009-01-01 | 8463.02 | 102.2 | 46.681 | missing | 2009 | missing | 36.7214 | 0.548 |
| 61 | Burundi | BDI | 2010-01-01 | 8955.71 | 102.2 | 46.691 | missing | 2010 | missing | 38.4305 | 0.54 |
| 62 | Burundi | BDI | 2011-01-01 | 9297.5 | 102.2 | 45.583 | missing | 2011 | missing | 36.7046 | 0.537 |
| 63 | Burundi | BDI | 2012-01-01 | 9613.97 | 102.2 | 44.413 | missing | 2012 | missing | 35.42 | 0.533 |
| 64 | Burundi | BDI | 2013-01-01 | 9976.99 | 102.2 | 43.402 | missing | 2013 | missing | 38.3674 | 0.528 |
| 65 | Burundi | BDI | 2014-01-01 | 10322.2 | 102.3 | 42.356 | missing | 2014 | missing | 34.9582 | 0.525 |
| 66 | Burundi | BDI | 2015-01-01 | 10667.7 | 102.3 | 41.321 | missing | 2015 | missing | 30.6847 | 0.517 |
| 67 | Burundi | BDI | 2016-01-01 | 10786.6 | 102.4 | 39.479 | missing | 2016 | missing | 31.5443 | 0.514 |
| 68 | Burundi | BDI | 2017-01-01 | 11020.0 | 102.4 | 38.124 | missing | 2017 | missing | 28.5466 | 0.51 |
| 69 | Burundi | BDI | 2018-01-01 | 11291.2 | 102.4 | 37.011 | missing | 2018 | missing | 29.0119 | 0.508 |
| 70 | Burundi | BDI | 2019-01-01 | 11695.8 | 102.4 | 36.323 | missing | 2019 | missing | 28.8444 | 0.507 |
| 71 | Burundi | BDI | 2020-01-01 | 12053.9 | 102.4 | 35.603 | missing | 2020 | missing | 28.625 | 0.506 |
| 72 | Burundi | BDI | 2021-01-01 | 12386.6 | 102.5 | 34.842 | missing | 2021 | missing | 28.6602 | 0.505 |
⋮
| Row | country | iso_code | year | totpop | sex_rat | birthrate | intyear | year_es | intyear_es | agrigdp_rat | gender_inequality_index |
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | String3 | Date | Float64 | Float64 | Float64 | Date | Int64 | Int64? | Float64? | Float64? | |
| 1 | Wallis and Futuna Islands | WLF | 1950-01-01 | 8.452 | 104.9 | 44.994 | missing | 1950 | missing | missing | missing |
| 2 | Wallis and Futuna Islands | WLF | 1951-01-01 | 8.618 | 104.9 | 45.027 | missing | 1951 | missing | missing | missing |
| 3 | Wallis and Futuna Islands | WLF | 1952-01-01 | 9.002 | 104.9 | 45.306 | missing | 1952 | missing | missing | missing |
| 4 | Wallis and Futuna Islands | WLF | 1953-01-01 | 9.337 | 104.9 | 45.805 | missing | 1953 | missing | missing | missing |
| 5 | Wallis and Futuna Islands | WLF | 1954-01-01 | 9.719 | 104.9 | 46.266 | missing | 1954 | missing | missing | missing |
| 6 | Wallis and Futuna Islands | WLF | 1955-01-01 | 9.667 | 104.9 | 45.574 | missing | 1955 | missing | missing | missing |
| 7 | Wallis and Futuna Islands | WLF | 1956-01-01 | 9.564 | 104.9 | 44.696 | missing | 1956 | missing | missing | missing |
| 8 | Wallis and Futuna Islands | WLF | 1957-01-01 | 9.444 | 104.9 | 43.569 | missing | 1957 | missing | missing | missing |
| 9 | Wallis and Futuna Islands | WLF | 1958-01-01 | 9.278 | 104.9 | 42.416 | missing | 1958 | missing | missing | missing |
| 10 | Wallis and Futuna Islands | WLF | 1959-01-01 | 9.092 | 104.9 | 41.178 | missing | 1959 | missing | missing | missing |
| 11 | Wallis and Futuna Islands | WLF | 1960-01-01 | 8.899 | 104.9 | 39.751 | missing | 1960 | missing | missing | missing |
| 12 | Wallis and Futuna Islands | WLF | 1961-01-01 | 8.661 | 104.9 | 38.06 | missing | 1961 | missing | missing | missing |
| 13 | Wallis and Futuna Islands | WLF | 1962-01-01 | 8.405 | 104.9 | 36.198 | missing | 1962 | missing | missing | missing |
| 14 | Wallis and Futuna Islands | WLF | 1963-01-01 | 8.54 | 104.9 | 36.085 | missing | 1963 | missing | missing | missing |
| 15 | Wallis and Futuna Islands | WLF | 1964-01-01 | 8.703 | 104.9 | 36.127 | missing | 1964 | missing | missing | missing |
| 16 | Wallis and Futuna Islands | WLF | 1965-01-01 | 8.867 | 104.9 | 35.856 | missing | 1965 | missing | missing | missing |
| 17 | Wallis and Futuna Islands | WLF | 1966-01-01 | 8.907 | 104.9 | 38.185 | missing | 1966 | missing | missing | missing |
| 18 | Wallis and Futuna Islands | WLF | 1967-01-01 | 8.98 | 104.9 | 40.471 | missing | 1967 | missing | missing | missing |
| 19 | Wallis and Futuna Islands | WLF | 1968-01-01 | 9.084 | 104.9 | 42.714 | missing | 1968 | missing | missing | missing |
| 20 | Wallis and Futuna Islands | WLF | 1969-01-01 | 9.211 | 104.9 | 44.824 | missing | 1969 | missing | missing | missing |
| 21 | Wallis and Futuna Islands | WLF | 1970-01-01 | 9.335 | 104.9 | 44.94 | missing | 1970 | missing | missing | missing |
| 22 | Wallis and Futuna Islands | WLF | 1971-01-01 | 9.42 | 104.9 | 44.622 | missing | 1971 | missing | missing | missing |
| 23 | Wallis and Futuna Islands | WLF | 1972-01-01 | 9.5 | 104.9 | 44.432 | missing | 1972 | missing | missing | missing |
| 24 | Wallis and Futuna Islands | WLF | 1973-01-01 | 9.572 | 104.9 | 43.989 | missing | 1973 | missing | missing | missing |
| 25 | Wallis and Futuna Islands | WLF | 1974-01-01 | 9.647 | 104.9 | 41.113 | missing | 1974 | missing | missing | missing |
| 26 | Wallis and Futuna Islands | WLF | 1975-01-01 | 9.705 | 104.9 | 37.874 | missing | 1975 | missing | missing | missing |
| 27 | Wallis and Futuna Islands | WLF | 1976-01-01 | 9.742 | 104.9 | 35.417 | missing | 1976 | missing | missing | missing |
| 28 | Wallis and Futuna Islands | WLF | 1977-01-01 | 9.995 | 104.9 | 36.792 | missing | 1977 | missing | missing | missing |
| 29 | Wallis and Futuna Islands | WLF | 1978-01-01 | 10.343 | 104.9 | 38.381 | missing | 1978 | missing | missing | missing |
| 30 | Wallis and Futuna Islands | WLF | 1979-01-01 | 10.714 | 104.9 | 37.623 | missing | 1979 | missing | missing | missing |
| 31 | Wallis and Futuna Islands | WLF | 1980-01-01 | 11.104 | 104.9 | 34.685 | missing | 1980 | missing | missing | missing |
| 32 | Wallis and Futuna Islands | WLF | 1981-01-01 | 11.525 | 104.9 | 37.219 | missing | 1981 | missing | missing | missing |
| 33 | Wallis and Futuna Islands | WLF | 1982-01-01 | 11.961 | 104.9 | 34.142 | missing | 1982 | missing | missing | missing |
| 34 | Wallis and Futuna Islands | WLF | 1983-01-01 | 12.426 | 104.9 | 31.956 | missing | 1983 | missing | missing | missing |
| 35 | Wallis and Futuna Islands | WLF | 1984-01-01 | 12.596 | 104.9 | 33.335 | missing | 1984 | missing | missing | missing |
| 36 | Wallis and Futuna Islands | WLF | 1985-01-01 | 12.733 | 104.9 | 33.091 | missing | 1985 | missing | missing | missing |
| 37 | Wallis and Futuna Islands | WLF | 1986-01-01 | 12.855 | 104.9 | 34.734 | missing | 1986 | missing | missing | missing |
| 38 | Wallis and Futuna Islands | WLF | 1987-01-01 | 12.983 | 104.9 | 35.778 | missing | 1987 | missing | missing | missing |
| 39 | Wallis and Futuna Islands | WLF | 1988-01-01 | 13.11 | 104.9 | 31.309 | missing | 1988 | missing | missing | missing |
| 40 | Wallis and Futuna Islands | WLF | 1989-01-01 | 13.241 | 104.9 | 29.841 | missing | 1989 | missing | missing | missing |
| 41 | Wallis and Futuna Islands | WLF | 1990-01-01 | 13.383 | 105.0 | 30.867 | missing | 1990 | missing | missing | missing |
| 42 | Wallis and Futuna Islands | WLF | 1991-01-01 | 13.526 | 105.0 | 29.676 | missing | 1991 | missing | missing | missing |
| 43 | Wallis and Futuna Islands | WLF | 1992-01-01 | 13.671 | 105.0 | 28.113 | missing | 1992 | missing | missing | missing |
| 44 | Wallis and Futuna Islands | WLF | 1993-01-01 | 13.825 | 105.0 | 26.373 | missing | 1993 | missing | missing | missing |
| 45 | Wallis and Futuna Islands | WLF | 1994-01-01 | 13.976 | 105.0 | 24.44 | missing | 1994 | missing | missing | missing |
| 46 | Wallis and Futuna Islands | WLF | 1995-01-01 | 14.117 | 105.0 | 22.106 | missing | 1995 | missing | missing | missing |
| 47 | Wallis and Futuna Islands | WLF | 1996-01-01 | 14.242 | 104.9 | 20.419 | missing | 1996 | missing | missing | missing |
| 48 | Wallis and Futuna Islands | WLF | 1997-01-01 | 14.341 | 104.9 | 22.778 | missing | 1997 | missing | missing | missing |
| 49 | Wallis and Futuna Islands | WLF | 1998-01-01 | 14.439 | 104.9 | 19.423 | missing | 1998 | missing | missing | missing |
| 50 | Wallis and Futuna Islands | WLF | 1999-01-01 | 14.541 | 104.8 | 18.943 | missing | 1999 | missing | missing | missing |
| 51 | Wallis and Futuna Islands | WLF | 2000-01-01 | 14.66 | 104.8 | 18.862 | missing | 2000 | missing | missing | missing |
| 52 | Wallis and Futuna Islands | WLF | 2001-01-01 | 14.786 | 104.8 | 18.862 | missing | 2001 | missing | missing | missing |
| 53 | Wallis and Futuna Islands | WLF | 2002-01-01 | 14.919 | 104.8 | 17.228 | missing | 2002 | missing | missing | missing |
| 54 | Wallis and Futuna Islands | WLF | 2003-01-01 | 15.057 | 104.9 | 16.192 | missing | 2003 | missing | missing | missing |
| 55 | Wallis and Futuna Islands | WLF | 2004-01-01 | 15.006 | 104.9 | 15.477 | missing | 2004 | missing | missing | missing |
| 56 | Wallis and Futuna Islands | WLF | 2005-01-01 | 14.7 | 105.0 | 14.966 | missing | 2005 | missing | missing | missing |
| 57 | Wallis and Futuna Islands | WLF | 2006-01-01 | 14.405 | 105.1 | 13.926 | missing | 2006 | missing | missing | missing |
| 58 | Wallis and Futuna Islands | WLF | 2007-01-01 | 14.115 | 105.1 | 13.678 | missing | 2007 | missing | missing | missing |
| 59 | Wallis and Futuna Islands | WLF | 2008-01-01 | 13.813 | 105.1 | 12.243 | missing | 2008 | missing | missing | missing |
| 60 | Wallis and Futuna Islands | WLF | 2009-01-01 | 13.518 | 105.1 | 13.087 | missing | 2009 | missing | missing | missing |
| 61 | Wallis and Futuna Islands | WLF | 2010-01-01 | 13.265 | 105.1 | 14.372 | missing | 2010 | missing | missing | missing |
| 62 | Wallis and Futuna Islands | WLF | 2011-01-01 | 13.018 | 105.0 | 14.443 | missing | 2011 | missing | missing | missing |
| 63 | Wallis and Futuna Islands | WLF | 2012-01-01 | 12.782 | 105.0 | 14.098 | missing | 2012 | missing | missing | missing |
| 64 | Wallis and Futuna Islands | WLF | 2013-01-01 | 12.56 | 104.9 | 13.539 | missing | 2013 | missing | missing | missing |
| 65 | Wallis and Futuna Islands | WLF | 2014-01-01 | 12.369 | 104.9 | 13.133 | missing | 2014 | missing | missing | missing |
| 66 | Wallis and Futuna Islands | WLF | 2015-01-01 | 12.246 | 104.8 | 13.012 | missing | 2015 | missing | missing | missing |
| 67 | Wallis and Futuna Islands | WLF | 2016-01-01 | 12.119 | 104.8 | 12.932 | missing | 2016 | missing | missing | missing |
| 68 | Wallis and Futuna Islands | WLF | 2017-01-01 | 12.002 | 104.8 | 12.713 | missing | 2017 | missing | missing | missing |
| 69 | Wallis and Futuna Islands | WLF | 2018-01-01 | 11.87 | 104.8 | 12.381 | missing | 2018 | missing | missing | missing |
| 70 | Wallis and Futuna Islands | WLF | 2019-01-01 | 11.761 | 104.8 | 12.189 | missing | 2019 | missing | missing | missing |
| 71 | Wallis and Futuna Islands | WLF | 2020-01-01 | 11.667 | 104.8 | 11.997 | missing | 2020 | missing | missing | missing |
| 72 | Wallis and Futuna Islands | WLF | 2021-01-01 | 11.642 | 104.8 | 11.816 | missing | 2021 | missing | missing | missing |
filtering to only include countries with events defined,
countries_with_events = filter(sdf -> !(all(ismissing.(sdf.intyear_es))), country_data)GroupedDataFrame with 15 groups based on key: country
| Row | country | iso_code | year | totpop | sex_rat | birthrate | intyear | year_es | intyear_es | agrigdp_rat | gender_inequality_index |
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | String3 | Date | Float64 | Float64 | Float64 | Date | Int64 | Int64? | Float64? | Float64? | |
| 1 | Libya | LBY | 1950-01-01 | 1125.23 | 105.7 | 46.972 | 1986-01-01 | 1950 | 1986 | missing | missing |
| 2 | Libya | LBY | 1951-01-01 | 1136.12 | 105.7 | 47.104 | 1986-01-01 | 1951 | 1986 | missing | missing |
| 3 | Libya | LBY | 1952-01-01 | 1149.58 | 105.7 | 47.298 | 1986-01-01 | 1952 | 1986 | missing | missing |
| 4 | Libya | LBY | 1953-01-01 | 1165.82 | 105.7 | 47.938 | 1986-01-01 | 1953 | 1986 | missing | missing |
| 5 | Libya | LBY | 1954-01-01 | 1185.9 | 105.6 | 48.407 | 1986-01-01 | 1954 | 1986 | missing | missing |
| 6 | Libya | LBY | 1955-01-01 | 1209.79 | 105.6 | 48.934 | 1986-01-01 | 1955 | 1986 | missing | missing |
| 7 | Libya | LBY | 1956-01-01 | 1241.58 | 105.6 | 49.439 | 1986-01-01 | 1956 | 1986 | missing | missing |
| 8 | Libya | LBY | 1957-01-01 | 1276.48 | 105.6 | 49.878 | 1986-01-01 | 1957 | 1986 | missing | missing |
| 9 | Libya | LBY | 1958-01-01 | 1314.72 | 105.6 | 50.211 | 1986-01-01 | 1958 | 1986 | missing | missing |
| 10 | Libya | LBY | 1959-01-01 | 1356.6 | 105.6 | 50.306 | 1986-01-01 | 1959 | 1986 | missing | missing |
| 11 | Libya | LBY | 1960-01-01 | 1402.21 | 105.6 | 50.463 | 1986-01-01 | 1960 | 1986 | missing | missing |
| 12 | Libya | LBY | 1961-01-01 | 1451.76 | 105.5 | 50.733 | 1986-01-01 | 1961 | 1986 | missing | missing |
| 13 | Libya | LBY | 1962-01-01 | 1505.76 | 105.5 | 51.125 | 1986-01-01 | 1962 | 1986 | missing | missing |
| 14 | Libya | LBY | 1963-01-01 | 1564.55 | 105.5 | 51.691 | 1986-01-01 | 1963 | 1986 | missing | missing |
| 15 | Libya | LBY | 1964-01-01 | 1624.96 | 105.4 | 51.962 | 1986-01-01 | 1964 | 1986 | missing | missing |
| 16 | Libya | LBY | 1965-01-01 | 1679.24 | 105.4 | 51.922 | 1986-01-01 | 1965 | 1986 | missing | missing |
| 17 | Libya | LBY | 1966-01-01 | 1720.9 | 105.3 | 51.194 | 1986-01-01 | 1966 | 1986 | missing | missing |
| 18 | Libya | LBY | 1967-01-01 | 1758.76 | 105.2 | 49.918 | 1986-01-01 | 1967 | 1986 | missing | missing |
| 19 | Libya | LBY | 1968-01-01 | 1798.4 | 105.2 | 48.643 | 1986-01-01 | 1968 | 1986 | missing | missing |
| 20 | Libya | LBY | 1969-01-01 | 1840.39 | 105.1 | 47.503 | 1986-01-01 | 1969 | 1986 | missing | missing |
| 21 | Libya | LBY | 1970-01-01 | 1885.26 | 105.0 | 46.404 | 1986-01-01 | 1970 | 1986 | missing | missing |
| 22 | Libya | LBY | 1971-01-01 | 1933.1 | 104.9 | 45.479 | 1986-01-01 | 1971 | 1986 | missing | missing |
| 23 | Libya | LBY | 1972-01-01 | 1983.54 | 104.8 | 44.263 | 1986-01-01 | 1972 | 1986 | missing | missing |
| 24 | Libya | LBY | 1973-01-01 | 2042.05 | 104.8 | 43.392 | 1986-01-01 | 1973 | 1986 | missing | missing |
| 25 | Libya | LBY | 1974-01-01 | 2126.46 | 104.9 | 43.349 | 1986-01-01 | 1974 | 1986 | missing | missing |
| 26 | Libya | LBY | 1975-01-01 | 2232.43 | 104.6 | 42.581 | 1986-01-01 | 1975 | 1986 | missing | missing |
| 27 | Libya | LBY | 1976-01-01 | 2351.25 | 104.3 | 41.89 | 1986-01-01 | 1976 | 1986 | missing | missing |
| 28 | Libya | LBY | 1977-01-01 | 2476.27 | 104.0 | 41.254 | 1986-01-01 | 1977 | 1986 | missing | missing |
| 29 | Libya | LBY | 1978-01-01 | 2607.34 | 103.9 | 40.698 | 1986-01-01 | 1978 | 1986 | missing | missing |
| 30 | Libya | LBY | 1979-01-01 | 2744.89 | 104.2 | 40.142 | 1986-01-01 | 1979 | 1986 | missing | missing |
| 31 | Libya | LBY | 1980-01-01 | 2888.94 | 104.7 | 38.545 | 1986-01-01 | 1980 | 1986 | missing | missing |
| 32 | Libya | LBY | 1981-01-01 | 3036.5 | 105.0 | 37.128 | 1986-01-01 | 1981 | 1986 | missing | missing |
| 33 | Libya | LBY | 1982-01-01 | 3187.53 | 105.1 | 36.338 | 1986-01-01 | 1982 | 1986 | missing | missing |
| 34 | Libya | LBY | 1983-01-01 | 3343.38 | 105.2 | 35.551 | 1986-01-01 | 1983 | 1986 | missing | missing |
| 35 | Libya | LBY | 1984-01-01 | 3503.8 | 105.3 | 34.792 | 1986-01-01 | 1984 | 1986 | missing | missing |
| 36 | Libya | LBY | 1985-01-01 | 3625.29 | 105.6 | 34.357 | 1986-01-01 | 1985 | 1986 | missing | missing |
| 37 | Libya | LBY | 1986-01-01 | 3743.34 | 105.8 | 33.681 | 1986-01-01 | 1986 | 1986 | missing | missing |
| 38 | Libya | LBY | 1987-01-01 | 3856.88 | 106.1 | 32.852 | 1986-01-01 | 1987 | 1986 | missing | missing |
| 39 | Libya | LBY | 1988-01-01 | 3967.0 | 106.2 | 31.851 | 1986-01-01 | 1988 | 1986 | missing | missing |
| 40 | Libya | LBY | 1989-01-01 | 4076.13 | 106.2 | 30.695 | 1986-01-01 | 1989 | 1986 | missing | missing |
| 41 | Libya | LBY | 1990-01-01 | 4183.95 | 106.1 | 29.479 | 1986-01-01 | 1990 | 1986 | missing | missing |
| 42 | Libya | LBY | 1991-01-01 | 4290.02 | 106.3 | 28.253 | 1986-01-01 | 1991 | 1986 | missing | missing |
| 43 | Libya | LBY | 1992-01-01 | 4393.93 | 106.7 | 27.111 | 1986-01-01 | 1992 | 1986 | missing | missing |
| 44 | Libya | LBY | 1993-01-01 | 4495.71 | 107.3 | 25.933 | 1986-01-01 | 1993 | 1986 | missing | missing |
| 45 | Libya | LBY | 1994-01-01 | 4594.23 | 107.6 | 24.944 | 1986-01-01 | 1994 | 1986 | missing | missing |
| 46 | Libya | LBY | 1995-01-01 | 4688.37 | 107.4 | 24.148 | 1986-01-01 | 1995 | 1986 | missing | missing |
| 47 | Libya | LBY | 1996-01-01 | 4777.76 | 107.3 | 23.478 | 1986-01-01 | 1996 | 1986 | missing | missing |
| 48 | Libya | LBY | 1997-01-01 | 4862.37 | 107.2 | 22.813 | 1986-01-01 | 1997 | 1986 | missing | missing |
| 49 | Libya | LBY | 1998-01-01 | 4942.32 | 107.1 | 22.188 | 1986-01-01 | 1998 | 1986 | missing | missing |
| 50 | Libya | LBY | 1999-01-01 | 5019.61 | 107.0 | 21.649 | 1986-01-01 | 1999 | 1986 | missing | missing |
| 51 | Libya | LBY | 2000-01-01 | 5096.39 | 107.0 | 21.195 | 1986-01-01 | 2000 | 1986 | missing | missing |
| 52 | Libya | LBY | 2001-01-01 | 5213.19 | 107.1 | 22.611 | 1986-01-01 | 2001 | 1986 | missing | missing |
| 53 | Libya | LBY | 2002-01-01 | 5338.64 | 107.2 | 22.811 | 1986-01-01 | 2002 | 1986 | 5.1853 | missing |
| 54 | Libya | LBY | 2003-01-01 | 5472.01 | 107.2 | 23.052 | 1986-01-01 | 2003 | 1986 | 4.09221 | missing |
| 55 | Libya | LBY | 2004-01-01 | 5613.27 | 107.3 | 23.338 | 1986-01-01 | 2004 | 1986 | 3.34262 | missing |
| 56 | Libya | LBY | 2005-01-01 | 5761.85 | 107.4 | 23.648 | 1986-01-01 | 2005 | 1986 | 2.51001 | 0.325 |
| 57 | Libya | LBY | 2006-01-01 | 5914.12 | 107.4 | 23.771 | 1986-01-01 | 2006 | 1986 | 1.51764 | 0.286 |
| 58 | Libya | LBY | 2007-01-01 | 6032.62 | 106.6 | 23.623 | 1986-01-01 | 2007 | 1986 | 1.54142 | 0.28 |
| 59 | Libya | LBY | 2008-01-01 | 6161.73 | 106.0 | 23.391 | 1986-01-01 | 2008 | 1986 | 1.38365 | 0.276 |
| 60 | Libya | LBY | 2009-01-01 | 6295.01 | 105.7 | 23.126 | 1986-01-01 | 2009 | 1986 | 2.15807 | 0.275 |
| 61 | Libya | LBY | 2010-01-01 | 6425.38 | 105.7 | 23.562 | 1986-01-01 | 2010 | 1986 | 1.79953 | 0.28 |
| 62 | Libya | LBY | 2011-01-01 | 6558.6 | 105.7 | 23.885 | 1986-01-01 | 2011 | 1986 | 3.05767 | 0.289 |
| 63 | Libya | LBY | 2012-01-01 | 5817.66 | 105.7 | 21.953 | 1986-01-01 | 2012 | 1986 | 1.81559 | 0.243 |
| 64 | Libya | LBY | 2013-01-01 | 5922.08 | 105.7 | 21.886 | 1986-01-01 | 2013 | 1986 | 2.41549 | 0.252 |
| 65 | Libya | LBY | 2014-01-01 | 6048.36 | 105.7 | 21.908 | 1986-01-01 | 2014 | 1986 | 3.51668 | 0.26 |
| 66 | Libya | LBY | 2015-01-01 | 6147.16 | 105.7 | 21.214 | 1986-01-01 | 2015 | 1986 | 4.3863 | 0.267 |
| 67 | Libya | LBY | 2016-01-01 | 6237.31 | 105.7 | 20.576 | 1986-01-01 | 2016 | 1986 | 4.61178 | 0.268 |
| 68 | Libya | LBY | 2017-01-01 | 6327.09 | 105.7 | 19.898 | 1986-01-01 | 2017 | 1986 | 3.87478 | 0.264 |
| 69 | Libya | LBY | 2018-01-01 | 6429.44 | 105.7 | 19.282 | 1986-01-01 | 2018 | 1986 | 3.66013 | 0.262 |
| 70 | Libya | LBY | 2019-01-01 | 6526.15 | 105.7 | 18.732 | 1986-01-01 | 2019 | 1986 | 4.08879 | 0.26 |
| 71 | Libya | LBY | 2020-01-01 | 6612.03 | 105.7 | 18.302 | 1986-01-01 | 2020 | 1986 | missing | 0.259 |
| 72 | Libya | LBY | 2021-01-01 | 6695.86 | 105.7 | 17.828 | 1986-01-01 | 2021 | 1986 | missing | 0.259 |
⋮
| Row | country | iso_code | year | totpop | sex_rat | birthrate | intyear | year_es | intyear_es | agrigdp_rat | gender_inequality_index |
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | String3 | Date | Float64 | Float64 | Float64 | Date | Int64 | Int64? | Float64? | Float64? | |
| 1 | Cuba | CUB | 1950-01-01 | 5865.9 | 106.5 | 31.975 | 1990-01-01 | 1950 | 1990 | missing | missing |
| 2 | Cuba | CUB | 1951-01-01 | 5987.39 | 106.5 | 31.313 | 1990-01-01 | 1951 | 1990 | missing | missing |
| 3 | Cuba | CUB | 1952-01-01 | 6108.43 | 106.5 | 31.202 | 1990-01-01 | 1952 | 1990 | missing | missing |
| 4 | Cuba | CUB | 1953-01-01 | 6232.76 | 106.4 | 31.166 | 1990-01-01 | 1953 | 1990 | missing | missing |
| 5 | Cuba | CUB | 1954-01-01 | 6360.72 | 106.4 | 31.151 | 1990-01-01 | 1954 | 1990 | missing | missing |
| 6 | Cuba | CUB | 1955-01-01 | 6492.32 | 106.4 | 31.077 | 1990-01-01 | 1955 | 1990 | missing | missing |
| 7 | Cuba | CUB | 1956-01-01 | 6626.85 | 106.3 | 31.039 | 1990-01-01 | 1956 | 1990 | missing | missing |
| 8 | Cuba | CUB | 1957-01-01 | 6763.9 | 106.3 | 31.003 | 1990-01-01 | 1957 | 1990 | missing | missing |
| 9 | Cuba | CUB | 1958-01-01 | 6903.61 | 106.3 | 31.091 | 1990-01-01 | 1958 | 1990 | missing | missing |
| 10 | Cuba | CUB | 1959-01-01 | 7046.13 | 106.2 | 31.793 | 1990-01-01 | 1959 | 1990 | missing | missing |
| 11 | Cuba | CUB | 1960-01-01 | 7192.57 | 106.1 | 32.664 | 1990-01-01 | 1960 | 1990 | missing | missing |
| 12 | Cuba | CUB | 1961-01-01 | 7342.22 | 106.0 | 33.52 | 1990-01-01 | 1961 | 1990 | missing | missing |
| 13 | Cuba | CUB | 1962-01-01 | 7494.82 | 105.9 | 34.443 | 1990-01-01 | 1962 | 1990 | missing | missing |
| 14 | Cuba | CUB | 1963-01-01 | 7653.71 | 105.8 | 35.189 | 1990-01-01 | 1963 | 1990 | missing | missing |
| 15 | Cuba | CUB | 1964-01-01 | 7818.99 | 105.8 | 34.69 | 1990-01-01 | 1964 | 1990 | missing | missing |
| 16 | Cuba | CUB | 1965-01-01 | 7985.58 | 105.7 | 33.933 | 1990-01-01 | 1965 | 1990 | missing | missing |
| 17 | Cuba | CUB | 1966-01-01 | 8149.72 | 105.8 | 33.129 | 1990-01-01 | 1966 | 1990 | missing | missing |
| 18 | Cuba | CUB | 1967-01-01 | 8311.17 | 105.8 | 32.362 | 1990-01-01 | 1967 | 1990 | missing | missing |
| 19 | Cuba | CUB | 1968-01-01 | 8470.75 | 105.8 | 31.644 | 1990-01-01 | 1968 | 1990 | missing | missing |
| 20 | Cuba | CUB | 1969-01-01 | 8629.82 | 105.9 | 30.86 | 1990-01-01 | 1969 | 1990 | missing | missing |
| 21 | Cuba | CUB | 1970-01-01 | 8789.49 | 105.9 | 29.966 | 1990-01-01 | 1970 | 1990 | 12.1214 | missing |
| 22 | Cuba | CUB | 1971-01-01 | 8949.78 | 105.9 | 29.008 | 1990-01-01 | 1971 | 1990 | 12.119 | missing |
| 23 | Cuba | CUB | 1972-01-01 | 9101.63 | 105.9 | 27.96 | 1990-01-01 | 1972 | 1990 | 12.1189 | missing |
| 24 | Cuba | CUB | 1973-01-01 | 9236.94 | 105.9 | 26.351 | 1990-01-01 | 1973 | 1990 | 12.1232 | missing |
| 25 | Cuba | CUB | 1974-01-01 | 9358.9 | 105.8 | 24.31 | 1990-01-01 | 1974 | 1990 | 12.1326 | missing |
| 26 | Cuba | CUB | 1975-01-01 | 9467.31 | 105.8 | 21.89 | 1990-01-01 | 1975 | 1990 | 12.113 | missing |
| 27 | Cuba | CUB | 1976-01-01 | 9561.3 | 106.0 | 19.529 | 1990-01-01 | 1976 | 1990 | 12.1075 | missing |
| 28 | Cuba | CUB | 1977-01-01 | 9640.42 | 106.1 | 17.364 | 1990-01-01 | 1977 | 1990 | 12.1183 | missing |
| 29 | Cuba | CUB | 1978-01-01 | 9704.67 | 106.2 | 15.078 | 1990-01-01 | 1978 | 1990 | 12.1449 | missing |
| 30 | Cuba | CUB | 1979-01-01 | 9755.3 | 106.2 | 14.447 | 1990-01-01 | 1979 | 1990 | 12.1794 | missing |
| 31 | Cuba | CUB | 1980-01-01 | 9794.12 | 106.3 | 13.706 | 1990-01-01 | 1980 | 1990 | 12.015 | missing |
| 32 | Cuba | CUB | 1981-01-01 | 9824.1 | 106.3 | 13.649 | 1990-01-01 | 1981 | 1990 | 12.0798 | missing |
| 33 | Cuba | CUB | 1982-01-01 | 9873.02 | 106.4 | 15.734 | 1990-01-01 | 1982 | 1990 | 12.1723 | missing |
| 34 | Cuba | CUB | 1983-01-01 | 9944.72 | 106.5 | 16.355 | 1990-01-01 | 1983 | 1990 | 12.2779 | missing |
| 35 | Cuba | CUB | 1984-01-01 | 10024.5 | 106.5 | 16.432 | 1990-01-01 | 1984 | 1990 | 12.3518 | missing |
| 36 | Cuba | CUB | 1985-01-01 | 10106.6 | 106.6 | 16.559 | 1990-01-01 | 1985 | 1990 | 11.193 | missing |
| 37 | Cuba | CUB | 1986-01-01 | 10191.5 | 106.9 | 16.749 | 1990-01-01 | 1986 | 1990 | 12.4041 | missing |
| 38 | Cuba | CUB | 1987-01-01 | 10279.5 | 107.5 | 17.305 | 1990-01-01 | 1987 | 1990 | 12.6348 | missing |
| 39 | Cuba | CUB | 1988-01-01 | 10374.3 | 108.0 | 17.915 | 1990-01-01 | 1988 | 1990 | 12.8059 | missing |
| 40 | Cuba | CUB | 1989-01-01 | 10476.5 | 108.3 | 17.744 | 1990-01-01 | 1989 | 1990 | 12.721 | missing |
| 41 | Cuba | CUB | 1990-01-01 | 10577.8 | 108.5 | 17.48 | 1990-01-01 | 1990 | 1990 | 13.0405 | 0.439 |
| 42 | Cuba | CUB | 1991-01-01 | 10675.5 | 108.8 | 16.033 | 1990-01-01 | 1991 | 1990 | 12.7759 | 0.432 |
| 43 | Cuba | CUB | 1992-01-01 | 10752.1 | 109.2 | 14.977 | 1990-01-01 | 1992 | 1990 | 12.4266 | 0.434 |
| 44 | Cuba | CUB | 1993-01-01 | 10815.4 | 109.5 | 14.147 | 1990-01-01 | 1993 | 1990 | 9.57115 | 0.43 |
| 45 | Cuba | CUB | 1994-01-01 | 10866.5 | 110.0 | 13.572 | 1990-01-01 | 1994 | 1990 | 7.89981 | 0.427 |
| 46 | Cuba | CUB | 1995-01-01 | 10907.9 | 110.9 | 13.374 | 1990-01-01 | 1995 | 1990 | 6.8833 | 0.421 |
| 47 | Cuba | CUB | 1996-01-01 | 10945.5 | 111.1 | 12.799 | 1990-01-01 | 1996 | 1990 | 7.13344 | 0.408 |
| 48 | Cuba | CUB | 1997-01-01 | 10980.6 | 110.2 | 13.578 | 1990-01-01 | 1997 | 1990 | 7.18681 | 0.403 |
| 49 | Cuba | CUB | 1998-01-01 | 11015.7 | 109.3 | 13.444 | 1990-01-01 | 1998 | 1990 | 6.11742 | 0.386 |
| 50 | Cuba | CUB | 1999-01-01 | 11051.9 | 108.5 | 13.287 | 1990-01-01 | 1999 | 1990 | 6.12418 | 0.378 |
| 51 | Cuba | CUB | 2000-01-01 | 11088.3 | 107.9 | 12.628 | 1990-01-01 | 2000 | 1990 | 6.60126 | 0.369 |
| 52 | Cuba | CUB | 2001-01-01 | 11123.2 | 107.2 | 12.171 | 1990-01-01 | 2001 | 1990 | 6.37957 | 0.363 |
| 53 | Cuba | CUB | 2002-01-01 | 11155.0 | 106.9 | 12.262 | 1990-01-01 | 2002 | 1990 | 5.94573 | 0.358 |
| 54 | Cuba | CUB | 2003-01-01 | 11185.1 | 106.8 | 11.829 | 1990-01-01 | 2003 | 1990 | 5.74521 | 0.338 |
| 55 | Cuba | CUB | 2004-01-01 | 11213.3 | 106.7 | 11.031 | 1990-01-01 | 2004 | 1990 | 5.47444 | 0.332 |
| 56 | Cuba | CUB | 2005-01-01 | 11237.3 | 106.7 | 10.446 | 1990-01-01 | 2005 | 1990 | 4.36365 | 0.328 |
| 57 | Cuba | CUB | 2006-01-01 | 11255.0 | 106.7 | 9.752 | 1990-01-01 | 2006 | 1990 | 3.40501 | 0.315 |
| 58 | Cuba | CUB | 2007-01-01 | 11266.3 | 106.7 | 9.921 | 1990-01-01 | 2007 | 1990 | 3.9081 | 0.321 |
| 59 | Cuba | CUB | 2008-01-01 | 11273.5 | 106.7 | 10.83 | 1990-01-01 | 2008 | 1990 | 3.81704 | 0.325 |
| 60 | Cuba | CUB | 2009-01-01 | 11279.7 | 106.7 | 11.487 | 1990-01-01 | 2009 | 1990 | 3.93041 | 0.33 |
| 61 | Cuba | CUB | 2010-01-01 | 11286.6 | 106.6 | 11.417 | 1990-01-01 | 2010 | 1990 | 3.61429 | 0.333 |
| 62 | Cuba | CUB | 2011-01-01 | 11294.2 | 106.7 | 11.76 | 1990-01-01 | 2011 | 1990 | 3.60487 | 0.329 |
| 63 | Cuba | CUB | 2012-01-01 | 11303.2 | 106.9 | 11.191 | 1990-01-01 | 2012 | 1990 | 3.8501 | 0.323 |
| 64 | Cuba | CUB | 2013-01-01 | 11315.4 | 107.2 | 11.122 | 1990-01-01 | 2013 | 1990 | 3.92492 | 0.318 |
| 65 | Cuba | CUB | 2014-01-01 | 11327.8 | 107.3 | 10.86 | 1990-01-01 | 2014 | 1990 | 3.93771 | 0.313 |
| 66 | Cuba | CUB | 2015-01-01 | 11336.2 | 107.5 | 10.972 | 1990-01-01 | 2015 | 1990 | 3.83552 | 0.312 |
| 67 | Cuba | CUB | 2016-01-01 | 11343.5 | 107.7 | 10.351 | 1990-01-01 | 2016 | 1990 | 3.93893 | 0.309 |
| 68 | Cuba | CUB | 2017-01-01 | 11340.5 | 107.7 | 10.182 | 1990-01-01 | 2017 | 1990 | 3.80068 | 0.31 |
| 69 | Cuba | CUB | 2018-01-01 | 11332.3 | 107.6 | 10.348 | 1990-01-01 | 2018 | 1990 | 3.78311 | 0.309 |
| 70 | Cuba | CUB | 2019-01-01 | 11324.2 | 107.5 | 9.752 | 1990-01-01 | 2019 | 1990 | 3.5677 | 0.307 |
| 71 | Cuba | CUB | 2020-01-01 | 11309.2 | 107.3 | 9.344 | 1990-01-01 | 2020 | 1990 | 2.76194 | 0.307 |
| 72 | Cuba | CUB | 2021-01-01 | 11292.2 | 107.3 | 8.922 | 1990-01-01 | 2021 | 1990 | 0.881941 | 0.303 |
and finally, creating a TSFrame with the sex_rat variable for each country.
relevant_country_ts = TSFrames.join((TSFrame(DataFrame([:Index => sdf.year_es, Symbol(sdf.country[1]) => sdf.sex_rat])) for sdf in countries_with_events)...; jointype = :JoinInner)72×15 TSFrame with Int64 Index
Index Libya China China, Hong Kong SAR China, Taiwan Province of Chin ⋯
Int64 Float64 Float64 Float64 Float64 ⋯
────────────────────────────────────────────────────────────────────────────────
1950 105.7 106.1 109.8 105. ⋯
1951 105.7 106.1 109.7 105.
1952 105.7 106.1 109.4 105.
1953 105.7 106.1 109.2 105.
1954 105.6 106.1 108.9 105. ⋯
1955 105.6 106.1 108.9 105.
1956 105.6 106.1 108.3 105.
1957 105.6 106.1 109.0 105.
⋮ ⋮ ⋮ ⋮ ⋮ ⋱
2015 105.7 115.0 107.6 107. ⋯
2016 105.7 114.5 107.6 107.
2017 105.7 114.0 107.6 107.
2018 105.7 113.4 107.7 107.
2019 105.7 112.9 107.7 107. ⋯
2020 105.7 112.3 107.7 107.
2021 105.7 111.8 107.7 107.
12 columns and 57 rows omittedCreate a mapping from country to event time, for each event.
Note that this can have multiple events per country.
event_times = [Symbol(sdf.country[1]) => sdf.intyear_es[findfirst(!ismissing, sdf.intyear_es)] for sdf in countries_with_events]15-element Vector{Pair{Symbol, Int64}}:
:Libya => 1986
:China => 1983
Symbol("China, Hong Kong SAR") => 1998
Symbol("China, Taiwan Province of China") => 1974
Symbol("Republic of Korea") => 1974
:India => 1972
:Pakistan => 1973
Symbol("Viet Nam") => 1999
:Armenia => 1991
:Azerbaijan => 1991
:Georgia => 1991
Symbol("Russian Federation") => 1985
:Albania => 1991
:Spain => 1975
:Cuba => 1990Convert to event time using EventStudies.jl (perform the event study).
eventtime_ts, retcodes = EventStudies.eventstudy(levels_to_returns(relevant_country_ts), event_times, 4)(9×15 TSFrame with Int64 Index
Index Libya China China, Hong Kong SAR China, Taiwan Province of ⋯
Int64 Float64 Float64 Float64 Float64 ⋯
────────────────────────────────────────────────────────────────────────────────
-4 0.0951928 0.0935016 0.371402 -0.1 ⋯
-3 0.0951022 0.0934143 -0.0927214 -0.0
-2 0.0950119 0.186567 0.0 -0.0
-1 0.284495 0.18622 0.46275 0.3
0 0.189215 0.278681 0.276625 0.0 ⋯
1 0.283153 0.277907 0.0 -0.2
2 0.0942063 0.461468 0.0920387 0.0
3 0.0 0.459349 -0.276371 0.1
4 -0.0942063 0.548447 -0.277136 0.4 ⋯
12 columns omitted, EventStudies.EventStatus[EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success()])Perform bootstrap inference with a 95% confidence interval
t0, lower, upper = inference(BootstrapInference(), eventtime_ts, 0.95)([0.08750559901358794, 0.05639795220573044, 0.037076052234521484, 0.14915962548207298, 0.2053603997918548, 0.08716474148950344, 0.30419233442415816, 0.27634298013774483, 0.3610686693636171], [0.012666142999793852, -0.04002900293414792, -0.03142136506890333, 0.04800203081096841, 0.09961761892883336, -0.08669979665881751, 0.13652946052636983, 0.06262873187748971, 0.15695636073234576], [0.16239711651013033, 0.1561040473290407, 0.1361553928509711, 0.25479841834865685, 0.3555889811206953, 0.24829626602792015, 0.5212877911822056, 0.5702681228666144, 0.5940640931676833])we're technically done with the event study here!
now, it's time to plot plot each variable in the event study
fig, ax, plt = series(
index(eventtime_ts), Matrix(remap_cumsum(eventtime_ts))';
labels = names(eventtime_ts),
color = Makie.resample_cmap(:rainbow_bgyrm_35_85_c71_n256, 15),
linewidth = 3,
axis = (
xlabel = "Years relative to event",
xticks = WilkinsonTicks(8, k_min = 8, k_max = 8),
ylabel = "Cumulative change\nin sex ratio (%)",
title = "Variable: sex ratio at birth",
subtitle = "Event: some legislation",
titlealign = :left,
),
figure = (resolution = (1000, 1000),)
)
leg = Legend(fig[2, 1], ax; nbanks = 3, tellwidth = false, tellheight = true)
figplot inference
fig, ax, mean_plt = lines(
index(eventtime_ts), t0;
label = "Mean",
linewidth = 3,
axis = (
xlabel = "Years relative to event",
xticks = WilkinsonTicks(8, k_min = 8, k_max = 8),
ylabel = "Cumulative change\nin sex ratio (%)",
title = "Variable: sex ratio at birth",
subtitle = "Event: some legislation",
titlealign = :left,
),
)
band_plt = band!(ax,
index(eventtime_ts), lower, upper;
label = "95% CI",
linewidth = 3,
color = Makie.wong_colors(0.5)[2],
)
leg = axislegend(ax, position = :lt)
figplot inference using errorbars
fig, ax, plt = rangebars(
index(eventtime_ts),
lower, upper;
whiskerwidth = 16,
label = "95% CI",
axis = (
xlabel = "Years relative to event",
xticks = WilkinsonTicks(8, k_min = 8, k_max = 8),
ylabel = "Cumulative change\nin sex ratio (%)",
title = "Variable: sex ratio at birth",
subtitle = "Event: some legislation",
titlealign = :left,
),
)
scatter!(ax, index(eventtime_ts), t0; label = "Mean value")Scatter{Tuple{Vector{Point{2, Float32}}}}small hack for a feature which we should add into Makie
function Makie.legendelements(plot::Rangebars, legend)
line_points = lift(plot.whiskerwidth) do ww
if ww ≤ 3
Point2f[(0.5, 1), (0.5, 0)]
else
Point2f[(0.25, 1), (0.75, 1), (NaN, NaN), (0.5, 1), (0.5, 0), (NaN, NaN), (0.25, 0), (0.75, 0)]
end
end
return Makie.LegendElement[
LineElement(
points = line_points,
color = Makie.scalar_lift(plot.color, legend.linecolor),
linewidth = Makie.scalar_lift(plot.linewidth, legend.linewidth)
),
]
end
axislegend(ax, position = :lt)
figreplicate eventstudies.R results
convert to event time
eventtime_ts, retcodes = EventStudies.eventstudy(levels_to_returns(relevant_country_ts), event_times, -2:3)(6×15 TSFrame with Int64 Index
Index Libya China China, Hong Kong SAR China, Taiwan Province of C ⋯
Int64 Float64 Float64 Float64 Float64 ⋯
────────────────────────────────────────────────────────────────────────────────
-2 0.0950119 0.186567 0.0 -0.094 ⋯
-1 0.284495 0.18622 0.46275 0.375
0 0.189215 0.278681 0.276625 0.0
1 0.283153 0.277907 0.0 -0.281
2 0.0942063 0.461468 0.0920387 0.094 ⋯
3 0.0 0.459349 -0.276371 0.187
12 columns omitted, EventStudies.EventStatus[EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success(), EventStudies.Success()])perform inference with a 95% confidence interval
t0, lower, upper = inference(BootstrapInference(), eventtime_ts, 0.95)([0.037076052234521484, 0.14915962548207298, 0.2053603997918548, 0.08716474148950344, 0.30419233442415816, 0.27634298013774483], [-0.0315635911707958, 0.03701683035704321, 0.09358506164096725, -0.0749783996219527, 0.13618171162839152, 0.04323068287054096], [0.12989470094049999, 0.2497554490344732, 0.34647341283161553, 0.24032409540363, 0.5209548982132289, 0.5761557157510687])we're technically done with the event study here!
plot inference
fig, ax, mean_plt = lines(
index(eventtime_ts), t0;
label = "Mean",
linewidth = 3,
axis = (
xlabel = "Years relative to event",
xticks = WilkinsonTicks(8, k_min = 8, k_max = 8),
ylabel = "Cumulative change\nin sex ratio (%)",
title = "Variable: sex ratio at birth",
subtitle = "Event: some legislation",
titlealign = :left,
),
)
band_plt = band!(ax,
index(eventtime_ts), lower, upper;
label = "95% CI",
linewidth = 3,
color = Makie.wong_colors(0.5)[2],
)
leg = axislegend(ax, position = :lt)
ylims!(ax, -0.75, 0.75) # match R
ylims!(ax, -0.5, 0.5) # match R
figThis page was generated using Literate.jl.