How to translate iTable tables to API queries¶
This guide shows how to translate the process of getting data from various iTables searches to using the API. We do this for each of the datasets.
General info¶
Note that for some scenarios it may take several API queries to generate the data for a single iTables table. Also, in the examples below we often search for a target parameter by a string value in a table. You can always export the table of possibilities to spreadsheet to view the whole thing (e.g., tbl.to_csv("fname.csv", index=False)
)
We first need to figure out what dataset to pull from. Here’s roughly how the “tabs” on the iTables web page map to the different API datasets:
“(National Data) GDP & Personal Income” -> [NIPA, NIUnderlyingDetail]
“Fixed Assets” -> FixedAssets
“GDP by Industry” -> [GDPbyIndustry, UnderlyingGDPbyIndustry]
“Input-Output” -> InputOutput
“Int’l Transactions, Services, & IIP” -> [IntlServTrade, ITA, IIP]
“Direct Investments & MNEs” -> MNE
“(Regional Data) GDP & Personal Income” -> Regional
Other resources¶
While we show one method here, there are some other resources that may be helpful:
search_metadata()
can be be used for ‘FixedAssets’, ‘NIPA’, ‘NIUnderlyingDetail’.NIPA web resources: Table Title to TableID, Series Details to Series Code, NIPA keywords
Fixed Assets web resources: Table Register, Series Register,
Regional API PDF has table mapping
Setup¶
[1]:
import beaapi
import pandas as pd
pd.set_option('display.max_colwidth', None) # show all text in cells
[2]:
# Get key from unversioned file
import os
from dotenv import load_dotenv
load_dotenv()
beakey = os.environ.get("beakey")
Code utilities¶
We define here a few tools to be use below
[9]:
# Get some basic Meta-data. What are the table names?
datasets_info = beaapi.get_data_set_list(beakey)
dataset_names = list(datasets_info['DatasetName'])
param_infos = {dataset_name: beaapi.get_parameter_list(beakey, dataset_name) for dataset_name in dataset_names}
Make a function get_table_param_from_desc()
to ease getting table IDs from descriptions
[10]:
# Tools to help lookup table IDs from table descriptions
table_var = {'NIPA':'TableName',
'NIUnderlyingDetail':'TableName',
'MNE':None,
'FixedAssets': 'TableName',
'ITA':None,
'IIP':None,
'InputOutput':"TableID",
'IntlServTrade':None,
'GDPbyIndustry':"TableID",
'Regional': "TableName",
'UnderlyingGDPbyIndustry':"TableID"}
table_param_desc = {'NIPA':'Description',
'NIUnderlyingDetail':'Description',
'MNE':None,
'FixedAssets': 'Description',
'ITA':None,
'IIP':None,
'InputOutput':"Desc",
'IntlServTrade':None,
'GDPbyIndustry':"Desc",
'Regional': "Desc",
'UnderlyingGDPbyIndustry':"Desc"}
table_names = {}
for dataset_name, table_var_name in table_var.items():
if table_var_name is not None:
table_names[dataset_name] = beaapi.get_parameter_values(beakey, dataset_name, table_var_name)
def get_table_param_from_desc(dataset_name, desc):
mask = table_names[dataset_name][table_param_desc[dataset_name]].str.contains(desc)
results = table_names[dataset_name][mask]
table_var_name = table_var[dataset_name]
return table_var_name, results
How to build query from iTables¶
National Data - GDP & Personal Income¶
NIPA (publication category “GDP and Personal Income”, default)¶
First, let’s take as example table the first one on the web page and describe what we do have
[39]:
# Example
desc = "Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product"
freq = "Q"
year = "2019" # input as string
Then let’s see what we need to build the query
[40]:
display(param_infos["NIPA"])
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | Frequency | string | A - Annual, Q-Quarterly, M-Monthly | 1 | 1 | ||
1 | ShowMillions | string | A flag indicating that million-dollar data sho... | 0 | N | 0 | |
2 | TableID | integer | The standard NIPA table identifier | 0 | <NA> | 0 | |
3 | TableName | string | The new NIPA table identifier | 0 | <NA> | 0 | |
4 | Year | integer | List of year(s) of data to retrieve (X for All) | 1 | 1 | X |
Note, we actually need exactly 1 of TableID or TableName. (They transitioned to TableName, but keep TableID around for compatibility.)
Next let’s find the TableName from the description.
[41]:
table_param_name, table_param_vals = get_table_param_from_desc("NIPA", desc)
display(table_param_vals)
print("We'll use that one")
table_param_val = table_param_vals.iloc[0,0]
TableName | Description | |
---|---|---|
0 | T10101 | Table 1.1.1. Percent Change From Preceding Per... |
We'll use that one
Finally, let’s get the data.
[42]:
tbl = beaapi.get_data(beakey, "NIPA", TableName=table_param_val, Frequency=freq, Year=year)
tbl.head()
[42]:
TableName | SeriesCode | LineNumber | LineDescription | TimePeriod | METRIC_NAME | CL_UNIT | UNIT_MULT | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|
0 | T10101 | A191RL | 1 | Gross domestic product | 2019Q1 | Fisher Quantity Index | Percent change, annual rate | 0 | 2.4 | T10101 |
1 | T10101 | A191RL | 1 | Gross domestic product | 2019Q2 | Fisher Quantity Index | Percent change, annual rate | 0 | 3.2 | T10101 |
2 | T10101 | A191RL | 1 | Gross domestic product | 2019Q3 | Fisher Quantity Index | Percent change, annual rate | 0 | 2.8 | T10101 |
3 | T10101 | A191RL | 1 | Gross domestic product | 2019Q4 | Fisher Quantity Index | Percent change, annual rate | 0 | 1.9 | T10101 |
4 | T10101 | DPCERL | 2 | Personal consumption expenditures | 2019Q1 | Fisher Quantity Index | Percent change, annual rate | 0 | 0.6 | T10101 |
NIUnderlyingDetail (Publication Category “Underlying Details”, non-default)¶
[12]:
# Info from iTables
desc = "Table 1AU. Real Manufacturing and Trade Inventories, Seasonally Adjusted, End of Period" # Note: have to cut off final "[Chained 1996 dollars, 1967-96, SIC]" to get it to match
freq="Q"
year="1995"
print("What parameters are needed")
display(param_infos["NIUnderlyingDetail"])
What parameters are needed
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | Frequency | string | A - Annual, Q-Quarterly, M-Monthly | 1 | 1 | ||
1 | TableID | integer | The standard NI underlying detail table identi... | 0 | <NA> | 0 | |
2 | TableName | string | The new NIPA table identifier | 0 | <NA> | 0 | |
3 | Year | integer | List of year(s) of data to retrieve (X for All) | 1 | 1 | X |
Get tablename from iTable’s table description from web
[13]:
table_param_name, table_param_vals = get_table_param_from_desc("NIUnderlyingDetail", desc)
display(table_param_vals)
print("That one looks good.")
table_param_val = table_param_vals.iloc[0,0]
What TableName matches?
TableName | Description | |
---|---|---|
0 | U001A | Table 1AU. Real Manufacturing and Trade Invent... |
Next, get data.
[14]:
tbl = beaapi.get_data(beakey, "NIUnderlyingDetail", TableName=table_param_val, Frequency=freq, Year=year)
tbl.head()
[14]:
TableName | SeriesCode | LineNumber | LineDescription | TimePeriod | METRIC_NAME | CL_UNIT | UNIT_MULT | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|
0 | U001A | KSTMT | 1 | Manufacturing and trade | 1995Q1 | Chained Dollars | Level | 6 | 973434 | U001A |
1 | U001A | KSTMT | 1 | Manufacturing and trade | 1995Q2 | Chained Dollars | Level | 6 | 984218 | U001A |
2 | U001A | KSTMT | 1 | Manufacturing and trade | 1995Q3 | Chained Dollars | Level | 6 | 991162 | U001A |
3 | U001A | KSTMT | 1 | Manufacturing and trade | 1995Q4 | Chained Dollars | Level | 6 | 994259 | U001A |
4 | U001A | KSTM | 2 | Manufacturing | 1995Q1 | Chained Dollars | Level | 6 | 410079 | U001A |
[10]:
# Unsure how to access Publication category "Additional Tables"
# desc="FWPI-1. Fixed-Weighted Price Indexes"
# Both methods fail:
#search_result = beaapi.search_metadata(desc, beakey)
#display(search_result)
#table_param_name, table_param_vals = get_table_param_from_desc("NIPA", desc) #Tried with NIUnderlyingDetail
#display(table_param_vals)
National Data - Fixed Assets¶
FixedAssets¶
[22]:
# Info from iTable
desc = "Table 1.1. Current-Cost Net Stock of Fixed Assets and Consumer Durable Goods"
year="2013"
First, what parameters are needed?
[18]:
display(param_infos["FixedAssets"])
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | TableName | string | The new Fixed Assets identifier | 1 | 0 | ||
1 | Year | integer | List of year(s) of data to retrieve (X for All) | 1 | 1 | X |
Get tablename from iTable’s table description from web
[24]:
table_param_name, table_param_vals = get_table_param_from_desc("FixedAssets", desc)
display(table_param_vals)
print("That one looks good")
table_param_val = table_param_vals.iloc[0,0]
TableName | Description | |
---|---|---|
0 | FAAt101 | Table 1.1. Current-Cost Net Stock of Fixed Ass... |
Get data
[25]:
tbl = beaapi.get_data(beakey, "FixedAssets", TableName=table_param_val, Year=year)
tbl.head()
[25]:
TableName | SeriesCode | LineNumber | LineDescription | TimePeriod | METRIC_NAME | CL_UNIT | UNIT_MULT | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|
0 | FAAt101 | k1wtotl1es00 | 1 | Fixed assets and consumer durable goods | 2013 | Current Dollars | Level | 9 | 56290.3 | FAAt101 |
1 | FAAt101 | k1ttotl1es00 | 2 | Fixed assets | 2013 | Current Dollars | Level | 9 | 51510.7 | FAAt101 |
2 | FAAt101 | k1ptotl1es00 | 3 | Private | 2013 | Current Dollars | Level | 9 | 38567.6 | FAAt101 |
3 | FAAt101 | k1ntotl1es00 | 4 | Nonresidential | 2013 | Current Dollars | Level | 9 | 21073.3 | FAAt101 |
4 | FAAt101 | k1ntotl1eq00 | 5 | Equipment | 2013 | Current Dollars | Level | 9 | 5897.2 | FAAt101 |
Industry Data¶
GDPbyIndustry (Publication category “GDP-by-Industry”, a default)¶
[28]:
# Info from iTable
desc = "Value Added by Industry"
year="2019"
freq="Q"
industries = "ALL" # from iTable
First, what parameters are needed?
[29]:
display(param_infos["GDPbyIndustry"])
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | Frequency | string | A - Annual, Q-Quarterly | 1 | 1 | ALL | |
1 | Industry | string | List of industries to retrieve (ALL for All) | 1 | 1 | ALL | |
2 | TableID | integer | The unique GDP by Industry table identifier (A... | 1 | 1 | ALL | |
3 | Year | integer | List of year(s) of data to retrieve (ALL for All) | 1 | 1 | ALL |
Get tablename
[30]:
table_param_name, table_param_vals = get_table_param_from_desc("GDPbyIndustry", desc)
display(table_param_vals)
print("That first one looks right.")
table_param_val = table_param_vals.iloc[0,0]
What TableName matches?
Key | Desc | |
---|---|---|
0 | 1 | Value Added by Industry (A) (Q) |
2 | 6 | Components of Value Added by Industry (A) |
3 | 7 | Components of Value Added by Industry as a Per... |
4 | 8 | Chain-Type Quantity Indexes for Value Added by... |
5 | 9 | Percent Changes in Chain-Type Quantity Indexes... |
6 | 10 | Real Value Added by Industry (A) (Q) |
7 | 11 | Chain-Type Price Indexes for Value Added by In... |
8 | 12 | Percent Changes in Chain-Type Price Indexes fo... |
Get data
[31]:
tbl = beaapi.get_data(beakey, "GDPbyIndustry", TableID=table_param_val, Year=year, Frequency=freq, Industry=industries)
tbl.head()
[31]:
TableID | Frequency | Year | Quarter | Industry | IndustrYDescription | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|
0 | 1 | Q | 2019 | I | 11 | Agriculture, forestry, fishing, and hunting | 159.7 | 1 |
1 | 1 | Q | 2019 | I | 111CA | Farms | 120.9 | 1 |
2 | 1 | Q | 2019 | I | 113FF | Forestry, fishing, and related activities | 38.8 | 1 |
3 | 1 | Q | 2019 | I | 21 | Mining | 302.1 | 1 |
4 | 1 | Q | 2019 | I | 211 | Oil and gas extraction | 185.6 | 1 |
UnderlyingGDPbyIndustry (Publication category “Underlying”, non-default)¶
[35]:
# Info from iTable
desc = "U.Value Added by Industry"
year="2013"
freq="A"
What parameters are needed?
[36]:
display(param_infos["UnderlyingGDPbyIndustry"])
industries = "ALL" # from iTable
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | Frequency | string | Q-Quarterly | 1 | 1 | ALL | |
1 | Industry | string | List of industries to retrieve (ALL for All) | 1 | 1 | ALL | |
2 | TableID | integer | The unique Underlying GDP by Industry table id... | 1 | 1 | ALL | |
3 | Year | integer | List of year(s) of data to retrieve (ALL for All) | 1 | 1 | ALL |
Get tablename
[37]:
table_param_name, table_param_vals = get_table_param_from_desc("UnderlyingGDPbyIndustry", desc)
print("What TableName matches?")
display(table_param_vals)
table_param_val = table_param_vals.iloc[0,0]
print("First one")
What TableName matches?
Key | Desc | |
---|---|---|
0 | 210 | U.Value Added by Industry (A) |
First one
Get data
[38]:
tbl = beaapi.get_data(beakey, "UnderlyingGDPbyIndustry", TableID=table_param_val, Year=year, Frequency=freq, Industry=industries)
tbl.head()
[38]:
TableID | Frequency | Year | Industry | IndustrYDescription | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|
0 | 210 | A | 2013 | 11 | Agriculture, forestry, fishing, and hunting | 214.3 | 210 |
1 | 210 | A | 2013 | 111 | Crop production | 111.7 | 210 |
2 | 210 | A | 2013 | 111CA | Farms | 183.3 | 210 |
3 | 210 | A | 2013 | 112 | Animal production and aquaculture | 71.5 | 210 |
4 | 210 | A | 2013 | 113FF | Forestry, fishing, and related activities | 31.0 | 210 |
InputOutput (Publication category “Input-Output”, a default)¶
[43]:
# Info from iTable
desc = "The Use of Commodities by Industries - Sector"
year="2020"
print("What parameters are needed")
display(param_infos["InputOutput"])
#industries = "ALL" # from iTable
What parameters are needed
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | TableID | integer | The unique Input-Output table identifier | 1 | 1 | ||
1 | Year | integer | List of year(s) of data to retrieve (ALL for All) | 1 | 1 | ALL |
Get tablename
[44]:
table_param_name, table_param_vals = get_table_param_from_desc("InputOutput", desc)
print("What TableName matches?")
display(table_param_vals)
print("That first one looks good")
table_param_val = table_param_vals.iloc[0,0]
What TableName matches?
Key | Desc | |
---|---|---|
9 | 258 | The Use of Commodities by Industries - Sector |
That first one looks good
Get data
[45]:
tbl = beaapi.get_data(beakey, "InputOutput", TableID=table_param_val, Year=year)
tbl.head()
[45]:
TableID | Year | RowCode | RowDescr | RowType | ColCode | ColDescr | ColType | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 258 | 2020 | 11 | Agriculture, forestry, fishing, and hunting | Commodity | 11 | Agriculture, forestry, fishing, and hunting | Industry | 106419 | 258 |
1 | 258 | 2020 | 11 | Agriculture, forestry, fishing, and hunting | Commodity | T001 | Total Intermediate | Industry | 446013 | 258 |
2 | 258 | 2020 | 11 | Agriculture, forestry, fishing, and hunting | Commodity | 31G | Manufacturing | Industry | 309395 | 258 |
3 | 258 | 2020 | 11 | Agriculture, forestry, fishing, and hunting | Commodity | 7 | Arts, entertainment, recreation, accommodation... | Industry | 8556 | 258 |
4 | 258 | 2020 | 11 | Agriculture, forestry, fishing, and hunting | Commodity | 21 | Mining | Industry | 168 | 258 |
[15]:
# Unsure how to access Publication category "Make Use Framework"
# desc="The Use of Commodities by Industries, After Redefinitions"
# Both methods fail:
#search_result = beaapi.search_metadata(desc, beakey)
#display(search_result)
#table_param_name, table_param_vals = get_table_param_from_desc("UnderlyingGDPbyIndustry", desc) # Tried also with InputOutput, GDPbyIndustry
#display(table_param_vals)
Int’l Transactions, Services, IIP¶
ITA¶
The different tables are associated with different sets of lines (indicators). So some tables aren’t easy to reconstruct exactly.
Note: (in PDF but API error msg confusing) you can’t get all indicators using “AllCountries” (agg’d over countries), even though that would seem easy (and is something like like table 1.1).
Basically you have to look through beaapi.get_parameter_values(beakey, "ITA", "Indicator")
Note also that the following indicators don’t report global sum, so ask for all countries individually: ‘ExpGdsAutoEngAndEngParts’, ‘ExpGdsOthAutoPartsAndAcc’, ‘ExpGdsPassCars’, ‘ExpGdsTrucksBusesSpecPurpVeh’, ‘ImpGdsAutoEngAndEngParts’, ‘ImpGdsOthAutoPartsAndAcc’, ‘ImpGdsPassCars’, ‘ImpGdsTrucksBusesSpecPurpVeh’
[49]:
# Roughly one line from "Table 1.2. U.S. International Transactions, Expanded Detail"
year="2020"
freq="QSA"
cntry="AllCountries"
desc = "Balance on goods"
print("What parameters are needed")
display(param_infos["ITA"])
What parameters are needed
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | Indicator | string | The indicator code for the type of transaction... | 0 | ALL | 1 | ALL |
1 | AreaOrCountry | string | The area or country requested | 0 | AllCountries | 1 | ALL |
2 | Frequency | string | A - Annual, QSA - Quarterly seasonally adjuste... | 0 | ALL | 1 | ALL |
3 | Year | string | Year requested | 0 | ALL | 1 | ALL |
Get indicator (or get a single country)
[51]:
# areas_ITA = beaapi.get_parameter_values(beakey, 'ITA', 'AreaOrCountry')
ita_indicatorsID = beaapi.get_parameter_values(beakey, 'ITA', 'Indicator')
ind_result = ita_indicatorsID[ita_indicatorsID["Desc"].str.contains(desc)]
display(ind_result)
print("Take the first one")
indicator = "BalGds"
Key | Desc | |
---|---|---|
2 | BalGds | Balance on goods |
3 | BalGdsServ | Balance on goods and services |
Take the first one
Get data
[52]:
tbl = beaapi.get_data(beakey, "ITA", Year=year, AreaOrCountry=cntry, Frequency=freq, Indicator=indicator)
tbl.head()
[52]:
Indicator | AreaOrCountry | Frequency | Year | TimeSeriesId | TimeSeriesDescription | TimePeriod | CL_UNIT | UNIT_MULT | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | BalGds | AllCountries | QSA | 2020 | TSI_ItaBalGds_QSA | Balance on goods; quarterly seasonally adjusted | 2020Q3 | USD | 6 | -245370 | Q |
1 | BalGds | AllCountries | QSA | 2020 | TSI_ItaBalGds_QSA | Balance on goods; quarterly seasonally adjusted | 2020Q4 | USD | 6 | -253125 | Q |
IntlServTrade¶
Similar issue about different iTables tables being different sets or broken out by country in different ways. Basically have to look at TypeOfService values to line up with tables. Though in this case we can get all types of service of “AllCountries” (agg’d over countries)
[56]:
type_desc = "Sea transport"
print("What parameters are needed")
display(param_infos["IntlServTrade"])
What parameters are needed
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | TypeOfService | string | The type of service requested | 0 | ALL | 1 | ALL |
1 | TradeDirection | string | The trade direction requested | 0 | ALL | 1 | ALL |
2 | Affiliation | string | The affiliation requested | 0 | ALL | 1 | ALL |
3 | AreaOrCountry | string | The area or country requested | 0 | AllCountries | 1 | ALL |
4 | Year | string | The year requested | 0 | ALL | 1 | ALL |
Get type
[58]:
# cntr_IST = beaapi.get_parameter_values(beakey, 'IntlServTrade', 'AreaOrCountry')
ist_Type = beaapi.get_parameter_values(beakey, 'IntlServTrade', 'TypeOfService')
type_result = ist_Type[ist_Type["Desc"].str.contains(type_desc)]
display(type_result)
type_of_service = type_result.iloc[0,0]
Key | Desc | |
---|---|---|
104 | TransportSea | Sea transport services |
Get data
[59]:
tbl = beaapi.get_data(beakey, "IntlServTrade", AreaOrCountry="AllCountries",TypeOfService=type_of_service, Year="1999")
tbl.head()
[59]:
TypeOfService | TradeDirection | Affiliation | AreaOrCountry | Year | TimeSeriesId | TimeSeriesDescription | TimePeriod | CL_UNIT | UNIT_MULT | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | TransportSea | Exports | Affiliated | AllCountries | 1999 | TSI_IstTransportSeaExpAllCountriesAff_A | Exports of sea transport services; all countri... | 1999 | USD | 6 | NaN | ..... |
1 | TransportSea | Exports | AllAffiliations | AllCountries | 1999 | TSI_IstTransportSeaExpAllCountriesAllAff_A | Exports of sea transport services; all countries | 1999 | USD | 6 | 10489.0 | |
2 | TransportSea | Exports | Unaffiliated | AllCountries | 1999 | TSI_IstTransportSeaExpAllCountriesUnaff_A | Exports of sea transport services; all countri... | 1999 | USD | 6 | 10489.0 | |
3 | TransportSea | Exports | UsAffiliates | AllCountries | 1999 | TSI_IstTransportSeaExpAllCountriesUsAff_A | Exports of sea transport services; all countri... | 1999 | USD | 6 | NaN | ..... |
4 | TransportSea | Exports | UsParents | AllCountries | 1999 | TSI_IstTransportSeaExpAllCountriesUsPar_A | Exports of sea transport services; all countri... | 1999 | USD | 6 | NaN | ..... |
IIP¶
Similar issues as above, but now TypeOfInvestment
are the lines in tables. Does allow all TypeOfInvestment
for “AllCountries” (agg’d over countries)
[61]:
type_desc = "Net international investment position excluding financial derivatives"
print("What parameters are needed")
display(param_infos["IIP"])
What parameters are needed
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | ParameterDefaultValue | MultipleAcceptedFlag | AllValue | |
---|---|---|---|---|---|---|---|
0 | TypeOfInvestment | string | Type of investment | 0 | ALL | 1 | ALL |
1 | Component | string | Component of changes in position | 0 | ALL | 1 | ALL |
2 | Frequency | string | A - Annual, QNSA - Quarterly not seasonally ad... | 0 | ALL | 1 | ALL |
3 | Year | string | Year requested | 0 | ALL | 1 | ALL |
Get Type of Investment
[62]:
# year_IIP = beaapi.get_parameter_values(beakey, 'IIP', 'Year') #if we wanted to get list of years
iip_Type = beaapi.get_parameter_values(beakey, 'IIP', 'TypeOfInvestment')
type_result = iip_Type[iip_Type["Desc"].str.contains(type_desc.lower())] #Note descriptions don't exaclty match lines so make lower case
display(type_result)
type_of_inv = type_result.iloc[0,0]
Key | Desc | |
---|---|---|
343 | NetExclFinDeriv | U.S. net international investment position exc... |
Get data
[63]:
tbl = beaapi.get_data(beakey, "IIP", AreaOrCountry="AllCountries",TypeOfInvestment=type_of_inv,Year="2020",Frequency="QNSA")
tbl.head()
[63]:
TypeOfInvestment | Component | Frequency | Year | TimeSeriesId | TimeSeriesDescription | TimePeriod | CL_UNIT | UNIT_MULT | DataValue | NoteRef | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | NetExclFinDeriv | Pos | QNSA | 2020 | TSI_IipNetExclFinDerivPos_QNSA | U.S. net international investment position exc... | 2020Q1 | USD | 6 | -12150967 | |
1 | NetExclFinDeriv | Pos | QNSA | 2020 | TSI_IipNetExclFinDerivPos_QNSA | U.S. net international investment position exc... | 2020Q2 | USD | 6 | -13018024 | |
2 | NetExclFinDeriv | Pos | QNSA | 2020 | TSI_IipNetExclFinDerivPos_QNSA | U.S. net international investment position exc... | 2020Q3 | USD | 6 | -13794338 | |
3 | NetExclFinDeriv | Pos | QNSA | 2020 | TSI_IipNetExclFinDerivPos_QNSA | U.S. net international investment position exc... | 2020Q4 | USD | 6 | -14004615 |
Direct Investment & MNEs¶
See the separate guide iTables_MNE
Regional¶
[64]:
# Regional actually has the table name at the end of the description, so no need for get_table_param_from_desc()!
table_param_val= "SQGDP1"
year="2021"
print("What parameters are needed")
display(param_infos["Regional"])
What parameters are needed
ParameterName | ParameterDataType | ParameterDescription | ParameterIsRequiredFlag | MultipleAcceptedFlag | ParameterDefaultValue | |
---|---|---|---|---|---|---|
0 | GeoFips | string | Comma-delimited list of 5-character geographic... | 1 | 1 | <NA> |
1 | LineCode | integer | Line code for a statistic or industry | 1 | 0 | <NA> |
2 | TableName | string | Regional income or product table to retrieve | 1 | 0 | |
3 | Year | string | Comma-delimted list of years; LAST5 for latest... | 0 | 1 | LAST5 |
[ ]:
linecode="ALL" # Mentioned in PDF
# Otherwise, could do
# pos_line_codes = beaapi.get_parameter_values_filtered(beakey, "Regional", "LineCode", TableName=table_param_val)
# display(pos_line_codes)
geo_fips = "00000" # Note: Not mentioned in docs, but common. See pdf for other common values
# Otherwise, could do
# pos_geo_codes = beaapi.get_parameter_values_filtered(beakey, "Regional", "GeoFips", TableName=table_param_val, LineCode=linecode)
# display(pos_geo_codes)
Get data
[66]:
tbl = beaapi.get_data(beakey, "Regional", TableName=table_param_val, Year=year, GeoFips=geo_fips, LineCode=linecode)
tbl.head()
[66]:
Code | GeoFips | GeoName | TimePeriod | Description | CL_UNIT | UNIT_MULT | DataValue | |
---|---|---|---|---|---|---|---|---|
0 | SQGDP1-3 | 00000 | United States | 2021Q1 | Current-dollar GDP (millions of current dollars) | Millions of current dollars | 6 | 22038226.0 |
1 | SQGDP1-3 | 00000 | United States | 2021Q2 | Current-dollar GDP (millions of current dollars) | Millions of current dollars | 6 | 22740959.0 |
2 | SQGDP1-3 | 00000 | United States | 2021Q3 | Current-dollar GDP (millions of current dollars) | Millions of current dollars | 6 | 23202344.0 |
3 | SQGDP1-3 | 00000 | United States | 2021Q4 | Current-dollar GDP (millions of current dollars) | Millions of current dollars | 6 | 24002815.0 |
4 | SQGDP1-1 | 00000 | United States | 2021Q1 | Real GDP (millions of chained 2012 dollars) | Millions of chained 2012 dollars | 6 | 19055655.0 |
[ ]: