def clean_stockchosen(row):
    """
    INtended for use with DataFrame.apply()

    Composes a boolean 'stockchosen' column from atomic indicators:

    - Whether the stock was on the left or right side of the screen
    - Which button was pressed at selection (left or right)
    """
    if int(row['study']) >= 3:
        if row['selection'] == 1:
            # chose option left
            if row['stockfractallocationtype'] == 'L':
                # stock was on left 
                # row['stockchosen'] = 1
                return 1
            elif row['stockfractallocationtype'] == 'R':
                # stock was on right
                # row['stockchosen'] = 0
                return 0
        elif row['selection'] == 0:
            # chose option right
            if row['stockfractallocationtype'] == 'R':
                # stock was on right
                # row['stockchosen'] = 1
                return 1
            elif row['stockfractallocationtype'] == 'L':
                # stock was on left
                # row['stockchosen'] = 0
                return 0
    else:
        if row['stockchosen'] == 'stock':
            return 1
        elif row['stockchosen'] == 'bond':
            return 0