Skip to content

Instantly share code, notes, and snippets.

@JohnsonBrent
JohnsonBrent / Download all blscrapeR functions and load into memory.R
Created September 13, 2022 18:15
Download blscrapeR functions to local directory and load into memory
library(xfun)
# Set the working directory to a temp directory into which you want to download the blscrapeR functions
current.directory <- getwd()
destination.directory <- tempdir()
setwd(destination.directory)
######################################################################################
# Using an example function, check whether the above local blscrapeR directory contains the needed scripts.
# If it doesn't, then download them.
# Here below is a manual kruithof or ipf. It terates between targets in a loop using the scale.to.target function
# There aren't very many checks in the function, so...
# - Be sure the Targets don't have conflicting totals
# - Be sure you don't include additional variables in the targets
# - Check that it's converged
for (i in 1:5) {
EMP305$Employment <- scale.to.target(source=EMP305, target=Target2, dv="Employment") # Scale to CTRY
EMP305$Employment <- scale.to.target(source=EMP305, target=Target3, dv="Employment") # Scale to IND
EMP305$Employment <- scale.to.target(source=EMP305, target=Target5, dv="Employment") # Scale to Year