<jupyter_start><jupyter_text>The Danish Tax Burden Imports:<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import pandas as pd
import pydst
dst = pydst.Dst(lang='en')<jupyter_output><empty_output><jupyter_text>Data In this paper we analyze and try to explain the development in the Danish tax burden in the years around the financial crisis, 2004-2016. To do so, we import and prepare a dataset containing information about the relevant variables from Statistikbanken; a process we will go through in this section. From this, we will create the variables necessary for the investigation and, finally, combine all data into one dataset pertaining specifically to this paper.   GDP We start out by importing data from the NAN1 table from Statistikbanken. This table contains information about components of the danish national accounts, including the danish GDP.<jupyter_code>nan1_var = dst.get_variables(table_id='NAN1')
nan1_var<jupyter_output><empty_output><jupyter_text>On this, we use the following (now muted) piece of code to identify all relevant variables and their values for selection:<jupyter_code>#for id in ['TRANSAKT','PRISENHED','Tid']:
#    print(id)
#    values = nan1_var.loc[nan1_var.id == id,['values']].values[0,0]
#    for value in values:      
#        print(f' id = {value["id"]}, text = {value["text"]}')<jupyter_output><empty_output><jupyter_text>Using this information, we select gross domestic product, GDP, (in both current and real prices) along with its real growth over time.<jupyter_code>time = ['2004','2005','2006','2007','2008','2009','2010','2011','2012', '2013', '2014', '2015', '2016']
variables_gdp = {'PRISENHED':['V_M', 'LAN_M', 'L_V'],'Tid': time}
gdp_api = dst.get_data(table_id = 'NAN1', variables=variables_gdp)
gdp_api.head(5)<jupyter_output><empty_output><jupyter_text>For simplicity (and to lower the risk of bugs), we rename all columns, units and variables:<jupyter_code># a. code for creating dictonaries containing new names of columns, units and variables. 
columns_dict = {}
columns_dict['TRANSAKT'] = 'variable'
columns_dict['PRISENHED'] = 'unit'
columns_dict['TID'] = 'year'
columns_dict['INDHOLD'] = 'value'

var_dict = {} # var is for variable
var_dict['B.1*g Gross domestic product'] = 'gdp'

unit_dict = {}
unit_dict['2010-prices, chained values, (bill. DKK.)'] = 'gdp_real'
unit_dict['Current prices, (bill. DKK.)'] = 'gdp_nominal'
unit_dict['Period-to-period real growth (per cent) '] = 'gdp_growth'

# b. renaming
gdp_api.rename(columns = columns_dict, inplace=True)

for key,value in var_dict.items():
    gdp_api.variable.replace(key,value,inplace=True)

for key,value in unit_dict.items():
    gdp_api.unit.replace(key,value,inplace=True)

gdp_api.head(5)<jupyter_output><empty_output><jupyter_text>To achieve a better overview (and to simultaniously get rid of the 'TRANSAKT' column), we pivot the table.<jupyter_code>gdp_api = gdp_api.pivot_table('value', 'year', 'unit')
gdp_api.head(10)<jupyter_output><empty_output><jupyter_text>Taxes The second step is now to create a table containing general information about tax revenues. This kind of information is contained in the "SKAT"-table from Statistikbanken, which we import and transform, as with GDP.<jupyter_code>tax_var = dst.get_variables(table_id='SKAT')
tax_var<jupyter_output><empty_output><jupyter_text>The relevant variables are again identified (muted) and we import the relevant data:<jupyter_code># a. identifying variables
#for id in ['TYPE','Tid']:
#    print(id)
#    values = skat_var.loc[skat_var.id == id,['values']].values[0,0]
#    for value in values:      
#        print(f' id = {value["id"]}, text = {value["text"]}')

# b. importing data
variables_skat = {'TYPE':['TOTAL', '1', '1.2','1.3', '4.3'],'Tid': time}
tax_api = dst.get_data(table_id = 'SKAT', variables=variables_skat)
tax_api.head(6)
# a. new names
columns_dict_tax = {}
columns_dict_tax['TYPE'] = 'tax'
columns_dict_tax['TID'] = 'year'
columns_dict_tax['INDHOLD'] = 'value'

var_dict_tax = {}
var_dict_tax['Taxes and duties, total'] = 'tax_total'
var_dict_tax['1.2. Corporation tax, etc.'] = 'tax_corp'
var_dict_tax['1. Income taxes, total'] = 'tax_income'
var_dict_tax['1.3. Tax on yields of certain pension scheme assets'] = 'tax_pension'
var_dict_tax['4.3. Motor vehicle duties'] = 'tax_vehic'

# b. renaming
tax_api.rename(columns = columns_dict_tax, inplace=True)

for key,value in var_dict_tax.items():
    tax_api.tax.replace(key,value,inplace=True)

# c. transformming table
tax_api = tax_api.pivot_table('value', 'year', 'tax')
tax_api.head(10)<jupyter_output><empty_output><jupyter_text>Merging Finally, we merge out two datasets.<jupyter_code>gdptax = pd.merge(gdp_api, tax_api, on='year', how='left')
gdptax.head(10)<jupyter_output><empty_output><jupyter_text>Analysis  In our analysis, we start with the development in the danish real GDP. The gross domestic product isn't only necessary for calculating the tax burden, GDP growth is also integral to explaining its developments. Firstly, when times are good (i.e. during the expansions and peaks of business cycles) we tend to see increasing employment and higher levels of income. In a progressive tax system, this naturally entails an increase in the tax burden. Furthermore, people tend to shift their consumption towards luxury good, which are often more heavily taxed. Other factors are also relevant, which we will get into later.<jupyter_code>%matplotlib widget
fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax2.bar(time, height = gdp_api['gdp_growth'], width = 0.8)
ax1.plot(time, gdp_api['gdp_real'], 'g')
ax1.grid(False)

ax1.set_xlabel('Year')
ax1.set_ylabel('Bill. DKK', color='g')
ax2.set_ylabel('Pct.', color='b')

plt.show()<jupyter_output><empty_output><jupyter_text>In the figure above, we see the twelve year development in Danish real GDP. Here we note the business cycle expansion and peak from 2004-2007, after which the economy dives into a recession in 2008-2009, due to the financial crisis. From there the economy begins its recovery with relatively low growth rates from 2010-2014, until it enters another expansion in the following years.  To calculate the tax burden, we use the formula$$\text{Tax burden} = \frac{\text{Total tax revenue}}{\text{GDP in market prices}}$$and set up our data in numpy arrays:<jupyter_code># a. creating arrays
#  i. nominal gdp
gdp_nom = np.array(gdptax['gdp_nominal'])
#  ii. tax revenue
tax_tot = np.array(gdptax['tax_total']) 

# b. calculating taxburden
taxburden = 100*(tax_tot/1000000)/gdp_nom

# c. descriptives
df_taxburden=pd.DataFrame(taxburden)
df_taxburden.head(5)
df_taxburden.describe()<jupyter_output><empty_output><jupyter_text>The average tax burden is 46,5 pct. Doing the period from 2004 to 2016 the lowest tax burden was 44,9 pct. and the highest tax burden was 49,8 pct. We're are now able to also illustrate the development in the tax burden.<jupyter_code>fig = plt.figure()
plt.bar(time, taxburden, color = 'y')
plt.xlabel('Year')
plt.ylabel('Pct.')
plt.ylim(42, 51)<jupyter_output><empty_output><jupyter_text>From this figure, we notice the relatively stable level of tax burden around the average of 46.5 pct., during the aforementioned expansion and peak periods, with the exception of an usually high level in 2005. At the onset of the recession the level takes a visible dive to around 45pct., after which it remains pretty much stable for the period 2008-2011. In 2012 it slowly recovers and suddenly takes a jump upwards in 2013 to around 47pct., from which it booms to its highest level of 49,8pct. in 2014. The following two years, 2015-2016, it seems to be making its way back to around its initial level.  Causes As explained in the previous section, other factors than just the business cycles seem to be important in explaining the movements in the tax burden. Of these factors, political decisions seem to be the most important. In *Figure 3* we have shown the development of the total tax burden compared to the development of other chosen taxes. From this it can be seen, that the tax burden related to income taxes seem to the main driver of the total tax burden. During the concerned period there have been different political actions, which have influenced the total tax burden through taxation of income. The significant rise in taxes during the period 2012-2015, are in large part due to a restructuring of capital pensions. In this period, everyone with a capital pension was offered to pay their future pension taxes in the years 2013-2015 at a lower tax rate, instead of at the time of payment (as is usually done). This advanced tax payments of approximately 29 bill. DKK in 2013, 59 bill. DKK in 2014, and 18 bill. DKK in 2015 - which, all else equal, of course caused a rise in the tax burden in these three years. This increase was largely due to an increase in the taxburden related to income taxes, which is as expected. In 2004 a specific pension scheme ('Den Særlige Pensionsopsparing', or simply 'SP') was suspended. This, among other things, resulted in a larger tax burden, since the SP was deducted from tax payments. This could in part explain the high level of tax burden in 2005.<jupyter_code>tax_inc = np.array(gdptax['tax_income'])
taxb_inc = 100*(tax_inc/1000000)/gdp_nom
tax_corp = np.array(gdptax['tax_corp'])
taxb_corp = 100*(tax_corp/1000000)/gdp_nom
tax_pension = np.array(gdptax['tax_pension'])
taxb_pension = 100*(tax_pension/1000000)/gdp_nom
tax_vehic = np.array(gdptax['tax_vehic'])
taxb_vehic = 100*(tax_vehic/1000000)/gdp_nom
%matplotlib widget 
#A. Creating figure
fig = plt.figure(3, figsize=(8,3))

