Inference and Gender Gaps

Inference and Gender Gaps#

Allen Downey

MIT License

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
gss = pd.read_hdf('gss_feminism_2022.hdf', key='gss')

Here are the 10 fe variables and the text of the questions.

fechld

A. A working mother can establish just as warm and secure a relationship with her children as a mother who does not work.

fefam

D. It is much better for everyone involved if the man is the achiever outside the home and the woman takes care of the home and family.

fehelp

B. It is more important for a wife to help her husband’s career than to have one herself.

fehire

Because of past discrimination, employers should make special efforts to hire and promote qualified women.

fehome

Women should take care of running their homes and leave running the country up to men.

fejobaff

Some people say that because of past discrimination, women should be given preference in hiring and promotion. Others say that such preference in hiring and promotion of women is wrong because it discriminates against men. What about your opinion - are you for or against preferential hiring and promotion of women? IF FOR:Do you favor preference in hiring and promotion strongly or not strongly? IF AGAINST:Do you oppose preference in hiring and promotion strongly or not strongly?

fepol

A. Tell me if you agree or disagree with this statement: Most men are better suited emotionally for politics than are most women.

fepres

If your party nominated a woman for President, would you vote for her if she were qualified for the job?

fepresch

C. A preschool child is likely to suffer if his or her mother works.

fework

Do you approve or disapprove of a married woman earning money in business or industry if she has a husband capable of supporting her?

fe_columns = [x for x in gss.columns if x.startswith('fe')]
fe_columns
['fechld',
 'fefam',
 'fehelp',
 'fehire',
 'fehome',
 'fejobaff',
 'fepol',
 'fepres',
 'fepresch',
 'fework']
from utils import decorate

grouped = gss.groupby('year')
intervals = pd.DataFrame(columns=['first', 'last', '# years'], dtype=int)

for column in fe_columns:
    counts = grouped[column].count()
    nonzero = counts.replace(0, np.nan).dropna()
    n_years = len(nonzero)
    first, last = nonzero.index.min(), nonzero.index.max()
    intervals.loc[column] = first, last, n_years
intervals
first last # years
fechld 1977 2022 23
fefam 1977 2022 23
fehelp 1977 1998 11
fehire 1996 2022 13
fehome 1974 1998 16
fejobaff 1996 2022 13
fepol 1974 2022 27
fepres 1972 2010 19
fepresch 1977 2022 23
fework 1972 1998 17
current_columns = intervals.query('last==2022').index.values
current_columns
array(['fechld', 'fefam', 'fehire', 'fejobaff', 'fepol', 'fepresch'],
      dtype=object)

For each variable, I’ll select “agree” and “strongly agree”, except for fework, where I’ve selected “approve”.

agree_responses = {
    'fechld': [1, 2],
    'fefam': [1, 2],
    'fehelp': [1, 2],
    'fehire': [1, 2],
    'fehome': [1],
    'fejobaff': [1, 2],
    'fepol': [1],
    'fepres': [1],
    'fepresch': [1, 2],
    'fework': [1],
}
def make_series_weighted(data, query, column):
    """
    """
    def weighted_fraction(group):
        responses = group[column].isin(agree_responses[column])
        weights = group['wtssall']
        fraction = (responses * weights).sum() / weights.sum()
        return fraction

    subset = data.query(query).dropna(subset=[column, 'wtssall'])
    series = subset.groupby('year').apply(weighted_fraction, include_groups=False)
    return series * 100
queries = ['sex==1 & age<30', 'sex==1 & age>=30', 
           'sex==2 & age<30', 'sex==2 & age>=30']

colors = ['C0', 'C0', 'C1', 'C1']
styles = ['-', '--', '-', '--']
short_labels = ['M<30', 'M≥30', 'F<30', 'F≥30']
long_labels = ['Male <30', 'Male ≥30', 'Female <30', 'Female ≥30']
from utils import make_lowess

def plot_weighted(query, column, smooth=False, **options):
    """
    """
    label = options.pop('label', '')
    ls = options.pop('ls', '-')
    series = make_series_weighted(gss, query, column)
    if smooth:
        if label == 'M<30':
            plt.plot(series.index, series.values, '.', alpha=0.4, **options)
        smooth = make_lowess(series)
        xs, ys = smooth.index, smooth.values
    else:
        xs, ys = series.index, series.values

    plt.plot(xs, ys, alpha=0.6, ls=ls, **options)

    offset = adjust_map.get((column, label), 0)
    x = xs[0] - 0.5
    y = ys[0] + offset
    plt.text(x, y, label, ha='right', va='center')
