View source: R/get-compustat.R
| get_compustat | R Documentation |
Downloads financial statement data from Compustat with standard filters for clean, analysis-ready data.
get_compustat(
wrds,
frequency = c("annual", "quarterly"),
region = c("na", "global"),
start_date = NULL,
end_date = NULL,
columns = NULL,
add_columns = NULL,
indfmt = "INDL",
consol = "C",
fill_sic = FALSE,
n = Inf,
lazy = FALSE
)
wrds |
A |
frequency |
One of |
region |
One of |
start_date |
Start date for filtering. Character string in
|
end_date |
End date for filtering. Character string in
|
columns |
Character vector of columns to return, replacing the defaults.
Use |
add_columns |
Character vector of additional columns to include beyond
the defaults. Ignored if |
indfmt |
Industry format filter. Defaults to |
consol |
Consolidation level. Defaults to |
fill_sic |
If |
n |
Maximum number of rows to return. Defaults to |
lazy |
If |
Default filters follow standard practice for most research applications.
Region-specific filters are applied automatically based on region:
datafmt: "STD" for North America, "HIST_STD" for Global
popsrc: "D" (domestic) for North America, "I" (international) for Global
North America and Global data have different structures and should not be combined without careful column harmonization.
A tibble with Compustat fundamentals. Default columns vary by region:
North America (from comp.funda / comp.fundq):
Identifiers: gvkey, cusip, tic, conm, datadate
Time: fyear/fyearq, fyr/fqtr
Income: ni/niq, ib/ibq, oiadp/oiadpq, revt/revtq
Balance sheet: at/atq, lt/ltq, seq/seqq, ceq/ceqq
Market: csho/cshoq, prcc_f/prccq
Other: sale/saleq, capx/capxy, che/cheq, dlc/dlcq, dltt/dlttq
Industry: sich (historical SIC); sic (when fill_sic = TRUE, coalesced
from sich and header SIC)
Global (from comp.g_funda / comp.g_fundq):
Identifiers: gvkey, isin, conm, datadate
Geography: loc, fic, exchg
Similar financial variables (with some differences, e.g., nit/nitq
instead of ni/niq)
link_ccm() for CRSP-Compustat linking, get_company() for
company header data
## Not run:
wrds <- wrds_connect()
# Annual North America fundamentals
funda <- get_compustat(wrds)
# Quarterly with date filter
fundq <- get_compustat(wrds,
frequency = "quarterly",
start_date = "2020-01-01",
end_date = "2023-12-31"
)
# Global annual
g_funda <- get_compustat(wrds, region = "global")
# Lazy query for further filtering
get_compustat(wrds, lazy = TRUE) |>
dplyr::filter(fyear >= 2020) |>
dplyr::select(gvkey, datadate, at, lt) |>
dplyr::collect()
# Fill missing SIC codes with header SIC from comp.company
funda_sic <- get_compustat(wrds, fill_sic = TRUE)
# Preview first 100 rows before full download
preview <- get_compustat(wrds, n = 100)
wrds_disconnect(wrds)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.