#A.1 First subplot
ax1 = fig.add_subplot(121)

#A.1.1 Formatting first subplot
ax1.set_xticks(range(13))
ax1.set_xticklabels(time, fontdict = {'fontsize': 8})
plt.xticks(rotation = 45)
ax1.set_ylim(40,52)

#A.1.2 Entering data into first subplot
ax1.bar(time, taxburden, label = "total taxburden", color = 'y', zorder = 1000)
ax1_2 = ax1.twinx() #create second y_axis
ax1_2.plot(time, taxb_inc, label = "taxburden from income taxes", color = 'b') #data plotted on second y-axis

#A.1.3 Final fomratting of first subplot
ax1_2.set_ylim(26,34)
ax1_2.grid(False) 
ax1.set_xlabel('Year')
ax1.set_ylabel('Pct.', color='y')
ax1_2.set_ylabel('Pct.', color='b')
ax1.legend()
ax1_2.legend(loc = 'upper right', bbox_to_anchor=(1.3,1.12))

#A.2 Second subplot
ax2 = fig.add_subplot(122)

#A.2.1 Formatting second subplot
ax2.set_xticks(range(13))
ax2.set_xticklabels(time, fontdict = {'fontsize': 8})
plt.xticks(rotation = 45)

#A.2.2 Entering data into second subplot
ax2.plot(time, taxb_corp, label = 'Corporate tax, etc.', color = 'y')
ax2.plot(time, taxb_pension, label = 'Pension tax', color = 'b')
ax2_2 = ax2.twinx() #create second y-axis
ax2_2.plot(time, taxb_vehic, label = 'Motor vehicle duties (r.h. axis)', color = 'r') #data plotted on second y-axis

#A.2.3 Final fomratting of second subplot
ax2_2.grid(False)
#ax2.set_ylim(40,52)
ax2.set_xlabel('Year')
ax2.set_ylabel('Pct.')
ax2_2.set_ylabel('Pct.', color = 'red')
ax2.legend()
ax2_2.legend(loc = 'upper right', bbox_to_anchor=(1.23,1.12))
plt.tight_layout(pad = 1) #create space between plots<jupyter_output><empty_output><jupyter_text>Append Finally we want to store all of our data. We therefore create a final table, inlucing all the variables used in this notebook, and export it as a CSV file. First step is to convert our arrays to dataframes.<jupyter_code># a. converting arrays to dataframes
df_taxb_all = pd.DataFrame({'tot_taxb':taxburden, 'tot_corp':tax_corp, 'tot_inc':tax_inc, 'tot_vehic':tax_vehic, 'taxb_pens':taxb_pension}, index=gdptax.index)
df_taxb_all.head()<jupyter_output><empty_output><jupyter_text>We now append out new DataFrame to the rest of our dataset<jupyter_code># b. joining DataFrames
TaxBurdenData = gdptax.join(df_taxb_all)
TaxBurdenData.head(12)<jupyter_output><empty_output><jupyter_text>We now export our dataset as a CSV file<jupyter_code># c. exporting csv file
TaxBurdenData.to_csv('TaxBurdenData.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10956866633614279, 'fraction_numerical': 0.032639233184597584, 'mean_word_length': 5.723888888888889, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '57465', 'license': 'MIT', 'n_tokens_mistral': 4307, 'n_tokens_neox': 3975, 'n_words': 1355, 'path': 'dataproject/dataproject.ipynb', 'repo_name': 'NumEconCopenhagen/Projects_workfolder', 'size': '12102'}