A second natural experiment for the state-government rule in R/fiscal.R,
using IG Federal revenue from the public API (corpus build 2026-10-26,
fccd87c), survey years 2006-2011:
- Alabama and Michigan (September 30) and Texas (August 31) jump in
survey year 2009 (+18.0%, +22.2%, +12.3%) and slow in 2011 (-4.7%,
+3.9%, +4.3%), as the June 30 states do (median +12.4%, +3.6%). Under
the plain rule their 2009 would end in 2008, before the stimulus, and
their 2011 would be the full stimulus year.
- 15 large September-30 cities and counties jump in 2011 (median +17.7%,
against +2.1% and +3.1% in 2009 and 2010), as the plain rule predicts.
- D.C. is inconclusive again: its 2009 is flat (+4.1%), like the plain
rule, but its 2011 falls (-0.9%), like the documented one.
The data agrees with the code, so the rule and
.SURVEY_YEAR_SAME_YEAR_GOVIDS are unchanged. The header comment and the
"survey-year rule" section now cite survey years 2009 and 2020 for the
state rule and say D.C. was inconclusive in both. man/ regenerated with
roxygen2 7.3.3.
Refs #77
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
NEWS.md gains a development-version entry for fiscal_period,
cog_fiscal_periods() and cog_survey_year().
total-spending.Rmd shows that its Florida rollup mixes a June 30 state
(July 2019 to June 2020) with two September 30 counties (October 2018 to
September 2019) under the same 2020. coverage-counters.Rmd counts the
FY2012 fiscal year ends of Georgia cities (273 December 31, 196 June 30,
36 September 30) and what months they cover. population-denominators.Rmd
notes that each cohort year is a survey year. The first two chunks run
against the bundled fixture.
Refs #77
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
`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
data-raw/measure_fiscal_year_end.R reads a corpus's long partitions and
reports, by survey year and government type, how many government-years
have a missing, zero, implausible or internally conflicting
fiscal_year_end; the most common values; how often a government's value
changes between consecutive years; and every state government's and the
District of Columbia's value.
On the bundled fixture (FY2011, FY2012, FY2019, FY2020; full published
partitions from the 2026-08-03 build) 0.1%-0.9% of government-years are
missing a value, none is zero, implausible or conflicting, and every
state government keeps the same value in all four years.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
The coverage docs said a city that contracts policing to the county
sheriff has no Police rows and that its Police spending "is a real zero".
Checked against the published corpus (build of 2026-10-26) through the
public API for 34 cities with documented sheriff contracts (Los Angeles,
San Diego and Orange counties, CA; King County, WA) in FY2012, FY2017
and FY2022: all 102 city-years carry Police spending. 93 have direct
Police rows (E62/F62/G62) and so count as reporting. The other nine
report the contract payment only as intergovernmental Police expenditure
(M62), which the "primary" and "direct" concepts leave out, so they land
among the collected governments with no Police rows while paying for
policing.
The vignette's three-group list, the n_units_collected and
n_units_reporting bullets in cog_peer_compare(), cog_geographic_rollup()
and .coverage_table(), and the FY2022 Georgia paragraphs now say that a
collected government with no rows in a category can still spend on it,
and that a contract city lands in that group only when it reports no
direct Police spending. man/ regenerated with roxygen2 7.3.3. No code
changed.
Closes#80
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
Checked against the published corpus (build of 2026-10-26) through the
public API:
- FY2022 Georgia cities, Police: 567 expected, 535 collected, 393
reporting. The 174-city gap is 32 not collected and 142 collected with
no Police rows. The FY2022 section now states the split.
- All US cities: Police participation among collected cities is 0.70,
0.73 and 0.72 in FY2012, FY2017 and FY2022, and 0.93 to 0.95 in every
sample year FY2013-FY2023. Among the 3,867 cities collected in both
FY2022 and FY2021 it is 0.929 and 0.935; Fire, Libraries and Housing &
Community move by 0.01 or less on the same cities.
A census year and a sample year collect different sets of governments,
so the census-vs-sample section now recommends comparing census years
with each other, or the same governments across years, and adds a
fixture chunk that measures participation over the 99 Georgia cities
collected in both FY2012 and FY2019 (0.97 and 0.94).
The fixture caveat now says what data-raw/regenerate_fixture_corpus.R
does: each fixture year is a full copy of the published partition. Its
FY2012 and FY2019 Georgia Police counts match the published corpus; the
newer crosswalk lists 567 Georgia cities where the fixture lists 566.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
vignettes/coverage-counters.Rmd explains the three per-year counters that
cog_geographic_rollup() and cog_peer_compare() attach as
provenance$coverage, using the definitions in .coverage_table(),
R/rollup.R and R/peers.R: n_units_expected (the ids passed, or the peers),
n_units_collected (of those, how many have any row in the spending long
view that year) and n_units_reporting (of those, how many have a row in
the requested category). It splits the named governments into three
groups, defines the collection rate and category participation, and
shows that reporting / expected is their product.
The evaluated chunks run against the bundled fixture and say so: Georgia
cities and Police across FY2011, FY2012, FY2019 and FY2020, a peer
comparison, and the census, consistent and per_capita effects. The FY2022
example from the reference pages needs the published corpus and is not
evaluated, following population-denominators.Rmd.
The article is added to the pkgdown Concepts index.
Closes#72
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
cog_suggestions(govid, years, category, flow, concept, years_present)
returns the list that cog_spending() and cog_revenue() attach as
attr(x, "provenance")$suggestions, given the years the caller's rows
cover. A caller can run a verb once with no category, filter the rows
itself, and build the suggestions for a category only when it needs
them, without reaching into .build_suggestions() and six other internal
names.
It validates every argument before opening a session, with cli errors
whose classes match the verbs' where one exists
(uscogdata_invalid_expenditure_concept, uscogdata_invalid_revenue_concept,
uscogdata_all_categories_not_combinable) and a new uscogdata_invalid_flow.
It resolves the verbs' default basis the way .verb_spendrev() does, so it
returns an empty list on a schema_version < 5 corpus, and it does not
print the suggestion message.
Tests check that it returns exactly the verbs' list for empty_year and
suppressed_component fires, a multi-government cohort, a data-frame
govid, both revenue concepts, "All Categories" under each concept, and
expenditure_concept = "total" given Direct-leg years.
Closes#75
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
The candidate-recipe query in .query_candidate_recipes() used SELECT
DISTINCT with no ORDER BY, and .build_suggestions() emits suggestions in
candidate order. DuckDB returns DISTINCT rows in whatever order its
parallel hash aggregate finishes, so two identical cog_spending() or
cog_revenue() calls could list the same suggestions in different orders.
The query now ends in ORDER BY recipe_id.
On the bundled fixture, cog_spending("010000226085", 2011, category =
"All Categories") listed corrections_other_capital_combined before
corrections_combined; both new tests fail against the previous code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5