Created
April 5, 2017 16:09
-
-
Save makmanalp/833d2497726a2a71e992056c78fd5032 to your computer and use it in GitHub Desktop.
STATA fillin in pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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