Skip to content

Instantly share code, notes, and snippets.

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(
@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 / 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 / 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 / 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 / bouts.R
Created March 12, 2019 04:57
spells in R
library(dplyr)
# just used to simulate some data
library(purrr)
# create fake data
f <- function(x,i) {
return(data.frame(bout=x, element=i))
}
fake_data <- map_dfr(1:4, ~map2_dfr(.x, 0:(round(runif(1)*10)+5), f)) %>%
mutate(invisible_id=ifelse(element==0,"bout","element")) %>%
@benzipperer
benzipperer / readme.md
Last active March 6, 2019 05:02
r package workflow

build

make R .rd documentation using roxygen (in man/): devtools::document()

need to knit root README (seems like devtools might be able to do this too?)

build vignettes (in doc/): devtools::build_vignettes()

build pkgdown site (in docs/): pkgdown::build_site()

install

@benzipperer
benzipperer / problems
Last active April 3, 2018 22:55
problematic import
setwd("/data/nlsy/data/raw/nlsy97_all_1997-2013")
head -n 1 nlsy97_all_1997-2013 > data.dat
read_delim("data.dat",delim=" ",)
read_delim("data.dat",delim=" ",col_types = cols(.default = col_integer()))
read_delim("data.dat",delim=" ",col_names=FALSE,col_types = cols(.default = col_integer()))
read_delim(pipe("cut -d \" \" -f1-8 data.dat"),delim=" ",col_names=FALSE,col_types = cols(.default = col_integer()))
newdata<-read_delim(pipe("cut -d \" \" -f1-10000 nlsy97_all_1997-2013.dat"),delim=" ",col_names=FALSE)