Skip to content

Instantly share code, notes, and snippets.

@makmanalp
Created April 5, 2017 16:09
Show Gist options
  • Save makmanalp/833d2497726a2a71e992056c78fd5032 to your computer and use it in GitHub Desktop.
Save makmanalp/833d2497726a2a71e992056c78fd5032 to your computer and use it in GitHub Desktop.
STATA fillin in pandas
def fillin(df, entities):
"""STATA style 'fillin', makes sure all combinations of entities in the
index are in the dataset."""
return df\
.set_index(entities)\
.reindex(pd.MultiIndex.from_product(df.index.levels, names=df.index.names))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment