make_data_square
Function
gme.make_data_square(trade_dataframe=None, imp_var_name: str = "importer", exp_var_name: str = "exporter", multiple_sectors: bool = False, sector_var_name: str = None, year_var_name: str = "year", drop_intratrade: bool = True, year_by_year: bool = True):
Description
Expand countries and sectors by adding zero-valued trade flows to make the panel square.
Arguments
- trade_dataframe: pd.DataFrame
A DataFrame containing trade values and observation identifiers (importer, exporter, year, and (optionally) sector).
The name of the column containing importer identifiers.
The name of the column containing exporter identifiers.
- multiple_sectors: bool
If true, the data is squared for each sector as well. Default is False.
- sector_var_name: (optional) str
The name of the column containing sector identifiers. Must be supplied if squaring for each section (i.e. if multiple_sectors = True).
- year_var_name: (optional) str
The name of the column containing year identifiers.
- drop_intratrade: bool
If True, the returned data will not contain intranational observations in which the importer and exporter are the same country. Default is True.
- year_by_year: bool
If true, the data is squared on a year by year basis, which allows the dimensions to differ each year. For example, it lets the set of countries or sectors around which the data is squared to differ each year. Doing so reduces the likelihood of including countries or sectors with zero trade activity in certain years.
## Returns
Returns: Pandas.DataFrame
A square dataset.
## Examples
>>> raw_data = pd.read_csv('https://www.usitc.gov/data/gravity/example_trade_and_grav_data_small.csv')
>>> trade_data = raw_data[['importer', 'exporter', 'year', 'trade_value']]
>>> square_data = make_data_square(trade_data, imp_var_name='importer', exp_var_name='exporter',
multiple_sectors=False, year_var_name='year',
drop_intratrade=False, year_by_year=True)