<jupyter_start><jupyter_text>Question 1 : How is presidential attention distributed accross policy spheres?<jupyter_code># Pie chart, where the slices will be ordered and plotted counter-clockwise:
columns = ['president_Krašto apsaugos', 'president_Premjeras',
       'president_Teisingumo', 'president_Žemės Ūkio',
       'president_Socialinės apsaugos ir darbo',
       'president_Ekonomikos ir inovacijų', 'president_Ūkio',
       'president_Vidaus reikalų', 'president_Susisiekimo',
       'president_Švietimo ir mokslo', 'president_Finansų',
       'president_Švietimo, mokslo ir sporto', 'president_Kultūros',
       'president_Energetikos', 'president_Aplinkos ',
       'president_Užsienio reikalų', 'president_Sveikatos apsaugos',]

labels =[i.replace("president_", "") for i in columns]

sizes = [round(df[i].mean()*1000) for i in columns]

data_dict = {labels[index]:i for index, i in enumerate(sizes)}

fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

plt.show()
sorted(data_dict.items(), key = lambda x: x[1], reverse=True)<jupyter_output><empty_output><jupyter_text>Q2: How the attention pattern differs over time?<jupyter_code>columns = ['president_Premjeras',
           'president_Užsienio reikalų', 
           'president_Krašto apsaugos', 
            'president_Vidaus reikalų',
          'president_Sveikatos apsaugos',]

agg_dict = {i : "mean" for i in columns}

df2 = df.groupby(["year"]).agg(agg_dict)
print(df2.shape)
df2.head()
df2.plot.line()<jupyter_output><empty_output><jupyter_text>Q 2.1: Did Grybauskaite pay more attention to FP/DP than others?<jupyter_code>df["grybauskaite"] = df.apply(lambda x: int(x["president"] == "<NAME>"), axis = 1)
print(df["grybauskaite"].mean())

dfa = df[df.grybauskaite == 0]
dfb = df[df.grybauskaite == 1]
# Foreign policy

print(dfa["president_Užsienio reikalų"].mean())
print(dfb["president_Užsienio reikalų"].mean())

ttest_ind(list(dfa["president_Užsienio reikalų"]), list(dfb["president_Užsienio reikalų"]))
# Defense

print(dfa["president_Krašto apsaugos"].mean())
print(dfb["president_Krašto apsaugos"].mean())

ttest_ind(list(dfa["president_Krašto apsaugos"]), list(dfb["president_Krašto apsaugos"]))<jupyter_output>0.015051095367135722
0.016560283687943263<jupyter_text>Q 2.2: Does Nauseda pay more attention to healthcare?<jupyter_code>df["nauseda"] = df.apply(lambda x: int(x["president"] == "<NAME>"), axis = 1)
print(df["nauseda"].mean())

dfa = df[df.nauseda == 0]
dfb = df[df.nauseda == 1]
# Healthcare

print(dfa["president_Sveikatos apsaugos"].mean())
print(dfb["president_Sveikatos apsaugos"].mean())

ttest_ind(list(dfa["president_Sveikatos apsaugos"]), list(dfb["president_Sveikatos apsaugos"]))<jupyter_output>0.009317608930500541
0.025630339654094603<jupyter_text>Does presidential attention mirror media attention?<jupyter_code>ministries = ['Krašto apsaugos', 'Premjeras',
       'Teisingumo', 'Žemės Ūkio',
       'Socialinės apsaugos ir darbo', 'Ekonomikos ir inovacijų', 'Ūkio',
       'Vidaus reikalų', 'Susisiekimo', 'Švietimo ir mokslo', 'Finansų',
       'Švietimo, mokslo ir sporto', 'Kultūros', 'Energetikos', 'Aplinkos ',
       'Užsienio reikalų', 'Sveikatos apsaugos',]


ministries2 = ["president_"+i for i in ministries]

ministries_full = ministries + ministries2

agg_dict = {i:"mean" for i in ministries_full}
agg_dict["president"] = "last" 

dfg = df.groupby(["year", "month"]).agg(agg_dict)
dfg["grybauskaite"] = dfg.apply(lambda x:int(x["president"]=="<NAME>"), axis=1)
print(dfg.shape)
dfg.head()
for m in ministries:
    print(m)
    print(pearsonr(dfg[m], dfg["president_"+m]))
    print()
    
for m in ministries:
    print(m)
    y = dfg[["president_"+m]]
    X = dfg[[m, "grybauskaite"]]
    X = sm.add_constant(X)
    
    model = sm.OLS(y, X)
    results = model.fit()
    print(results.summary())
    
    print()<jupyter_output>Krašto apsaugos
                                OLS Regression Results                               
