Build the firm-year analytical panel and its derived indicators
Source:R/build-accounts-indicators.R
build_accounts_indicators.RdTranslates n0_1_accounts_indicators_v2.do
(Pseudocode/n0_1_accounts_indicators_v2.md). Cleans the raw firm-level
panel, optionally folds in establishment-level plant data, and constructs
every derived variable the other 4 pipeline stages depend on: growth
rates, high-growth-firm (HGF) flags, age/size/sector/region categories,
the TL3 urbanisation typology, labour productivity, multi-factor
productivity (Solow residual), and the acquisition indicator.
Usage
build_accounts_indicators(
config,
base_financials,
plants_raw = NULL,
exchange_rates = NULL,
tl3_typology = NULL
)Arguments
- config
A
scaleup_configfromconfig_scaleup().- base_financials
A data frame of raw firm-level financials, matching the
BASE_FINANCIALSsheet ofvariable_dictionary_v1.xlsx. Must containidf, year, sector_1d, sector_2d, sector_3d, employment, turnover, region_2d; every other column is optional and used only if present.- plants_raw
Optional data frame of establishment-level data (the
PLANTS_RAWsheet), with columnsidf, idp, year. IfNULL(the default), nomultiplantindicator is produced.- exchange_rates
Optional data frame with columns
year, country, rate(as shipped in this package'sexchange_ratesdataset). Required only for the non-Euro countries listed incountry_patches$non_euro.- tl3_typology
Optional data frame with columns
region_3d, typology_access_cities(as shipped in this package'stl3_typologydataset). Required only ifbase_financialshas aregion_3dcolumn.
Value
A data frame, one row per (idf, year), ready to be passed to
compute_characteristics(), compute_persistence(),
compute_contribution(), and compute_predictors().
Details
Unlike the source .do file, this is a pure function: it takes
already-loaded data frames and returns the built panel, rather than
reading/writing .dta files itself (that I/O now lives in
run_scaleup_pipeline(), mirroring MASTER_OECD_p2.do's role). This also
means the row-order-dependent sort idf year step in the source is
unnecessary here: every lag/lead below is computed via panel_lag() /
panel_lead(), which key off (idf, year) values directly rather than
physical row position.