Skip to contents

This function opens the ComexStat NCM (8-digit product code) trade data as an Arrow Dataset. The data is assumed to be located in the ComexStat data directory and to have been downloaded and processed using the comex_download() function.

Usage

comex_ncm()

Value

An Arrow Dataset containing combined import and export NCM trade data, with an additional direction column indicating 'exp' (export) or 'imp' (import). The dataset has the following columns:

  • year: Year (integer)

  • month: Month (integer)

  • ncm: 8-digit NCM product code (string)

  • unit_code: Unit of measurement code (integer)

  • country_code: Country code (integer)

  • state_abb: Brazilian state abbreviation (string)

  • transp_mode_code: Transportation mode code (integer)

  • urf_code: Customs clearance unit code (integer)

  • qt_stat: Statistical quantity (integer64)

  • kg_net: Net weight in kilograms (integer64)

  • fob_usd: FOB value in US dollars (integer64)

  • freight_usd: Freight value in US dollars (integer64, only for imports)

  • insurance_usd: Insurance value in US dollars (integer64, only for imports)

  • direction: Trade direction, either 'exp' (export) or 'imp' (import) (derived)

Examples

if (FALSE) { # \dontrun{
library(dplyr)
# Open the ComexStat NCM dataset:
ncm_dataset <- comex_ncm()

# Explore the dataset:
print(ncm_dataset)
ncm_dataset|>group_by(year, direction)|>summarise(fob_usd=sum(fob_usd), freight_usd=sum(freight_usd))|>mutate(p=freight_usd/fob_usd)|>collect()
comex_ncm()|>group_by(country_code)|>summarise(fob_usd=sum(fob_usd, na.rm=TRUE), freight_usd=sum(freight_usd))|>mutate(p=freight_usd/fob_usd)|>arrange(desc(p))|>collect()
} # }