I have a panel data frame with dimensions in multi-index: country and year. For each country in level = 0 of the index, I want to divide (or subtract) some variable from the United States only.
In pseudo code
for country in countries_in_level0:
Data[‘new_variable’][country] = Data[‘variable’][country] - Data[‘variable’][‘United States’]
What I tried to do is
Data[‘new_variable’] = Data[‘variable’] - Data[‘variable’].loc[‘United States’, :]
But I get NaN in for every country but the United States