Skip to content

Instantly share code, notes, and snippets.

@benzipperer
benzipperer / postfile_example.do
Last active April 11, 2019 15:45
example of using postfile in stata
* Example Stata script using postfile to create
* a dataset of results from an analysis.
* This example simulates a female wage penalty X times
* and compares the density of estimates to the normal density.
* parameters for simulation
local numiterations = 50
local samplesize = 500
* set the simulation seed just for reproducibility of this artificial example
@benzipperer
benzipperer / example.md
Last active April 18, 2019 19:34
table example
sysuse state_geocodes, clear
list, ab(20)

     +---------------------------------------------------------------------------------------------------------+
     |           state_name   state_abb   fips   census   division        division_name   region   region_name |
     |---------------------------------------------------------------------------------------------------------|
  1. |          Connecticut          CT      9       16          1          New England        1     Northeast |
  2. |                Maine          ME     23       11          1          New England        1     Northeast |
  3. |        Massachusetts          MA     25       14          1          New England        1     Northeast |
@benzipperer
benzipperer / cboplot.R
Created November 7, 2019 22:23
compare CBO's elasticities with median research estimates from Dube (2019)
library(tidyverse)
library(EmpElastR)
library(viridis)
# Dube (2019) review: median estimates
ests <- tibble(`Median, \n low-wage` = -0.04, `Median, \n any group` = -0.17)
# SR elasticity is the base elasticity scaled by real barsize and indexing adjustments
cbo_sr_rwta_elas <- function(x) {
@benzipperer
benzipperer / effectivemw.do
Last active December 3, 2019 19:52
effective state minimum wages
set more off
clear all
* load CPS for population weights
load_epiextracts, begin(1979m1) end(2018m12) sample(basic) keep(age statefips)
keep if age >= 16
* convert monthly weight to annual
replace basicwgt = basicwgt / 12
collapse (sum) pop = basicwgt, by(statefips year)
tempfile statepops
@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(
@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
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 / 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
@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 / 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) %>%