Fix errors and bugs in the given code, without changing its intended functionality. ONLY…
- User
Fix errors and bugs in the given code, without changing its intended functionality. ONLY return the fixed code and nothing else. Enclose the entire code in a single code block.
Description =============================================================================================================
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Generate Input files for Stata
Details:
- This generate the input files containing BDS data by bins and real GDP by state in chained 2017 dollars.
Computer: Apple MacOS M3 Ultra
Language: R (v4.4.0)
Date: Oct 12, 2024
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
SETUP -----------------------------------------------------------------------------------------------------------
rm(list=ls()) library(openxlsx) library(tidyverse) library(censusapi) library(readxl)
setwd("~/OneDrive - National University of Singapore/Projects/Convergence/Code_local/Convergence_Establishment")
#naics #,"empszfi","FAGE EMPSZES variable_list = str_to_upper(c("JOB_CREATION","EMP","YEAR", "EMPSZES", "estabs_entry_rate", "estabs_exit_rate", "job_creation", "job_creation_births", "job_creation_continuers", "job_destruction", "job_destruction_deaths", "job_destruction_continuers", "net_job_creation", "firmdeath_emp", "firm", "estab", "estabs_entry", "estabs_exit", "firmdeath_firms", "firmdeath_estabs", "job_creation_rate", "job_creation_rate_births", "job_destruction_rate", "job_destruction_rate_deaths", "net_job_creation_rate", "reallocation_rate", "denom"))
output = getCensus( name = 'timeseries/bds', key = 'ec7899b137456a03ace7c9e79cd8d8834007a0f3', vars = c(variable_list), region = "state:*" )
State GDP Data --------------------------------------------------------------------------------------------------------
real_gdp_by_state_63_23 <- read_excel("./data/gdp/spliced_real_gdp_63_23_chained_2017_millions.xlsx")
real_gdp_by_state_63_23 <- real_gdp_by_state_63_23 |> rename(state = GeoName) |> pivot_longer( cols = -c("statefips", "state"), names_to = "year", values_to = "real_gdp", names_transform = list(year = as.numeric) ) |> mutate(real_gdp = real_gdp*1000000)
real_gdp_by_state <- real_gdp_by_state_63_23 |> filter(!state %in% c("United States","District of Columbia")) |> mutate( year = as.numeric(year), ) |> filter(year <= 2019, year >= 1963)
population_by_state <- read_dta("~/Library/CloudStorage/OneDrive-NationalUniversityofSingapore/Projects/Convergence/Code_local/Convergence_Establishment/data/state_pop.dta")
Generate Data to push out ---------------------------------------------------------------------------------------
- Assistant