% Generated by roxygen2: do not edit by hand % Please edit documentation in R/revenue.R \name{cog_revenue} \alias{cog_revenue} \title{Summarized revenue by category} \usage{ cog_revenue( govid = NULL, years, category = NULL, per_capita = FALSE, adjust_to_year = NULL, basis = c("harmonized", "raw"), recipe = NULL, revenue_concept = c("general", "total"), complete = FALSE, limit = NULL, offset = NULL, state = NULL, type = NULL, fiscal_period = FALSE ) } \arguments{ \item{govid}{Character vector of \code{canonical_govid} values, or \code{NULL} to name the cohort by \code{state}/\code{type} instead. One of \code{govid}, \code{state}, or \code{type} is required.} \item{years}{Integer vector of years.} \item{category}{Character vector of category names (from \code{summary_categories.category}), or \code{NULL} for all categories broken out one row each. The reserved value \code{"All Categories"} instead returns a single summed row per \verb{(year, canonical_govid, subtype)}, covering every category inside the requested concept's subtype scope. It cannot be combined with other category names, and it is not the same thing as \code{revenue_concept = "total"}: the concept chooses which subtypes are in scope, \code{"All Categories"} chooses whether rows inside that scope are broken out or summed. Because the result keeps one row per \code{revenue_subtype}, filtering the returned frame to \code{revenue_subtype == "own_source"} gives an own-source revenue total.} \item{per_capita}{If \code{TRUE}, adds \code{amt_per_capita_nominal} (and \code{amt_per_capita_real} when \code{adjust_to_year} is set) using the per-year Census F-33 population from \code{gov_population_yearly}. Result also gains a \code{pop_source} column with values \code{"census_f33"} or \code{"unavailable"} (the latter for gov types 4/5 and any row whose population is missing in that year).} \item{adjust_to_year}{Integer base year for CPI-U real-dollar conversion, or \code{NULL} for nominal only.} \item{basis}{\code{"harmonized"} (default) sums item codes through the cross-vintage harmonization mapping (folding series-break-affected codes onto a comparable target and excluding aggregate / discontinued rows -- see the \code{harmonization} block in \code{cog_explain()}); \code{"raw"} reproduces the pre-Phase-R2 behavior (published item codes, no folding). On a corpus with \code{schema_version < 5} (no harmonization tables), \code{basis} silently resolves to \code{"raw"} when left at its default and the resolution is recorded in the provenance; explicitly passing \code{basis = "harmonized"} on such a corpus aborts. Ignored when \code{recipe} is set (see below).} \item{recipe}{Optional harmonization recipe id (see \code{\link[=cog_recipes]{cog_recipes()}}) for multi-code cross-vintage series that a 1:1 harmonized_code mapping can't express (e.g. a wide-era aggregate that only splits into leaf codes in the modern era). Mutually exclusive with \code{category}. The result's subtype column reads \code{"recipe"} and \code{category} reads the recipe's label. Requires \code{schema_version >= 5}. A recipe query bypasses \code{basis} entirely (it joins \code{long} directly rather than going through the \verb{*_annotated}/\verb{*_annotated_harmonized} views), so the \code{basis} argument is ignored and the result's provenance reports \code{basis = "recipe"} with an inert \code{harmonization} block (\code{applied = FALSE}, pointing at the \code{recipe} block instead) rather than a possibly-misleading \code{"harmonized"}/\code{"raw"} value.} \item{revenue_concept}{Which of Census's two published revenue concepts to return. Concepts are defined as sets of the crosswalk's \code{revenue_subtype} values -- never as item-code first letters, which cannot classify correctly (prefix \code{Y} spans revenue, expenditure and balance codes, and prefix \code{X} does the same): \itemize{ \item \code{"general"} (default) -- Census General Revenue: \code{own_source} + \code{federal} + \code{state} + \code{local_aid}. The manual defines this concept by subtraction (section 4.3: \emph{"General revenue comprises all revenue except that classified as liquor store, utility, or insurance trust revenue"}), so utility (\code{A91}-\code{A94}), liquor store (\code{A90}) and insurance trust revenue are all excluded. \item \code{"total"} -- Census Total Revenue: every revenue subtype, i.e. \code{general} plus utility, liquor store, and insurance trust revenue (\code{Y01}/\code{Y02}/\code{Y04}/\code{Y11}/\code{Y12}/\code{Y51}/\code{Y52} and the employee-retirement \code{X01}/\code{X02}/\code{X05}/\code{X08}). } The two are related by Census's own identity, \verb{Total Revenue = General + Utility + Liquor Store + Insurance Trust}. Note that the employee-retirement (\code{X}) codes stop at FY2016, when those systems moved out of the annual finance file into the separate Annual Survey of Public Pensions, so a \code{"total"} series steps down at the FY2016/FY2017 seam for reasons that are about collection scope rather than revenue (series breaks \code{SB197}-\code{SB202}).} \item{complete}{If \code{TRUE}, fill the requested grid so that a cell the corpus does not carry still appears, labelled with \strong{why} it is missing, and add a \code{value_source} column to every row: \itemize{ \item \code{"reported"} — the corpus carries this cell. \item \code{"census_zero"} — dense-source year (\verb{<= FY2011}), cell absent: Census published \verb{$0}. \code{amt_nominal} is \code{0}. \item \code{"not_reported"} — sparse-source year (\verb{>= FY2012}), cell absent: the government did not report, and the value is unknown. \code{amt_nominal} is \code{NA}, \strong{not} \code{0} — writing a zero there would invent data. } The grid comes from the corpus's \code{code_set} table, scoped to each government's own type, so a county is never filled with cells only a state can report. Reported rows are passed through untouched. Defaults to \code{FALSE} (the historical behaviour: absent cells simply do not appear). Needs a corpus published from 2026-07-29 onward, which is when \code{representation}/\code{code_set} began shipping; aborts with class \code{uscogdata_representation_unavailable} otherwise. Not available with \code{recipe} or with \code{expenditure_concept = "total"} (class \code{uscogdata_complete_unsupported}) — neither draws its cells from \code{code_set}.} \item{limit}{Maximum number of result rows to return, pushed into the SQL query itself (\code{LIMIT}/\code{OFFSET}) rather than applied after the full result is materialized. \code{NULL} (the default) returns every matching row, exactly as before this parameter existed. Mutually exclusive with \code{recipe} and with \code{complete = TRUE} -- see \code{offset} and \code{total_rows}.} \item{offset}{Rows to skip before \code{limit} starts counting (0-based). Ignored if \code{limit} is \code{NULL}; defaults to \code{0L} when \code{limit} is set.} \item{state, type}{Name the cohort by predicate instead of by id: \code{state} is a 2-letter USPS abbreviation (or a FIPS code) and \code{type} is one of \code{"state"}, \code{"county"}, \code{"city"}, \code{"township"} (or the integer \code{0:3}) -- the same vocabulary, and the same internal coercion, as \code{\link[=cog_gov_search]{cog_gov_search()}}. Both default to \code{NULL}. The cohort is then expressed as a subquery against \code{canonical_fips_xwalk} inside each statement rather than round-tripped through R as a literal id list. For a fleet-scale cohort that is the difference between a 301,591-character \code{IN} list re-parsed in 5--8 statements per call and a constant-size predicate: measured at \strong{94 ms versus 449 ms} for the same FY2022 aggregate over the 20,106-government \code{type = "city"} cohort, within 7\% of the no-filter floor. Supplying \code{govid} \strong{and} \code{state}/\code{type} INTERSECTS them -- the governments in \code{govid} that also match the predicate -- rather than one silently taking precedence. Naming no cohort at all (\code{govid}, \code{state} and \code{type} all \code{NULL}) aborts with class \code{uscogdata_no_cohort}. When the cohort is named by predicate, \code{provenance$scope$govids_found} and \code{govids_missing} are empty -- there is no id list to report against -- and \code{provenance$scope$cohort} carries \code{state}, \code{type} and \code{n_governments} instead. A \code{govid}-named cohort reports exactly as before.} \item{fiscal_period}{If \code{TRUE}, add three columns to every row: \code{fiscal_year_end} (the government's fiscal year end that survey year, an MMDD integer such as \code{630}), and \code{period_start} and \code{period_end} (Dates, inclusive), the calendar months the row covers. \code{year} is the Census survey year, which covers different months for different governments; see "The survey-year rule" in \code{\link[=cog_fiscal_periods]{cog_fiscal_periods()}}. The columns come from each government-year's own \code{fiscal_year_end}, so a change of fiscal year is respected, and are \code{NA} where the corpus has no value. The result also gains \code{provenance$transformations$fiscal_period}. Defaults to \code{FALSE}, which returns exactly the columns and provenance this verb returned before the argument existed.} } \value{ Tibble with columns \code{year}, \code{canonical_govid}, \code{gov_name}, \code{revenue_subtype}, \code{category}, \code{amt_nominal}, optional \code{amt_real}, optional \code{amt_per_capita_nominal}, optional \code{amt_per_capita_real}, optional \code{pop_source}, \code{codes_included}, \code{aggregate_fallback}, \code{notes}, \code{value_source} when \code{complete = TRUE}, and \code{fiscal_year_end}, \code{period_start} and \code{period_end} when \code{fiscal_period = TRUE}. } \description{ Mirror of \code{\link[=cog_spending]{cog_spending()}} for revenue categories. One row per \verb{(year, canonical_govid, revenue_subtype, category)}. Amounts are returned in \strong{full U.S. dollars} (raw Census values are in $1,000s; this verb multiplies by 1000 and records the conversion in \code{provenance}). }