=====================================================================================
Dep. Variable:     president_Krašto apsaugos   R-squared:                       0.277
Model:                                   OLS   Adj. R-squared:                  0.272
Method:                        Least Squares   F-statistic:                     50.24
Date:                       Sun, 23 Jan 2022   Prob (F-statistic):           3.39e-19
Time:                               20:41:21   Log-Likelihood:                 760.02
No. Observations:                        265   AIC:                            -1514.
Df Residuals:                            262   BIC:                            -1503.
Df Model:                                  2                                         
Covariance Type:                   nonrobust                                         
======================================[...]<jupyter_text>Is presidential attention larger during the first year of presidential term?<jupyter_code>dg1b = datetime(2009, 7, 12)
dg1e = datetime(2010, 7, 12)
dg2b = datetime(2014, 7, 12)
dg2e = datetime(2015, 7, 12)
gnb = datetime(2019, 7, 12)
gne = datetime(2020, 7, 12)

first_year = []

for i in df.date:
    plh = 0
    if dg1b <= i < dg1e :
        plh = 1
    if dg2b <= i < dg2e :
        plh = 1
    if gnb <= i < gne :
        plh = 1
    first_year.append(plh)
    
df["first_year"] = first_year
print(df.first_year.mean())
dfa = df[df.first_year == 0]
dfb = df[df.first_year == 1]

for m in ministries2:
    print(m)
    print("Normal: ", dfa[m].mean())
    print("Firsr year: ", dfb[m].mean())
    print(ttest_ind(dfa[m], dfb[m]))
    print()<jupyter_output>president_Krašto apsaugos
Normal:  0.016169205861596578
Firsr year:  0.013989296779645104
Ttest_indResult(statistic=1.6339514262952763, pvalue=0.102274401359019)

president_Premjeras
Normal:  0.0716302046577276
Firsr year:  0.10074171439301474
Ttest_indResult(statistic=-10.213537047438884, pvalue=1.8077325931222448e-24)

president_Teisingumo
Normal:  0.007347752086014363
Firsr year:  0.005163834381748193
Ttest_indResult(statistic=2.4548446213300763, pvalue=0.01409742343696923)

president_Žemės Ūkio
Normal:  0.005209846818049732
Firsr year:  0.006947704440897568
Ttest_indResult(statistic=-2.189804576172605, pvalue=0.02854232575853095)

president_Socialinės apsaugos ir darbo
Normal:  0.005458923159948524
Firsr year:  0.009107126091446812
Ttest_indResult(statistic=-4.369616265652839, pvalue=1.2467785875827773e-05)

president_Ekonomikos ir inovacijų
Normal:  0.0022831998007389266
Firsr year:  0.010703220354896254
Ttest_indResult(statistic=-12.785930765139751, pvalue=2.203889902902592e-37)
[...]<jupyter_text>Top 5 Spheres for each president<jupyter_code>prez_cols = ['president_Užsienio reikalų',
       'president_Vidaus reikalų', 'president_Švietimo ir mokslo',
       'president_Teisingumo', 'president_Sveikatos apsaugos',
       'president_Kultūros', 'president_Premjeras',
       'president_Švietimo, mokslo ir sporto', 'president_Energetikos',
       'president_Ekonomikos ir inovacijų',
       'president_Finansų', 'president_Žemės Ūkio',
       'president_Krašto apsaugos', 'president_Socialinės apsaugos ir darbo',
       'president_Aplinkos ', 'president_Susisiekimo', 'president_Ūkio']
df_adamkus = df[df["president"] == "<NAME>"]

adamkus_atention_dict = {}
for col in prez_cols:
    adamkus_atention_dict[col] = df_adamkus[col].mean()
    
s_adamkus_atention_dict = sorted(adamkus_atention_dict.items(), key = lambda x : x[1], reverse = True)
s_adamkus_atention_dict[0:5]
df_grybauskaite = df[df["president"] == "<NAME>"]

grybauskaite_atention_dict = {}
for col in prez_cols:
    grybauskaite_atention_dict[col] = df_grybauskaite[col].mean()
    
s_grybauskaite_atention_dict = sorted(grybauskaite_atention_dict.items(), key = lambda x : x[1], reverse = True)
s_grybauskaite_atention_dict[0:5]
df_nauseda = df[df["president"] == "<NAME>"]

nauseda_atention_dict = {}
for col in prez_cols:
    nauseda_atention_dict[col] = df_nauseda[col].mean()
    
s_nauseda_atention_dict = sorted(nauseda_atention_dict.items(), key = lambda x : x[1], reverse = True)
s_nauseda_atention_dict[0:5]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1380808690404345, 'fraction_numerical': 0.07942063971031986, 'mean_word_length': 3.897163120567376, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '659064', 'license': 'MIT', 'n_tokens_mistral': 3656, 'n_tokens_neox': 3166, 'n_words': 570, 'path': '2_analysis/Analysis_pt1.ipynb', 'repo_name': 'lukas-pkl/presidential_attention', 'size': '8347'}