Skip to content

Instantly share code, notes, and snippets.

@benzipperer
benzipperer / lincom_estadd_example.do
Created February 16, 2021 18:11
using Stata to mix and match regressions into a single table: lincomestadd example
sysuse auto, clear
* separately add required estimate to each model and store models
foreach yvar in mpg price length {
foreach xvar in weight foreign {
reg `yvar' `xvar'
lincomestadd `xvar', statname(`xvar'_)
eststo `yvar'_`xvar'
}
}
@benzipperer
benzipperer / cbo_vs_dube.R
Created February 9, 2021 03:23
example bar chart in R
library(tidyverse)
library(viridis)
cbo_elast_2021 <- -0.48
cbo_elast_2019 <- -0.38
dube_elast_2019 <- -0.04
emp_effects <- tribble(
~source, ~emp,
@benzipperer
benzipperer / clean_qcew.R
Last active October 28, 2020 13:48
analysis of pivot vs non-pivot counties and QCEW wage growth
library(tidyverse)
library(haven)
library(data.table)
clean_qcew_annual <- function(x) {
# QCEW data from https://www.bls.gov/cew/downloadable-data-files.htm
fread(cmd = paste0("unzip -p ", x, "_annual_singlefile.zip")) %>%
# keep only county-level private sector
filter(agglvl_code == 71 & own_code == 5) %>%
@benzipperer
benzipperer / summarize_groups.R
Last active October 26, 2020 19:18
summarize groups in R
summarize_groups <- function(.data, .groups, ...) {
dots <- enquos(...)
map_dfr(.groups, ~ summarize_onegroup(.data, all_of(.x), !!!dots)) %>%
relocate(name, value)
}
summarize_onegroup <- function(.data, .group, ...) {
data <- .data %>%
rename(value = {{ .group }}) %>%
@benzipperer
benzipperer / group_collapse.R
Created October 25, 2020 16:48
calculate mean over various subgroups: Stata vs (tidy) R
library(tidyverse)
mydata <- mtcars
groups <- c("cyl", "gear", "carb")
group_summarize <- function(x) {
mydata %>%
rename(group_value = {{ x }}) %>%
group_by(group_value) %>%
@benzipperer
benzipperer / bls_cpiurs.csv
Last active July 1, 2020 20:33
example R script using EPI CPS data
YEAR JAN FEB MAR APR MAY JUNE JULY AUG SEP OCT NOV DEC AVG
1977 100.0
1978 100.5 101.1 101.8 102.7 103.6 104.5 105.0 105.5 106.1 106.7 107.3 107.8 104.4
1979 108.7 109.7 110.7 111.8 113.0 114.1 115.1 116.0 117.1 117.9 118.5 119.5 114.3
1980 120.8 122.4 123.8 124.7 125.7 126.7 127.5 128.6 129.9 130.7 131.5 132.4 127.1
1981 133.6 135.2 136.3 137.1 137.9 138.7 139.7 140.7 141.8 142.4 142.9 143.4 139.1
1982 144.2 144.7 144.9 145.0 146.1 147.5 148.5 148.8 149.5 150.2 150.5 150.6 147.5
1983 151.0 151.1 151.2 152.4 153.2 153.7 154.3 154.8 155.6 156.0 156.2 156.4 153.8
1984 157.2 158.0 158.3 159.1 159.5 160.0 160.5 161.1 161.8 162.2 162.2 162.4 160.2
1985 162.6 163.2 164.0 164.6 165.3 165.7 166.0 166.4 166.9 167.3 167.9 168.2 165.7
@benzipperer
benzipperer / process_ephi_rates.R
Created June 30, 2020 02:54
own employer provided health insurance coverage rates, 2019 March CPS, by industry and sector
library(tidyverse)
library(vroom)
# sector names
sector_names <- read_csv("https://raw.githubusercontent.com/Economic/ui_state_detailed/master/output/state_ui_industry_recoded.csv") %>%
group_by(sector, sectorname) %>%
tally() %>%
select(sector, sector_name = sectorname)
# Read in 2019 March CPS
clear all
set more off
* download CES data, if new
!wget -N https://download.bls.gov/pub/time.series/ce/ce.data.0.AllCESSeries
!wget -N https://download.bls.gov/pub/time.series/ce/ce.series
!wget -N https://download.bls.gov/pub/time.series/ce/ce.industry
* identify 3-digit industries
insheet using ce.industry, clear tab
@benzipperer
benzipperer / readme.md
Last active April 1, 2020 04:19
onedrive mapping

We use rclone to mount OneDrive as a network share in the directory ~/OneDrive.

First, log in as the user who needs OneDrive, and create the directory:

mkdir ~/OneDrive

Then configure rclone:

rclone config
@benzipperer
benzipperer / something.R
Created March 31, 2020 18:09
emp provided health insurance by sector - march cps
marchcps %>%
# adult/af universe for health insurance q
filter(prpertyp == 2 | prpertyp == 3) %>%
# workers last year with industry info
filter(industry > 0) %>%
# keep only private and public emp (drop self employed & without pay)
filter(clwk == 1 | clwk == 2) %>%
# convert 2012 Census industry codes to NAICS sectors
# using codebook https://www2.census.gov/programs-surveys/demo/guidance/industry-occupation/census-2012-final-code-list.xls
mutate(