def plot_four_series_weighted(column, smooth=False):
    for i, query in enumerate(queries):
        options = dict(color=colors[i], ls=styles[i], label=short_labels[i])
        plot_weighted(query, column, smooth, **options)
            
    decorate(ylabel='Percent agree', 
             xlim=[1971, 2023])

Plot without smoothing#

adjust_map = {('fejobaff', 'M<30'): -1.3,
              ('fejobaff', 'M≥30'): -0.3,
              ('fepol', 'F≥30'): 1,
             ('fehire', 'F≥30'): -0.5,
             }

smooth = False
title = """A working mother can establish just as warm and secure a
relationship with her children as a mother who does not work
"""
plot_four_series_weighted('fechld', smooth=smooth)
plt.title(title, loc='left');
_images/4e85493b0c50f98991ae339b142d3b6e2e4eec3e19dbf632bfd0b16d423d5372.png
title = """It is much better for everyone involved if the man is the achiever 
outside the home and the woman takes care of the home and family
"""
plot_four_series_weighted('fefam', smooth=smooth)
plt.title(title, loc='left');
_images/bff92f4433165b4d85913eb9a18edd432f74cb02aa6196e750f084f452b3aa58.png
title = """Because of past discrimination, employers should make 
special efforts to hire and promote qualified women
"""
plot_four_series_weighted('fehire', smooth=smooth)
plt.title(title, loc='left');
_images/ff709d62614cd0a432698844d7abcc76efefc6dd3cc7e9b089aea08ad831510f.png
title = """Some people say that because of past discrimination, 
women should be given preference in hiring and promotion. 
Others say that such preference in hiring and promotion of 
women  is wrong because it discriminates against men. 
What about your opinion - are you for or against 
preferential hiring and promotion of women?
"""
plot_four_series_weighted('fejobaff', smooth=smooth)
plt.title(title, loc='left')
plt.ylabel('Percent in favor');
_images/0e1b28a84deeaaa8ac6fde40431ae26dbf72be46b01a84362e589a55d2ac2937.png
title = """Most men are better suited emotionally
for politics than are most women
"""
plot_four_series_weighted('fepol', smooth=smooth)
plt.title(title, loc='left')
plt.xlim([1968, 2023]);
_images/daed0fcab3a965ec249546cb3e10c3f479aed361921a61f7714451afc9e6766e.png
title = """A preschool child is likely to suffer if his or her mother works
"""
plot_four_series_weighted('fepresch', smooth=smooth)
plt.title(title, loc='left');
_images/5ee38465552a19aa7f8f96600a9fa85c41bcd80ca7d48813383521fd592615cd.png

Plot with smoothing#

adjust_map = {('fepresch', 'F≥30'): -1,
             ('fepresch', 'M<30'): 1,
             ('fejobaff', 'M<30'): -0.5,
             }

smooth = True
title = """A working mother can establish just as warm and secure a
relationship with her children as a mother who does not work
"""
plot_four_series_weighted('fechld', smooth=smooth)
plt.title(title, loc='left');
_images/51e630fc51f3f99278529c6d2cf566599f0dbeecf1ce626ec528e949e31e21a3.png
title = """It is much better for everyone involved if the man is the achiever 
outside the home and the woman takes care of the home and family
"""
plot_four_series_weighted('fefam', smooth=smooth)
plt.title(title, loc='left');
_images/74c0f03750aaa940dfb5db7132b97cfafb96451482f701056b72b0e6b0a05e33.png
title = """Because of past discrimination, employers should make 
special efforts to hire and promote qualified women
"""
plot_four_series_weighted('fehire', smooth=smooth)
plt.title(title, loc='left');
_images/c4a3a963ff006649839406707d55be6f6bf483840c0ebb4d588c3d85c66de67d.png
title = """Some people say that because of past discrimination, 
women should be given preference in hiring and promotion. 
Others say that such preference in hiring and promotion of 
women  is wrong because it discriminates against men. 
What about your opinion - are you for or against 
preferential hiring and promotion of women?
"""
plot_four_series_weighted('fejobaff', smooth=smooth)
plt.title(title, loc='left')
plt.ylabel('Percent in favor');
_images/0b5d0a5545dc75a488f6be538886c2afad507e57b3d7ab7b2c328b8595805586.png
title = """Most men are better suited emotionally
for politics than are most women
"""
plot_four_series_weighted('fepol', smooth=smooth)
plt.title(title, loc='left')
plt.xlim([1968, 2023]);
_images/a545f03e08bd48ff156f87d56a0cf16dcc26fb82991bb0d763e906ba7029c7a7.png
title = """A preschool child is likely to suffer if his or her mother works
"""
plot_four_series_weighted('fepresch', smooth=smooth)
plt.title(title, loc='left');
_images/1b8c6e236c404e9f76f084cb2bf189827ed803b840e3b98f4808aea9e4217c45.png