feat: fiscal-year periods on the verbs and survey-year helpers (#77)
`year` is the Census survey year, and Census files a government's fiscal year under survey year Y when it ended between July 1 of Y-1 and June 30 of Y, so one survey year covers different months for different governments. cog_spending(), cog_revenue() and cog_balances() gain a trailing `fiscal_period = FALSE`. With TRUE, every row gains fiscal_year_end (MMDD integer), period_start and period_end (Dates, inclusive), looked up per government-year from long.fiscal_year_end so a change of fiscal year is respected, plus provenance$transformations$fiscal_period. With the default, columns and provenance are exactly as before. cog_fiscal_periods(govid, years) returns the govid x years grid of periods; cog_survey_year(govid, date) returns the survey year whose period contains a date, using each candidate year's own fiscal_year_end and returning NA rather than borrowing another year's value. State governments, and the District of Columbia, cover the fiscal year ending in calendar year Y. That changes Alabama, Michigan (September 30) and Texas (August 31). Census's 2004 and 2006 technical documentation lists those exceptions, and the corpus agrees for survey year 2020: those states' federal aid rises with the CARES Act in 2020 while New York's and 15 large September-30 local governments' rises in 2021. D.C. rests on the documentation alone. Tests run against the bundled fixture (85 expectations). Refs #77 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
This commit is contained in:
12 files changed
+899
-17
No files matched your search
+16
-2
@@ -17,7 +17,8 @@ cog_revenue(
|
||||
limit = NULL,
|
||||
offset = NULL,
|
||||
state = NULL,
|
||||
type = NULL
|
||||
type = NULL,
|
||||
fiscal_period = FALSE
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
@@ -154,13 +155,26 @@ Ignored if `limit` is `NULL`; defaults to `0L` when `limit` is set.}
|
||||
and `govids_missing` are empty -- there is no id list to report against --
|
||||
and `provenance$scope$cohort` carries `state`, `type` and
|
||||
`n_governments` instead. A `govid`-named cohort reports exactly as before.}
|
||||
|
||||
\item{fiscal_period}{If `TRUE`, add three columns to every row:
|
||||
`fiscal_year_end` (the government's fiscal year end that survey year, an
|
||||
MMDD integer such as `630`), and `period_start` and `period_end` (Dates,
|
||||
inclusive), the calendar months the row covers. `year` is the Census
|
||||
survey year, which covers different months for different governments;
|
||||
see "The survey-year rule" in [cog_fiscal_periods()]. The columns come
|
||||
from each government-year's own `fiscal_year_end`, so a change of fiscal
|
||||
year is respected, and are `NA` where the corpus has no value. The result
|
||||
also gains `provenance$transformations$fiscal_period`. Defaults to
|
||||
`FALSE`, which returns exactly the columns and provenance this verb
|
||||
returned before the argument existed.}
|
||||
}
|
||||
\value{
|
||||
Tibble with columns `year`, `canonical_govid`, `gov_name`,
|
||||
`revenue_subtype`, `category`, `amt_nominal`, optional `amt_real`,
|
||||
optional `amt_per_capita_nominal`, optional `amt_per_capita_real`,
|
||||
optional `pop_source`, `codes_included`, `aggregate_fallback`, `notes`,
|
||||
and `value_source` when `complete = TRUE`.
|
||||
`value_source` when `complete = TRUE`, and `fiscal_year_end`,
|
||||
`period_start` and `period_end` when `fiscal_period = TRUE`.
|
||||
}
|
||||
\description{
|
||||
Mirror of [cog_spending()] for revenue categories. One row per
|
||||
|
||||
Reference in new issue
Block a user