Copyright 2021 Allen B. Downey
License: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from simpson import *
gss = pd.read_hdf('gss_simpson', 'gss')
Would you say that most of the time people try to be helpful, or that they are mostly just looking out for themselves?
xvarname = 'year'
yvarname = 'helpful'
gvarname = 'cohort10'
run_subgroups(gss, xvarname, yvarname, gvarname)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | -0.005825 | 3.914851e-16 | 0.000716 | [-0.007227578565834578, -0.004422785059639855] |
1890.0 | -0.019158 | 4.795507e-01 | 0.027097 | [-0.07226678623878108, 0.03395058250983201] |
1900.0 | 0.031164 | 4.159768e-04 | 0.008829 | [0.013859514124449107, 0.048468582435378126] |
1910.0 | 0.011832 | 1.382779e-02 | 0.004807 | [0.002411631450232177, 0.021252823199767908] |
1920.0 | 0.007490 | 1.368502e-02 | 0.003038 | [0.0015356085968546039, 0.013444454041372303] |
1930.0 | 0.008493 | 4.814896e-04 | 0.002433 | [0.0037247556387850593, 0.01326223285510425] |
1940.0 | 0.005320 | 5.022354e-03 | 0.001896 | [0.0016034244262409045, 0.00903609532788564] |
1950.0 | 0.008550 | 4.216908e-07 | 0.001690 | [0.005237326124043439, 0.011862170189889918] |
1960.0 | 0.014967 | 7.996334e-10 | 0.002436 | [0.010193019613194458, 0.019740344684094562] |
1970.0 | 0.020643 | 6.542301e-07 | 0.004150 | [0.012509708919919588, 0.02877671732266779] |
1980.0 | 0.038891 | 1.298280e-05 | 0.008919 | [0.021409694870457442, 0.056371943729181244] |
1990.0 | 0.024598 | 3.586891e-01 | 0.026799 | [-0.02792767994438156, 0.07712432640161354] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 48.497852 | 50.960117 | 57.409565 | 52.086140 | 47.216496 | 41.009464 | NaN | NaN | NaN |
1977.0 | 57.632401 | 51.335876 | 60.000004 | 56.108601 | 52.406418 | 39.981785 | 42.857143 | NaN | NaN |
1982.0 | 64.885498 | 55.223881 | 59.216587 | 56.091953 | 55.348045 | 51.553673 | 43.193714 | NaN | NaN |
1987.0 | 59.183674 | 56.451614 | 54.637867 | 51.861362 | 55.472015 | 47.003609 | 37.755936 | 41.666664 | NaN |
1992.0 | 62.121212 | 52.153111 | 63.157890 | 56.696426 | 54.852318 | 49.291496 | 36.099140 | 36.578171 | NaN |
1997.0 | 60.000004 | 62.804878 | 58.999996 | 55.128204 | 50.326801 | 44.560837 | 40.547066 | 31.774811 | 31.182796 |
2002.0 | NaN | 53.571426 | 66.666672 | 52.777779 | 53.696495 | 58.823532 | 46.531792 | 42.618385 | 26.712328 |
2007.0 | NaN | 54.838711 | 62.195122 | 61.676643 | 56.159420 | 46.827793 | 46.162529 | 36.280136 | 31.559404 |
2012.0 | NaN | NaN | 67.241379 | 62.359547 | 55.688625 | 48.262550 | 45.890411 | 40.564373 | 43.516876 |
2017.0 | NaN | NaN | 72.413788 | 65.517242 | 56.375839 | 52.846973 | 50.085182 | 47.500000 | 40.031643 |
visualize(series_all, table)
plt.title('')
title = """Would you say that most of the time people try to be helpful,
or that they are mostly just looking out for themselves?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "helpful"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('helpful_vs_year_by_cohort10.jpg')
Generally speaking, would you say that most people can be trusted or that you can't be too careful in dealing with people?
xvarname = 'year'
yvarname = 'trust'
gvarname = 'cohort10'
yvalue = 1
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | -0.013451 | 1.635942e-72 | 0.000747 | [-0.014914877801887255, -0.011987170663713648] |
1890.0 | -0.037958 | 1.868996e-01 | 0.028760 | [-0.09432758189038531, 0.01841119793414462] |
1900.0 | 0.022180 | 9.635582e-03 | 0.008568 | [0.005386576791562049, 0.03897303255181153] |
1910.0 | -0.023103 | 1.879545e-06 | 0.004848 | [-0.032604235603353626, -0.013602205002939325] |
1920.0 | -0.013333 | 8.273245e-06 | 0.002991 | [-0.01919505039781757, -0.00747118388268748] |
1930.0 | -0.011764 | 1.236946e-06 | 0.002426 | [-0.01651906007167977, -0.007009893302926963] |
1940.0 | -0.003639 | 5.438850e-02 | 0.001892 | [-0.00734610246048668, 6.853840616605992e-05] |
1950.0 | 0.005298 | 2.247567e-03 | 0.001734 | [0.001899573656206997, 0.008697010111858335] |
1960.0 | 0.013464 | 2.803729e-07 | 0.002621 | [0.008326414353880133, 0.018602447712284018] |
1970.0 | 0.007495 | 9.796910e-02 | 0.004530 | [-0.0013823338034487887, 0.01637302796972214] |
1980.0 | 0.015568 | 1.134109e-01 | 0.009834 | [-0.0037067684953792385, 0.034843461403460764] |
1990.0 | 0.167110 | 1.713328e-05 | 0.038869 | [0.09092820648936911, 0.24329234288528695] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 40.212765 | 47.360703 | 50.582748 | 47.169811 | 41.521069 | 34.428795 | NaN | NaN | NaN |
1977.0 | 39.130436 | 44.612476 | 47.164593 | 50.977444 | 45.802338 | 35.009140 | 18.681318 | NaN | NaN |
1982.0 | 33.962265 | 38.524590 | 47.440273 | 48.242809 | 46.578365 | 41.242939 | 36.678200 | NaN | NaN |
1987.0 | 48.223351 | 40.755470 | 40.455120 | 40.966923 | 45.295586 | 36.978416 | 25.856443 | 41.666664 | NaN |
1992.0 | 57.575756 | 34.761906 | 39.259258 | 35.555557 | 37.447403 | 39.235413 | 26.881721 | 29.585800 | NaN |
1997.0 | 51.724136 | 35.227272 | 35.391922 | 43.265991 | 46.107178 | 38.027107 | 31.737848 | 21.975090 | 30.107529 |
2002.0 | NaN | 28.571430 | 51.428574 | 37.500000 | 44.787643 | 45.454548 | 33.141212 | 27.576601 | 18.620689 |
2007.0 | NaN | 33.333336 | 42.458099 | 34.025974 | 44.897957 | 36.851685 | 38.974361 | 24.684874 | 20.310766 |
2012.0 | NaN | NaN | 36.206894 | 38.333332 | 32.238804 | 40.926640 | 33.901196 | 25.131809 | 25.800711 |
2017.0 | NaN | NaN | 43.333332 | 47.260273 | 40.863789 | 41.312057 | 31.217838 | 31.780365 | 25.236591 |
visualize(series_all, table)
plt.title('')
title = """Generally speaking, would you say that most people can be trusted
or that you can't be too careful in dealing with people?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "can be trusted"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('trust_vs_year_by_cohort10.jpg')
Do you think most people would try to take advantage of you if they got a chance, or would they try to be fair?
xvarname = 'year'
yvarname = 'fair'
gvarname = 'cohort10'
yvalue = 2
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | -0.010977 | 3.439721e-52 | 0.000722 | [-0.01239260710371703, -0.009562006898250907] |
1890.0 | -0.018565 | 5.166361e-01 | 0.028627 | [-0.07467265652757318, 0.0375416620240953] |
1900.0 | 0.042908 | 7.818749e-06 | 0.009599 | [0.024094383010655227, 0.06172130979577424] |
1910.0 | 0.000983 | 8.432464e-01 | 0.004970 | [-0.008758492007722286, 0.010724110809917716] |
1920.0 | 0.001674 | 5.914467e-01 | 0.003119 | [-0.004439529767318436, 0.007788093250046219] |
1930.0 | -0.000050 | 9.841519e-01 | 0.002495 | [-0.004940447210043803, 0.0048413103346909405] |
1940.0 | 0.001983 | 3.065279e-01 | 0.001939 | [-0.0018175354212342462, 0.005782619241239932] |
1950.0 | 0.004863 | 4.109611e-03 | 0.001695 | [0.0015414540814034845, 0.008183928716427216] |
1960.0 | 0.012788 | 1.092845e-07 | 0.002408 | [0.008068221249952951, 0.017507371025538898] |
1970.0 | 0.023897 | 4.903755e-09 | 0.004085 | [0.015891241129705608, 0.0319029245169848] |
1980.0 | 0.018530 | 3.112648e-02 | 0.008597 | [0.0016805751400463982, 0.035379496305145836] |
1990.0 | 0.008230 | 7.544276e-01 | 0.026309 | [-0.04333584393368995, 0.05979540170621026] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 57.974136 | 63.328426 | 66.511627 | 61.943321 | 57.394005 | 48.985958 | NaN | NaN | NaN |
1977.0 | 68.965515 | 67.366409 | 65.138885 | 67.119156 | 61.456100 | 53.173874 | 45.054947 | NaN | NaN |
1982.0 | 71.111115 | 60.060059 | 61.484921 | 63.448273 | 63.032372 | 56.276447 | 44.094486 | NaN | NaN |
1987.0 | 70.256409 | 67.813766 | 64.948448 | 62.901157 | 63.636364 | 57.894737 | 43.811073 | 47.222221 | NaN |
1992.0 | 83.582092 | 63.809525 | 67.910454 | 56.787331 | 59.661495 | 57.777779 | 44.637054 | 41.317364 | NaN |
1997.0 | 68.000000 | 60.000004 | 62.849873 | 60.443623 | 60.812294 | 51.876022 | 50.040688 | 36.786060 | 44.086021 |
2002.0 | NaN | 67.857140 | 64.761909 | 54.166668 | 55.294121 | 60.687958 | 44.956772 | 47.075211 | 26.027397 |
2007.0 | NaN | 73.333336 | 59.393944 | 65.137611 | 63.423424 | 50.050251 | 52.203388 | 41.637833 | 41.022446 |
2012.0 | NaN | NaN | 86.206894 | 70.056496 | 61.261261 | 58.994198 | 51.360542 | 50.088493 | 43.392857 |
2017.0 | NaN | NaN | 75.862068 | 68.055557 | 61.666668 | 62.300884 | 54.017097 | 52.921532 | 44.145569 |
visualize(series_all, table)
plt.title('')
title = """Do you think most people would try to take advantage of you if they got a chance,
or would they try to be fair?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "would try to be fair"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('fair_vs_year_by_cohort10.jpg')
Is there any area right around here--that is, within a mile--where you would be afraid to walk alone at night?
xvarname = 'year'
yvarname = 'fear'
gvarname = 'cohort10'
yvalue = 2
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | 0.012328 | 4.249652e-57 | 0.000774 | [0.010810771933626414, 0.013845309443939616] |
1890.0 | -0.079679 | 1.055168e-02 | 0.031158 | [-0.14074793363139834, -0.018609118609463675] |
1900.0 | -0.017515 | 7.369016e-02 | 0.009793 | [-0.03670801021651464, 0.0016787834759727192] |
1910.0 | -0.014597 | 4.414805e-03 | 0.005127 | [-0.02464697120628914, -0.004547698369112861] |
1920.0 | -0.001810 | 5.747878e-01 | 0.003226 | [-0.008132916187274662, 0.0045131452271464645] |
1930.0 | 0.002928 | 2.531914e-01 | 0.002562 | [-0.002094232307007154, 0.007949716746511858] |
1940.0 | 0.011611 | 2.149857e-08 | 0.002074 | [0.007547059949823356, 0.0156755764124481] |
1950.0 | 0.012591 | 9.727969e-12 | 0.001849 | [0.008967804533088923, 0.016215118555470188] |
1960.0 | 0.014720 | 3.355490e-09 | 0.002489 | [0.009840690623795986, 0.01959849816753189] |
1970.0 | 0.013566 | 1.053552e-03 | 0.004141 | [0.005449140161843367, 0.021682084487936574] |
1980.0 | 0.015112 | 7.910421e-02 | 0.008607 | [-0.0017562266905255773, 0.03198090496813623] |
1990.0 | -0.000324 | 9.914506e-01 | 0.030207 | [-0.05952924823264222, 0.05888188432984788] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 51.677853 | 61.085976 | 59.852673 | 60.680527 | 58.717110 | 63.829784 | NaN | NaN | NaN |
1977.0 | 51.273884 | 51.993065 | 63.144333 | 60.000004 | 60.177975 | 59.051304 | 55.421684 | NaN | NaN |
1982.0 | 40.776699 | 45.708157 | 53.369270 | 60.029499 | 61.599998 | 58.072918 | 64.106583 | NaN | NaN |
1987.0 | 49.006622 | 57.731956 | 52.334946 | 56.752140 | 68.474579 | 64.077667 | 60.310883 | 73.033707 | NaN |
1992.0 | 36.363636 | 47.679325 | 55.710304 | 49.047619 | 60.108547 | 62.918919 | 57.044674 | 59.210526 | NaN |
1997.0 | 52.173912 | 42.000000 | 52.676056 | 61.648743 | 63.492065 | 63.255440 | 59.950249 | 61.773117 | 59.574467 |
2002.0 | NaN | 60.869564 | 48.453609 | 68.131866 | 72.222221 | 71.356789 | 70.277077 | 72.799995 | 62.264149 |
2007.0 | NaN | 56.666668 | 67.096779 | 61.721069 | 69.485901 | 65.392776 | 70.370369 | 66.543213 | 63.846153 |
2012.0 | NaN | NaN | 68.627457 | 63.815792 | 67.000000 | 74.842766 | 64.991020 | 71.212120 | 66.489365 |
2017.0 | NaN | NaN | 75.000000 | 64.963501 | 71.176468 | 70.175438 | 70.625999 | 67.687073 | 66.153847 |
visualize(series_all, table)
plt.title('')
title = """Is there any area right around here--that is, within a mile--
where you would be afraid to walk alone at night?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "no"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('fear_vs_year_by_cohort10.jpg')
xvarname = 'year'
yvarname = 'happy'
gvarname = 'cohort10'
yvalue = [1,2]
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | -0.002285 | 0.013764 | 0.000928 | [-0.0041032155360231585, -0.00046696535868165833] |
1890.0 | 0.038240 | 0.260519 | 0.033987 | [-0.0283719266073775, 0.10485287547877495] |
1900.0 | 0.013303 | 0.269695 | 0.012052 | [-0.010318885219879297, 0.036923936886392394] |
1910.0 | -0.000571 | 0.926663 | 0.006205 | [-0.01273346612146039, 0.011591134383984458] |
1920.0 | 0.012295 | 0.002059 | 0.003990 | [0.004475333777179293, 0.02011549252262864] |
1930.0 | 0.005512 | 0.089231 | 0.003244 | [-0.0008449362671818783, 0.011869753403289293] |
1940.0 | -0.005121 | 0.039920 | 0.002493 | [-0.01000690901132986, -0.00023582305915941133] |
1950.0 | -0.002493 | 0.244426 | 0.002142 | [-0.0066919040760102634, 0.0017050661328273297] |
1960.0 | -0.011806 | 0.000135 | 0.003093 | [-0.017867459185350452, -0.005745054358809668] |
1970.0 | -0.016417 | 0.001657 | 0.005219 | [-0.02664549930962453, -0.006187730687237497] |
1980.0 | 0.041103 | 0.000036 | 0.009950 | [0.021601700203285976, 0.06060335667134924] |
1990.0 | -0.100883 | 0.003191 | 0.034212 | [-0.16793823019606974, -0.03382823087112466] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 86.173637 | 87.082405 | 84.995583 | 86.947792 | 87.952759 | 82.339447 | NaN | NaN | NaN |
1977.0 | 90.645882 | 87.686066 | 87.328094 | 91.337715 | 90.622406 | 88.950279 | 91.208794 | NaN | NaN |
1982.0 | 92.605629 | 89.863846 | 87.577003 | 85.963005 | 88.153305 | 89.083824 | 86.375320 | NaN | NaN |
1987.0 | 86.075951 | 90.327873 | 89.550682 | 89.155373 | 91.178497 | 91.607567 | 90.210251 | 93.162392 | NaN |
1992.0 | 84.810127 | 89.017342 | 92.733559 | 89.743591 | 88.369965 | 87.874565 | 89.048340 | 92.518250 | NaN |
1997.0 | 91.666672 | 82.857147 | 91.265594 | 89.621490 | 91.793755 | 87.942886 | 92.041710 | 88.952026 | 88.721809 |
2002.0 | NaN | 92.682930 | 91.558441 | 95.061729 | 89.005241 | 89.721260 | 88.724586 | 91.319443 | 81.048386 |
2007.0 | NaN | 85.000000 | 87.903229 | 91.033134 | 87.165176 | 85.088333 | 86.595581 | 89.257500 | 83.249580 |
2012.0 | NaN | NaN | 79.518074 | 88.047806 | 86.609070 | 85.258965 | 86.091125 | 87.236534 | 91.058823 |
2017.0 | NaN | NaN | 81.818184 | 87.962959 | 85.050507 | 88.141808 | 85.066376 | 86.766396 | 88.865097 |
visualize(series_all, table)
plt.title('')
title = """Taken all together, how would you say things are these days--
would you say that you are very happy, pretty happy, or not too happy?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "very happy" or "pretty happy"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('happy_vs_year_by_cohort10.jpg')
https://gss.norc.org/Documents/quex/GSS2018%20Ballot%202%20-%20English.pdf
Which of these statements comes closest to your feelings about pornography laws?
There should be laws against the distribution of pornography, whatever the age, or
There should be laws against the distribution of pornography to persons under 18, or
There should be no laws forbidding the distribution of pornography
xvarname = 'year'
yvarname = 'pornlaw'
gvarname = 'cohort10'
yvalue = 1
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | -0.011273 | 1.277596e-46 | 0.000786 | [-0.012814157706280808, -0.009732028169030328] |
1890.0 | 0.049571 | 2.488427e-01 | 0.042987 | [-0.034681924587223564, 0.13382425168956025] |
1900.0 | 0.001062 | 9.185716e-01 | 0.010386 | [-0.01929529389481996, 0.021418981267806593] |
1910.0 | 0.016735 | 2.862712e-03 | 0.005612 | [0.005736044776578969, 0.02773381307212317] |
1920.0 | 0.018362 | 4.235711e-08 | 0.003350 | [0.011795533184439917, 0.02492836323164188] |
1930.0 | 0.012158 | 1.860490e-06 | 0.002550 | [0.0071603454218177615, 0.01715590025094741] |
1940.0 | 0.022156 | 9.168343e-26 | 0.002111 | [0.018017742705881714, 0.0262934470123472] |
1950.0 | 0.021974 | 1.920759e-31 | 0.001884 | [0.018282171319694028, 0.025666350513799785] |
1960.0 | 0.018347 | 3.580736e-12 | 0.002639 | [0.013175175338581077, 0.023519117216250517] |
1970.0 | 0.026695 | 2.131507e-08 | 0.004766 | [0.01735377334527781, 0.03603692475501992] |
1980.0 | -0.000554 | 9.576488e-01 | 0.010435 | [-0.02100545474681647, 0.01989721556037316] |
1990.0 | 0.055484 | 1.008570e-01 | 0.033817 | [-0.01079611059586183, 0.12176403010848791] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 64.827583 | 62.004662 | 46.812748 | 41.398865 | 23.000000 | 17.796610 | NaN | NaN | NaN |
1977.0 | 70.873787 | 63.498096 | 50.983150 | 45.921452 | 27.586206 | 21.735161 | 14.285715 | NaN | NaN |
1982.0 | 66.417908 | 63.384617 | 63.317757 | 54.588234 | 31.911263 | 28.672318 | 21.522310 | NaN | NaN |
1987.0 | 60.215057 | 62.857143 | 59.143967 | 49.159122 | 37.625416 | 30.652174 | 25.693312 | 28.767124 | NaN |
1992.0 | 80.645164 | 75.961533 | 59.547741 | 51.793724 | 41.043724 | 28.658537 | 26.457882 | 16.566265 | NaN |
1997.0 | 64.000000 | 72.327042 | 63.250000 | 55.452866 | 40.264027 | 35.748791 | 29.159937 | 18.216682 | 19.354837 |
2002.0 | NaN | 64.285713 | 65.048546 | 52.857143 | 47.011955 | 34.803921 | 33.815029 | 22.005571 | 19.444445 |
2007.0 | NaN | 67.741936 | 58.641975 | 54.407291 | 42.286751 | 39.676113 | 31.151241 | 28.041714 | 21.766169 |
2012.0 | NaN | NaN | 72.413788 | 58.192093 | 46.483181 | 33.657585 | 34.582623 | 30.948120 | 18.360071 |
2017.0 | NaN | NaN | 46.428570 | 52.739727 | 43.581081 | 41.415932 | 36.597939 | 26.333332 | 21.135647 |
visualize(series_all, table)
plt.title('')
title = """Do you think there should be laws against the distribution of pornography,
whatever the age?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent who agree')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('pornlaw_vs_year_by_cohort10.jpg')
Do you think the use of marijuana should be made legal or not?
xvarname = 'year'
yvarname = 'fair'
gvarname = 'cohort10'
yvalue = 1
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | 0.007628 | 4.894648e-25 | 0.000738 | [0.006181028622331223, 0.009074056999469483] |
1890.0 | -0.033302 | 3.176265e-01 | 0.033323 | [-0.09861428262082172, 0.03201100393840778] |
1900.0 | -0.047445 | 5.688114e-06 | 0.010456 | [-0.06793839227718237, -0.026952103556243365] |
1910.0 | -0.006878 | 1.893425e-01 | 0.005240 | [-0.017148161334355302, 0.0033926322764510396] |
1920.0 | -0.007816 | 1.734340e-02 | 0.003285 | [-0.014254712258633652, -0.0013776770265430211] |
1930.0 | -0.004494 | 8.514546e-02 | 0.002610 | [-0.009609505230442256, 0.0006222233728750397] |
1940.0 | -0.004128 | 4.140376e-02 | 0.002024 | [-0.008094322536882637, -0.00016089734706081164] |
1950.0 | -0.006393 | 2.262750e-04 | 0.001734 | [-0.009791087561745196, -0.002995314647718323] |
1960.0 | -0.018968 | 8.145024e-15 | 0.002443 | [-0.023755710800939682, -0.014180582957056752] |
1970.0 | -0.023100 | 1.227564e-08 | 0.004056 | [-0.03104873869197835, -0.015151177999504961] |
1980.0 | -0.011127 | 1.871949e-01 | 0.008437 | [-0.02766331627836619, 0.005408337065099423] |
1990.0 | -0.027890 | 2.716327e-01 | 0.025370 | [-0.07761469315900867, 0.02183503775561164] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.drop([1890, 1990], axis=1, inplace=True)
table
cohort10 | 1900.0 | 1910.0 | 1920.0 | 1930.0 | 1940.0 | 1950.0 | 1960.0 | 1970.0 | 1980.0 |
---|---|---|---|---|---|---|---|---|---|
year5 | |||||||||
1972.0 | 34.267242 | 30.633286 | 29.767441 | 32.388664 | 36.608067 | 44.305771 | NaN | NaN | NaN |
1977.0 | 26.018806 | 28.625954 | 30.555555 | 29.713425 | 31.691650 | 41.490341 | 51.648354 | NaN | NaN |
1982.0 | 22.222223 | 36.336334 | 33.178654 | 31.724136 | 31.516186 | 38.645981 | 54.068245 | NaN | NaN |
1987.0 | 23.076923 | 27.327934 | 32.603092 | 34.659821 | 31.693077 | 37.646198 | 51.465797 | 40.277779 | NaN |
1992.0 | 8.955224 | 26.666668 | 25.373135 | 33.936653 | 32.440056 | 35.959595 | 49.079090 | 53.592812 | NaN |
1997.0 | 24.000000 | 31.176472 | 26.972012 | 32.717190 | 33.150383 | 41.517128 | 39.137508 | 53.823818 | 40.860214 |
2002.0 | NaN | 10.714286 | 27.619049 | 34.722221 | 36.862747 | 28.992630 | 40.345821 | 46.239555 | 63.698631 |
2007.0 | NaN | 23.333334 | 33.333336 | 27.217125 | 27.927929 | 40.703518 | 38.079094 | 45.905418 | 50.872822 |
2012.0 | NaN | NaN | 12.068965 | 24.293785 | 30.630630 | 37.717602 | 40.986397 | 41.061947 | 47.500000 |
2017.0 | NaN | NaN | 17.241379 | 23.611111 | 33.333336 | 32.389381 | 40.000000 | 41.903172 | 48.101269 |
visualize(series_all, table)
plt.title('')
title = """Do you think the use of marijuana should be made legal or not?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "No legal"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Birth decade', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('grass_vs_year_by_cohort10.jpg')
Please tell me whether or not you think it should be possible for a pregnant woman to obtain a legal abortion if she is married and does not want any more children?
xvarname = 'year'
yvarname = 'abnomore'
gvarname = 'degree5'
yvalue = 1
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | 0.001087 | 1.125147e-01 | 0.000685 | [-0.0002553661356612109, 0.002428518308773977] |
Bachelor | -0.007197 | 1.408424e-04 | 0.001891 | [-0.010902896392419013, -0.003491560224995832] |
Graduate | -0.003035 | 2.664773e-01 | 0.002731 | [-0.008388718933076215, 0.0023183130679895665] |
High school | -0.004824 | 5.901322e-07 | 0.000966 | [-0.006717657373921055, -0.0029311627462750072] |
Junior college | -0.005357 | 1.051011e-01 | 0.003305 | [-0.011835141107864013, 0.0011216886119192592] |
Less than high school | -0.005804 | 6.186059e-04 | 0.001695 | [-0.009126510318211626, -0.0024808930384135324] |
xvarname = 'year'
yvarname = 'abnomore'
gvarname = 'degree5'
yvalue = 1
pre2002 = gss['year'] <= 2002
run_subgroups(gss[pre2002].copy(), xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | -0.003790 | 2.351366e-03 | 0.001246 | [-0.006231733743745992, -0.0013479066579696942] |
Bachelor | -0.017306 | 1.992308e-06 | 0.003640 | [-0.02444058458187502, -0.010171453047968702] |
Graduate | -0.015681 | 4.433129e-03 | 0.005511 | [-0.02648156251583954, -0.004880278427213492] |
High school | -0.010132 | 4.905516e-09 | 0.001732 | [-0.013526278301109883, -0.006737554537518539] |
Junior college | -0.025549 | 7.390727e-05 | 0.006446 | [-0.03818363759624023, -0.012914460628362566] |
Less than high school | -0.012809 | 8.673247e-06 | 0.002880 | [-0.018453559931449825, -0.007164752017908858] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.sort_values(by=2017, axis=1, ascending=False, inplace=True)
table
degree5 | Graduate | Bachelor | Junior college | High school | Less than high school |
---|---|---|---|---|---|
year5 | |||||
1972.0 | 66.521744 | 64.489792 | 65.909096 | 48.397213 | 33.031456 |
1977.0 | 71.713150 | 59.868420 | 51.369865 | 47.039143 | 35.184166 |
1982.0 | 65.161285 | 60.095387 | 49.814125 | 41.382488 | 29.060326 |
1987.0 | 66.535431 | 57.009346 | 39.170506 | 40.535145 | 28.598484 |
1992.0 | 58.483757 | 56.616413 | 50.239235 | 46.364494 | 27.201260 |
1997.0 | 62.796829 | 53.030300 | 42.239185 | 40.330349 | 27.013630 |
2002.0 | 60.975613 | 46.540878 | 40.909092 | 40.782700 | 27.966103 |
2007.0 | 63.120567 | 48.463688 | 42.553192 | 40.812798 | 29.347824 |
2012.0 | 65.862068 | 61.657036 | 50.678738 | 41.760563 | 29.756100 |
2017.0 | 66.230370 | 56.739815 | 48.547718 | 44.581860 | 31.435644 |
visualize(series_all, table)
plt.title('')
title = """Do you think it should be possible for a pregnant woman to obtain
a legal abortion if she is married and does not want any more children?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying yes')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Highest degree', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('abnomore_vs_year_by_degree.jpg')
Suppose an admitted Communist wanted to make a speech in your community. Should he be allowed to speak, or not?
xvarname = 'year'
yvarname = 'spkcom'
gvarname = 'degree5'
yvalue = 1
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | 0.014292 | 5.678844e-79 | 0.000760 | [0.012803253681013845, 0.0157808503460148] |
Bachelor | 0.002997 | 2.818237e-01 | 0.002785 | [-0.0024609126971154053, 0.008454834831469148] |
Graduate | 0.007417 | 8.523145e-02 | 0.004309 | [-0.0010293443646586095, 0.01586340838257216] |
High school | 0.004062 | 1.179069e-04 | 0.001055 | [0.0019943791836820293, 0.0061297568942805525] |
Junior college | -0.004073 | 3.115858e-01 | 0.004025 | [-0.011960826181515005, 0.0038156611943626385] |
Less than high school | 0.006822 | 3.189803e-05 | 0.001640 | [0.0036074539209238364, 0.01003659248511412] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.sort_values(by=2017, axis=1, ascending=False, inplace=True)
table
degree5 | Graduate | Bachelor | Junior college | High school | Less than high school |
---|---|---|---|---|---|
year5 | |||||
1972.0 | 83.419685 | 87.431694 | 82.352943 | 66.939888 | 39.827374 |
1977.0 | 82.631577 | 83.514099 | 82.692307 | 60.303982 | 37.187721 |
1982.0 | 95.121948 | 80.652168 | 69.430054 | 58.449860 | 39.844357 |
1987.0 | 88.846153 | 87.722420 | 69.469032 | 62.519623 | 44.380402 |
1992.0 | 87.328766 | 84.853424 | 79.166672 | 69.074074 | 48.183254 |
1997.0 | 91.948051 | 83.914513 | 71.820450 | 64.413055 | 40.149628 |
2002.0 | 89.696968 | 88.379204 | 71.333328 | 69.547737 | 45.147678 |
2007.0 | 87.954544 | 84.856758 | 71.818176 | 65.567451 | 43.650795 |
2012.0 | 87.162163 | 87.269371 | 69.361702 | 63.488697 | 42.821159 |
2017.0 | 91.304352 | 85.648148 | 76.543213 | 67.063728 | 48.195877 |
visualize(series_all, table)
plt.title('')
title = """Suppose an admitted Communist wanted to make a speech in your community.
Should he be allowed to speak, or not?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "allowed"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Highest degree', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('spkcom_vs_year_by_degree.jpg')
There are always some people whose ideas are considered bad or dangerous by other people. For instance, somebody who is against all churches and religion . . .
If some people in your community suggested that a book he wrote against churches and religion should be taken out of your public library, would you favor removing this book, or not?
xvarname = 'year'
yvarname = 'libath'
gvarname = 'degree5'
yvalue = 2
run_subgroups(gss, xvarname, yvarname, gvarname, yvalue)
param | pvalue | stderr | conf_inf | |
---|---|---|---|---|
all | 0.020020 | 1.155318e-139 | 0.000796 | [0.018460663867511762, 0.02158008662287882] |
Bachelor | 0.002794 | 3.329208e-01 | 0.002886 | [-0.00286207320822676, 0.008450756301191506] |
Graduate | -0.001364 | 7.914382e-01 | 0.005156 | [-0.011469777270686371, 0.008742661551919181] |
High school | 0.011170 | 8.864263e-24 | 0.001111 | [0.008992540105935186, 0.013347869961416787] |
Junior college | 0.000880 | 8.409281e-01 | 0.004385 | [-0.0077151502305467376, 0.009475530326046725] |
Less than high school | 0.014161 | 1.835754e-18 | 0.001615 | [0.010995416516936413, 0.017327331504967836] |
series_all, table = summarize(gss, xvarname, yvarname, gvarname, yvalue)
table.sort_values(by=2017, axis=1, ascending=False, inplace=True)
table
degree5 | Graduate | Bachelor | Junior college | High school | Less than high school |
---|---|---|---|---|---|
year5 | |||||
1972.0 | 87.628868 | 88.461533 | 82.692307 | 69.604721 | 43.528694 |
1977.0 | 93.617020 | 85.097191 | 87.000000 | 67.314651 | 43.555241 |
1982.0 | 94.715446 | 83.842796 | 78.787880 | 64.505676 | 39.176830 |
1987.0 | 95.312500 | 90.072205 | 76.521736 | 67.649399 | 48.803825 |
1992.0 | 92.068962 | 87.027916 | 82.159630 | 67.964348 | 48.275860 |
1997.0 | 90.837700 | 83.617744 | 74.242424 | 71.018456 | 49.007446 |
2002.0 | 95.092026 | 85.046730 | 88.387093 | 72.154472 | 52.479340 |
2007.0 | 93.197281 | 84.196182 | 75.510201 | 73.533188 | 53.894077 |
2012.0 | 92.229729 | 89.776955 | 85.281387 | 76.361130 | 50.859951 |
2017.0 | 90.816322 | 88.632874 | 80.241936 | 77.505829 | 63.592232 |
visualize(series_all, table)
plt.title('')
title = """If people object to a book by someone who is opposed to
churches and religion, should it be removed from a public library, or not?
"""
plt.title(title, loc='left', fontdict=dict(fontsize=14))
plt.ylabel('Percent saying "not removed"')
plt.xlabel('Year')
x = y = 1.02
plt.legend(title='Highest degree', bbox_to_anchor=(x, y), loc='upper left', ncol=1)
plt.tight_layout()
plt.savefig('libath_vs_year_by_degree.jpg')