def StdDed(DSI, earned, STD, age_head, age_spouse, STD_Aged, STD_Dep,
           MARS, MIDR, blind_head, blind_spouse, standard, c19700,
           STD_allow_charity_ded_nonitemizers):
    """
    Calculates standard deduction, including standard deduction for
    dependents, aged and bind.

    Notes
    -----
    Tax Law Parameters:
        STD : Standard deduction amount, filing status dependent

        STD_Dep : Standard deduction for dependents

        STD_Aged : Additional standard deduction for blind and aged

    Taxpayer Characteristics:
        earned : Form 2441 earned income amount

        e02400 : Gross Social Security Benefit

        DSI : Dependent Status Indicator:
            0 - not being claimed as a dependent
            1 - claimed as a dependent

        MIDR : Married filing separately itemized deductions
        requirement indicator:
            0 - not necessary to itemize because of filing status
            1 - necessary to itemize when filing separately

    Returns
    -------
    standard : the standard deduction amount for filing unit
    """
    # calculate deduction for dependents
    if DSI == 1:
        c15100 = max(350. + earned, STD_Dep)
        basic_stded = min(STD[MARS - 1], c15100)
    else:
        c15100 = 0.
        if MIDR == 1:
            basic_stded = 0.
        else:
            basic_stded = STD[MARS - 1]
    # calculate extra standard deduction for aged and blind
    num_extra_stded = blind_head + blind_spouse
    if age_head >= 65:
        num_extra_stded += 1
    if MARS == 2 and age_spouse >= 65:
        num_extra_stded += 1
    extra_stded = num_extra_stded * STD_Aged[MARS - 1]
    # calculate the total standard deduction
    standard = basic_stded + extra_stded
    if MARS == 3 and MIDR == 1:
        standard = 0.
    if STD_allow_charity_ded_nonitemizers:
        standard += c19700
    return standard