<jupyter_start><jupyter_text>Average Number of Years Lost For People Who Died of Coronavirus in ChinaWe illustrate the use of the package by estimating the average number of years by which people's lives are shortened due to coronavirus. Using data from [Table 1 of the paper](http://weekly.chinacdc.cn/en/article/id/e53946e2-c6c4-41e9-9a9b-fea8db1a8f51>) that gives us the distribution of ages of people who died from COVID-19 in China, with conservative assumptions (assuming gender of the dead person to be male, taking the middle of age ranges) we find that people's lives are shortened by about 11 years on average. These estimates are conservative for one additional reason: there is likely an inverse correlation between people who die and their expected longevity. And note that given a bulk of the deaths are among older people, when people are more infirm, the quality adjusted years lost is likely yet more modest. Given that the last life tables from China are from 1981, we estimate the average number of years lost if people had the same profile as Americans. Using the most recent SSA data, we find that number to be 16. Compare this to deaths from road accidents, [the modal reason for death](https://www.businessinsider.com/how-youre-most-likely-to-die-at-every-age-2018-6) among 5-24 and 25-44 ages in the US. Male life expectancy in the US at 25 is another ~ 52 years.  ![table1.png](table1.png)<jupyter_code>import pandas as pd
from lost_years import lost_years_hld<jupyter_output><empty_output><jupyter_text>Prepare example input in DataFramePlease look at country codes here:- https://www.lifetable.de/cgi-bin/country_codes.php<jupyter_code>df = pd.read_csv('/opt/github/lost_years/examples/covid19/table_1.csv')
df['year'] = 2020
df<jupyter_output><empty_output><jupyter_text>Get Human Life Table data columns from HLD dataset<jupyter_code>highest_ldf = lost_years_hld(df, {'age': 'lowest_age', 'country': 'country', 'sex': 'sex', 'year': 'year'})
highest_ldf.head()<jupyter_output><empty_output><jupyter_text>**Note that the year we are matching to is 1981.**<jupyter_code># From table 1, 95.7% deaths in Hubie region == 110 (https://www.lifetable.de/cgi-bin/regions.php)
highest_ldf = highest_ldf[highest_ldf.hld_region=='110'].copy()
highest_ldf<jupyter_output><empty_output><jupyter_text>Assuming all the people who died were at the bottom of the age ranges<jupyter_code>highest_ldf['years_lost'] = highest_ldf['hld_life_expectancy'] * highest_ldf['n_deaths'] / highest_ldf['n_deaths'].sum()
highest_ldf
highest_ldf['years_lost'].sum().round()
lowest_ldf = lost_years_hld(df, {'age': 'highest_age', 'country': 'country', 'sex': 'sex', 'year': 'year'})
lowest_ldf.head()<jupyter_output><empty_output><jupyter_text>Assuming all the people who died were at the top of the age ranges<jupyter_code># From table 1, 95.7% deaths in Hubie region == 110 (https://www.lifetable.de/cgi-bin/regions.php)
lowest_ldf = lowest_ldf[lowest_ldf.hld_region=='110'].copy()
lowest_ldf
lowest_ldf['years_lost'] = lowest_ldf['hld_life_expectancy'] * lowest_ldf['n_deaths'] / lowest_ldf['n_deaths'].sum()
lowest_ldf
lowest_ldf['years_lost'].sum().round()
middle_ldf = lost_years_hld(df, {'age': 'middle_age', 'country': 'country', 'sex': 'sex', 'year': 'year'})
middle_ldf.head()<jupyter_output><empty_output><jupyter_text>Assuming all the people who died were at the middle of the age ranges<jupyter_code># From table 1, 95.7% deaths in Hubie region == 110 (https://www.lifetable.de/cgi-bin/regions.php)
middle_ldf = middle_ldf[middle_ldf.hld_region=='110'].copy()
middle_ldf
middle_ldf['years_lost'] = middle_ldf['hld_life_expectancy'] * middle_ldf['n_deaths'] / middle_ldf['n_deaths'].sum()
middle_ldf
middle_ldf['years_lost'].sum().round()<jupyter_output><empty_output><jupyter_text>Assume the Longevity is the Same as People in the US<jupyter_code>from lost_years import lost_years_ssa
ssa_middle_ldf = lost_years_ssa(df, {'age': 'middle_age', 'sex': 'sex', 'year': 'year'})
ssa_middle_ldf.head()
ssa_middle_ldf['years_lost'] = ssa_middle_ldf['ssa_life_expectancy'] * ssa_middle_ldf['n_deaths'] / ssa_middle_ldf['n_deaths'].sum()
ssa_middle_ldf
ssa_middle_ldf['years_lost'].sum().round()<jupyter_output><empty_output><jupyter_text>Assume Everyone Lives Till 90<jupyter_code>y90_middle_ldf = df.copy()
y90_middle_ldf['y90_life_expectancy'] = 90 - y90_middle_ldf['middle_age']
y90_middle_ldf.head()
y90_middle_ldf['years_lost'] = y90_middle_ldf['y90_life_expectancy'] * y90_middle_ldf['n_deaths'] / y90_middle_ldf['n_deaths'].sum()
y90_middle_ldf
y90_middle_ldf['years_lost'].sum().round()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12108108108108108, 'fraction_numerical': 0.02508108108108108, 'mean_word_length': 7.11578947368421, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 5, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '307068', 'license': 'MIT', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1592, 'n_words': 420, 'path': 'examples/corona_virus.ipynb', 'repo_name': 'gojiplus/lost_years', 'size': '4625'}